Class: Libvirt::Spec::Device::Disk
- Inherits:
-
Object
- Object
- Libvirt::Spec::Device::Disk
- Includes:
- Util
- Defined in:
- lib/libvirt/spec/device/disk.rb
Overview
Any device that looks like a disk, be it a floppy, harddisk, cdrom, or paravirtualized driver is specified via the disk element.
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#driver_cache ⇒ Object
Returns the value of attribute driver_cache.
-
#driver_type ⇒ Object
Returns the value of attribute driver_type.
-
#serial ⇒ Object
Returns the value of attribute serial.
-
#shareable ⇒ Object
Returns the value of attribute shareable.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target_bus ⇒ Object
Returns the value of attribute target_bus.
-
#target_dev ⇒ Object
Returns the value of attribute target_dev.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(xml = nil) ⇒ Disk
constructor
Initializes a new disk element.
-
#load!(xml) ⇒ Object
Loads data from XML.
-
#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object
Returns the XML representation of this device.
Methods included from Util
Constructor Details
#initialize(xml = nil) ⇒ Disk
Initializes a new disk element. If an XML string is passed then that will be used to initialize the attributes of the device.
24 25 26 27 28 |
# File 'lib/libvirt/spec/device/disk.rb', line 24 def initialize(xml=nil) @shareable = false load!(xml) if xml end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
11 12 13 |
# File 'lib/libvirt/spec/device/disk.rb', line 11 def device @device end |
#driver ⇒ Object
Returns the value of attribute driver.
15 16 17 |
# File 'lib/libvirt/spec/device/disk.rb', line 15 def driver @driver end |
#driver_cache ⇒ Object
Returns the value of attribute driver_cache.
17 18 19 |
# File 'lib/libvirt/spec/device/disk.rb', line 17 def driver_cache @driver_cache end |
#driver_type ⇒ Object
Returns the value of attribute driver_type.
16 17 18 |
# File 'lib/libvirt/spec/device/disk.rb', line 16 def driver_type @driver_type end |
#serial ⇒ Object
Returns the value of attribute serial.
19 20 21 |
# File 'lib/libvirt/spec/device/disk.rb', line 19 def serial @serial end |
#shareable ⇒ Object
Returns the value of attribute shareable.
18 19 20 |
# File 'lib/libvirt/spec/device/disk.rb', line 18 def shareable @shareable end |
#source ⇒ Object
Returns the value of attribute source.
12 13 14 |
# File 'lib/libvirt/spec/device/disk.rb', line 12 def source @source end |
#target_bus ⇒ Object
Returns the value of attribute target_bus.
14 15 16 |
# File 'lib/libvirt/spec/device/disk.rb', line 14 def target_bus @target_bus end |
#target_dev ⇒ Object
Returns the value of attribute target_dev.
13 14 15 |
# File 'lib/libvirt/spec/device/disk.rb', line 13 def target_dev @target_dev end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/libvirt/spec/device/disk.rb', line 10 def type @type end |
Instance Method Details
#load!(xml) ⇒ Object
Loads data from XML.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/libvirt/spec/device/disk.rb', line 31 def load!(xml) xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element) try(xml.xpath("//disk[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym } try(xml.xpath("//disk[@device]"), :preserve => true) { |result| self.device = result["device"].to_sym } try(xml.xpath("//disk/source")) { |result| self.source = result["dev"] || result["file"] } try(xml.xpath("//disk/target")) do |result| self.target_dev = result["dev"] self.target_bus = result["bus"] end raise_if_unparseables(xml.xpath("//disk/*")) end |
#to_xml(xml = Nokogiri::XML::Builder.new) ⇒ Object
Returns the XML representation of this device.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/libvirt/spec/device/disk.rb', line 46 def to_xml(xml=Nokogiri::XML::Builder.new) xml.disk(:type => type, :device => device) do |d| if source # Source tag, the attribute depends on the type. attribute = type == :block ? :dev : :file d.source(attribute => source) end if target_dev # Target tag has optional "bus" parameter = { :dev => target_dev } [:bus] = target_bus if target_bus d.target() end if driver # Driver tag has a couple optional parameters = { :name => driver } [:type] = driver_type if driver_type [:cache] = driver_cache if driver_cache d.driver() end d.shareable if shareable d.serial serial if serial end xml.to_xml end |