Class: Libvirt::Spec::Domain::OSBooting

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

Overview

The OS booting section of a domain specification indicates to libvirt how to configure the virtual machine to boot. There are three main ways to configure booting. Each hypervisor supports one or more of the following:

  1. BIOS bootloader
  2. Host bootloader
  3. Direct kernel boot

TODO: Host bootloader and direct kernel bootloader options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ OSBooting

Initializes an OS booting specification. This shouldn't be called directly since the domain spec automatically loads this.



34
35
36
37
38
# File 'lib/libvirt/spec/domain/os_booting.rb', line 34

def initialize(xml=nil)
  @boot = []

  load!(xml) if xml
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



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

def arch
  @arch
end

#bootObject

Returns the value of attribute boot.



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

def boot
  @boot
end

#bootloaderObject

Host bootloader configuration options



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

def bootloader
  @bootloader
end

#bootloader_argsObject

Returns the value of attribute bootloader_args.



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

def bootloader_args
  @bootloader_args
end

#bootmenu_enabledObject

Returns the value of attribute bootmenu_enabled.



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

def bootmenu_enabled
  @bootmenu_enabled
end

#cmdlineObject

Returns the value of attribute cmdline.



29
30
31
# File 'lib/libvirt/spec/domain/os_booting.rb', line 29

def cmdline
  @cmdline
end

#initrdObject

Returns the value of attribute initrd.



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

def initrd
  @initrd
end

#kernelObject

Direct kernel boot



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

def kernel
  @kernel
end

#loaderObject

Part of the BIOS bootloader



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

def loader
  @loader
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#load!(root) ⇒ Object

Loads the OS booting information from the given XML string. This shouldn't be called directly, since the domain spec automatically calls this.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/libvirt/spec/domain/os_booting.rb', line 49

def load!(root)
  root = Nokogiri::XML(root).root if !root.is_a?(Nokogiri::XML::Element)
  try(root.xpath("//os/type[@arch]"), :preserve => true) { |result| self.arch = result["arch"].to_sym }
  try(root.xpath("//os/type")) { |result| self.type = result.text.to_sym }

  try(root.xpath("//os/boot"), :multi => true) do |results|
    self.boot = []

    results.each do |result|
      self.boot << result["dev"].to_sym
    end
  end

  raise_if_unparseables(root.xpath("//os/*"))
end

#to_xml(parent = Nokogiri::XML::Builder.new) ⇒ Object

Convert just the OS booting section to its XML representation.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/libvirt/spec/domain/os_booting.rb', line 66

def to_xml(parent=Nokogiri::XML::Builder.new)
  parent.os do |os|
    # Build the arguments for the OS booting type
    type_args = [type]
    type_args << { :arch => arch } if arch

    # Setup the specification
    os.type_ *type_args
    os.loader loader if loader
    os.bootmenu(:enable => bootmenu_enabled ? 'yes' : 'no') if !bootmenu_enabled.nil?

    # Boot order for BIOS booting
    boot.each { |dev| os.boot :dev => dev } if boot.is_a?(Array)

    # Host bootloader configuration options
    os.bootloader bootloader if bootloader
    os.bootloader_args bootloader_args if bootloader_args

    # Direct kernel boot options
    os.kernel kernel if kernel
    os.initrd initrd if initrd
    os.cmdline cmdline if cmdline
  end

  parent.to_xml
end