Module: Proxmox

Defined in:
lib/pve/proxmox.rb

Defined Under Namespace

Modules: RestConnection Classes: AlreadyExists, AplInfo, Base, Exception, HA, Hosted, LXC, Node, NotFound, Qemu, Storage, Task

Class Method Summary collapse

Class Method Details

.api_ticketObject



45
46
47
# File 'lib/pve/proxmox.rb', line 45

def self.api_ticket
  @@api_ticket
end

.connect(username, password, realm: nil, verify_tls: nil, uri: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pve/proxmox.rb', line 16

def self.connect username, password, realm: nil, verify_tls: nil, uri: nil
  uri ||= 'https://localhost:8006/api2/json'
  cred =
    {
      username: username,
      password: password,
      realm: realm || 'pve'
    }
  @@connection =
    RestClient::Resource.new( uri, verify_ssl: ! ! verify_tls).tap do |rs|
      resp = rs['/access/ticket'].post cred
      case resp.code
      when 200
        data = JSON.parse resp.body, symbolize_names: true
        @@api_ticket =
          {
            CSRFPreventionToken: data[:data][:CSRFPreventionToken],
            cookie: "PVEAuthCookie=#{CGI.escape data[:data][:ticket]}"
          }
      else
        raise Exception, "Authentication failed"
      end
    end
end

.connectionObject



41
42
43
# File 'lib/pve/proxmox.rb', line 41

def self.connection
  @@connection
end

.find(name_or_id) ⇒ Object



57
58
59
# File 'lib/pve/proxmox.rb', line 57

def self.find name_or_id
  Proxmox::LXC.find( name_or_id) || Proxmox::Qemu.find( name_or_id) || Proxmox::Node.find( name_or_id)
end

.find_by_name(name) ⇒ Object



49
50
51
# File 'lib/pve/proxmox.rb', line 49

def self.find_by_name name
  Proxmox::LXC.find_by_name( name) || Proxmox::Qemu.find_by_name( name) || Proxmox::Node.find_by_name( name)
end

.find_by_vmid(vmid) ⇒ Object



53
54
55
# File 'lib/pve/proxmox.rb', line 53

def self.find_by_vmid vmid
  Proxmox::LXC.find_by_vmid( vmid) || Proxmox::Qemu.find_by_vmid( vmid) || Proxmox::Node.find_by_vmid( vmid)
end