Class: ForemanAP::Hypervisor

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_vm/hypervisor.rb

Overview

A host in the cluster that runs a hypervisor.

Instance Method Summary collapse

Constructor Details

#initialize(uri, user, passphrase) ⇒ Hypervisor

Create an object.

uri

The libvirt URI. Example: qemu+tcp:///host/system

user

The username to login with.

passphrase

The passphrase to login with.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/foreman_vm/hypervisor.rb', line 74

def initialize(uri, user, passphrase)
  @uri = uri
  @conn = Libvirt::open_auth(@uri, 
		[Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) do |cred|
     case cred["type"]
     when Libvirt::CRED_AUTHNAME 
       user
     when Libvirt::CRED_PASSPHRASE
       passphrase
     else
       raise 'Unknown error'
     end
  end
end

Instance Method Details

#cpusObject

The total number of CPUs (physical and virtual)



7
8
9
# File 'lib/foreman_vm/hypervisor.rb', line 7

def cpus
  nodeinfo.cpus
end

#domainsObject

The names of all the domains defined on the hypervisor.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/foreman_vm/hypervisor.rb', line 38

def domains
  res = []

  # Active domains
  @conn.list_domains.each do |domid|
    dom = @conn.lookup_domain_by_id(domid)
    res.push dom.name
  end

  # Inactive domains
  @conn.list_defined_domains.each do |domname|
    res.push domname
  end

  res
end

#domains2Object

A list of handles to all the active domains on the hypervisor TODO - replace #domains with this



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/foreman_vm/hypervisor.rb', line 57

def domains2
  res = []

  # Active domains
  @conn.list_domains.each do |domid|
    dom = @conn.lookup_domain_by_id(domid)
    res.push ForemanAP::Domain.new(@conn, dom.name, @foreman_api)
  end

  res
end

#free_memoryObject

The amount of free memory, in bytes.



17
18
19
# File 'lib/foreman_vm/hypervisor.rb', line 17

def free_memory
  @conn.node_free_memory
end

#guest(fqdn) ⇒ Object

A guest running on the hypervisor

[+fqdn+] the FQDN of the guest


33
34
35
# File 'lib/foreman_vm/hypervisor.rb', line 33

def guest(fqdn)
   ForemanAP::Domain.new(@conn, fqdn, @foreman_api)
end

#hostnameObject

Return the name of hypervisor



27
28
29
# File 'lib/foreman_vm/hypervisor.rb', line 27

def hostname
  @conn.hostname	
end

#memoryObject

The total amount of memory, in bytes.



12
13
14
# File 'lib/foreman_vm/hypervisor.rb', line 12

def memory
  nodeinfo.memory * 1024		# Convert from KiB
end

#storage_pool(name) ⇒ Object

Lookup a storage pool by name.



22
23
24
# File 'lib/foreman_vm/hypervisor.rb', line 22

def storage_pool(name)
  StoragePool.new(@conn, name)
end