class ForemanAP::Domain
A virtual machine or container, i.e. a “domain” within libvirt
Public Class Methods
new(conn, name, foreman_api)
click to toggle source
Create an object.
conn
-
A connection to libvirtd on a hypervisor
name
-
The name of the domain
foreman_api
-
A handle to a
ForemanAP::ForemanAPI
object.
# File lib/foreman_vm/domain.rb, line 65 def initialize(conn, name, foreman_api) @conn = conn @dom = conn.lookup_domain_by_name(name) @foreman_api = foreman_api end
Public Instance Methods
add_libgfapi_volume(volume_name, host_name, device_id)
click to toggle source
Add a storage volume that uses libgfapi.
volume_name
-
The name of the volume.
host_name
-
The FQDN or IP address of the GlusterFS server.
device_id
-
The position the disk appears on the SCSI bus, starting at one.
# File lib/foreman_vm/domain.rb, line 29 def add_libgfapi_volume(volume_name, host_name, device_id) # Determine the target disk name. target_dev = 'vd' + ('a'..'z').to_a[device_id - 1] disk_xml = REXML::Document.new " <disk type='network' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source protocol='gluster' name='#{volume_name}'> <host name='#{host_name}' port='0'/> </source> <target dev='#{target_dev}' bus='virtio'/> <alias name='virtio-disk#{device_id}'/> </disk> " # Modify the domain XML to insert the disk domain_xml = REXML::Document.new(@dom.xml_desc) #puts 'OLD: ' + domain_xml.to_s domain_xml.elements.each('domain/devices') do |ele| ele.add_element(disk_xml.root) end #puts 'NEW: ' + domain_xml.to_s @dom.undefine @dom = @conn.define_domain_xml(domain_xml.to_s) end
memory()
click to toggle source
Return the amount of memory allocated to the domain, in bytes
# File lib/foreman_vm/domain.rb, line 14 def memory # Convert from KiB to bytes @dom.info.max_mem.to_i * 1024 end
name()
click to toggle source
Return the hostname of the domain
# File lib/foreman_vm/domain.rb, line 9 def name @dom.name end
start()
click to toggle source
Start (power on) the domain
# File lib/foreman_vm/domain.rb, line 57 def start @dom.create end
vcpu_count()
click to toggle source
Return the number of vCPUs allocated to the domain
# File lib/foreman_vm/domain.rb, line 20 def vcpu_count @dom.info.nr_virt_cpu end