class ForemanAP::Cluster
A cluster of hypervisors.
Attributes
A list of the names of all members of the cluster.
DEPRECATED - avoid using these
DEPRECATED - avoid using these
Public Class Methods
Create an object.
members
-
A list of names of hypervisors to be members.
user
-
The libvirtd username.
password
-
The libvirtd password.
# File lib/foreman_vm/cluster.rb, line 72 def initialize(members, user, password) @members = members @hv = {} @user = user @password = password @members.each do |fqdn| uri = 'qemu+tcp://' + fqdn + '/system' @hv[fqdn] = Hypervisor.new(uri, @user, @password) end end
Public Instance Methods
Return name of best hypervisor
name
-
The name of the guest to be added
memory
-
The total size of the guest in Bytes
# File lib/foreman_vm/cluster.rb, line 15 def best_fit(name, memory) alloc = ForemanAP::Allocator.new @members.each do |hostname| host = member(hostname) alloc.add_host(host.hostname, host.free_memory, host.domains) end alloc.add_guest(name, memory) end
The name of the hypervisor that contains a given virtual machine.
vm
-
The name of the virtual machine.
# File lib/foreman_vm/cluster.rb, line 38 def find(vm) @members.each do |host| #puts host #puts @hv[host].free_memory #puts @hv[host].domains.join("\n") if @hv[host].domains.include? vm return host end end return nil end
Return a handle to the guest domain
fqdn
-
the FQDN of the guest
# File lib/foreman_vm/cluster.rb, line 7 def guest(fqdn) host = member(find(fqdn)) or raise 'Guest not found' host.guest(fqdn) end
A handle to the ForemanAP::Hypervisor
object for a member of the cluster.
name
-
The name of the hypervisor.
# File lib/foreman_vm/cluster.rb, line 52 def member(name) unless @hv.include? name raise ArgumentError, "hypervisor #{name} is not defined" end @hv[name] end
Return a list of all Hypervisor
objects in the cluster TODO: replace members
with this function
# File lib/foreman_vm/cluster.rb, line 32 def members2 @hv.values end
Migrate a virtual machine from one host to another (FIXME - UNIMPLEMENTED)
guest
-
The name of the guest
destination
-
The target hypervisor
# File lib/foreman_vm/cluster.rb, line 62 def migrate(guest, destination) # TODO: the equivalent of this: # virsh migrate $vm qemu+ssh://${target}-san.brontolabs.local/system --verbose --persistent --undefinesource --live --timeout 60 raise 'STUB' end