Class: Libvirt::Spec::Domain

Inherits:
Object
  • Object
show all
Defined in:
lib/libvirt/spec/domain.rb,
lib/libvirt/spec/domain/os_booting.rb

Overview

A specification of a domain. This translates directly down to XML which can be used to define and launch domains on a node by libvirt.

Note: This class may only be temporary, and the functionality may be merged back into Domain. Also, the interface will likely change.

Defined Under Namespace

Classes: OSBooting

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Domain) initialize

A new instance of Domain



27
28
29
30
# File 'lib/libvirt/spec/domain.rb', line 27

def initialize
  @os = OSBooting.new
  @devices = []
end

Instance Attribute Details

- (Object) current_memory

Returns the value of attribute current_memory



18
19
20
# File 'lib/libvirt/spec/domain.rb', line 18

def current_memory
  @current_memory
end

- (Object) description

Returns the value of attribute description



15
16
17
# File 'lib/libvirt/spec/domain.rb', line 15

def description
  @description
end

- (Object) devices

Returns the value of attribute devices



25
26
27
# File 'lib/libvirt/spec/domain.rb', line 25

def devices
  @devices
end

- (Object) hypervisor

Returns the value of attribute hypervisor



12
13
14
# File 'lib/libvirt/spec/domain.rb', line 12

def hypervisor
  @hypervisor
end

- (Object) memory

Returns the value of attribute memory



17
18
19
# File 'lib/libvirt/spec/domain.rb', line 17

def memory
  @memory
end

- (Object) name

Returns the value of attribute name



13
14
15
# File 'lib/libvirt/spec/domain.rb', line 13

def name
  @name
end

- (Object) on_crash

Returns the value of attribute on_crash



23
24
25
# File 'lib/libvirt/spec/domain.rb', line 23

def on_crash
  @on_crash
end

- (Object) on_poweroff

Returns the value of attribute on_poweroff



21
22
23
# File 'lib/libvirt/spec/domain.rb', line 21

def on_poweroff
  @on_poweroff
end

- (Object) on_reboot

Returns the value of attribute on_reboot



22
23
24
# File 'lib/libvirt/spec/domain.rb', line 22

def on_reboot
  @on_reboot
end

- (Object) os

Returns the value of attribute os



16
17
18
# File 'lib/libvirt/spec/domain.rb', line 16

def os
  @os
end

- (Object) uuid

Returns the value of attribute uuid



14
15
16
# File 'lib/libvirt/spec/domain.rb', line 14

def uuid
  @uuid
end

- (Object) vcpu

Returns the value of attribute vcpu



19
20
21
# File 'lib/libvirt/spec/domain.rb', line 19

def vcpu
  @vcpu
end

Instance Method Details

- (String) to_xml

Returns the XML for this specification. This XML may be passed into libvirt to create a domain. This is actually the method which should be used for validation of this XML, since libvirt has great validation built in. If you define a domain and an error occurs, then it will notify you what is missing or wrong with the specification.

Returns:

  • (String)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/libvirt/spec/domain.rb', line 39

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.domain(:type => hypervisor) do
      # Name and description
      xml.name name if name
      xml.uuid uuid if uuid
      xml.description description if description

      # Operating system boot information
      os.to_xml(xml)

      # Basic resources
      xml.memory memory if memory
      xml.currentMemory current_memory if current_memory
      xml.vcpu vcpu if vcpu

      # Lifecycle control
      xml.on_poweroff on_poweroff if on_poweroff
      xml.on_reboot on_reboot if on_reboot
      xml.on_crash on_crash if on_crash

      # Devices
      if !devices.empty?
        xml.devices do
          devices.map { |d| d.to_xml(xml) }
        end
      end
    end
  end.to_xml
end