class ForemanAP::Hypervisor
A host in the cluster that runs a hypervisor.
Public Class Methods
new(uri, user, passphrase)
click to toggle source
Create an object.
uri
-
The libvirt URI. Example: qemu+tcp:///host/system
user
-
The username to login with.
passphrase
-
The passphrase to login with.
# 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
Public Instance Methods
cpus()
click to toggle source
The total number of CPUs (physical and virtual)
# File lib/foreman_vm/hypervisor.rb, line 7 def cpus nodeinfo.cpus end
domains()
click to toggle source
The names of all the domains defined on the hypervisor.
# 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
domains2()
click to toggle source
A list of handles to all the active domains on the hypervisor TODO - replace domains
with this
# 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_memory()
click to toggle source
The amount of free memory, in bytes.
# File lib/foreman_vm/hypervisor.rb, line 17 def free_memory @conn.node_free_memory end
guest(fqdn)
click to toggle source
A guest running on the hypervisor
[+fqdn+] the FQDN of the guest
# File lib/foreman_vm/hypervisor.rb, line 33 def guest(fqdn) ForemanAP::Domain.new(@conn, fqdn, @foreman_api) end
hostname()
click to toggle source
Return the name of hypervisor
# File lib/foreman_vm/hypervisor.rb, line 27 def hostname @conn.hostname end
memory()
click to toggle source
The total amount of memory, in bytes.
# File lib/foreman_vm/hypervisor.rb, line 12 def memory nodeinfo.memory * 1024 # Convert from KiB end
storage_pool(name)
click to toggle source
Lookup a storage pool by name.
# File lib/foreman_vm/hypervisor.rb, line 22 def storage_pool(name) StoragePool.new(@conn, name) end
Private Instance Methods
nodeinfo()
click to toggle source
The ‘nodeinfo’ structure for the connection
# File lib/foreman_vm/hypervisor.rb, line 92 def nodeinfo @nodeinfo ||= @conn.node_get_info end