Class: ForemanAP::Domain
- Inherits:
-
Object
- Object
- ForemanAP::Domain
- Defined in:
- lib/foreman_vm/domain.rb
Overview
A virtual machine or container, i.e. a “domain” within libvirt
Instance Method Summary collapse
-
#add_libgfapi_volume(volume_name, host_name, device_id) ⇒ Object
Add a storage volume that uses libgfapi.
-
#initialize(conn, name, foreman_api) ⇒ Domain
constructor
Create an object.
-
#memory ⇒ Object
Return the amount of memory allocated to the domain, in bytes.
-
#name ⇒ Object
Return the hostname of the domain.
-
#start ⇒ Object
Start (power on) the domain.
-
#vcpu_count ⇒ Object
Return the number of vCPUs allocated to the domain.
Constructor Details
#initialize(conn, name, foreman_api) ⇒ Domain
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.
65 66 67 68 69 |
# 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 |
Instance Method Details
#add_libgfapi_volume(volume_name, host_name, device_id) ⇒ Object
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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
Return the amount of memory allocated to the domain, in bytes
14 15 16 17 |
# File 'lib/foreman_vm/domain.rb', line 14 def memory # Convert from KiB to bytes @dom.info.max_mem.to_i * 1024 end |
#name ⇒ Object
Return the hostname of the domain
9 10 11 |
# File 'lib/foreman_vm/domain.rb', line 9 def name @dom.name end |
#start ⇒ Object
Start (power on) the domain
57 58 59 |
# File 'lib/foreman_vm/domain.rb', line 57 def start @dom.create end |
#vcpu_count ⇒ Object
Return the number of vCPUs allocated to the domain
20 21 22 |
# File 'lib/foreman_vm/domain.rb', line 20 def vcpu_count @dom.info.nr_virt_cpu end |