Module: Libvirt::Spec::Device

Defined in:
lib/libvirt/spec/device.rb,
lib/libvirt/spec/device/disk.rb,
lib/libvirt/spec/device/input.rb,
lib/libvirt/spec/device/sound.rb,
lib/libvirt/spec/device/video.rb,
lib/libvirt/spec/device/emulator.rb,
lib/libvirt/spec/device/graphics.rb,
lib/libvirt/spec/device/interface.rb,
lib/libvirt/spec/device/video_model.rb

Defined Under Namespace

Classes: Disk, Emulator, Graphics, Input, Interface, Sound, Video, VideoModel

Class Method Summary collapse

Class Method Details

.get(name) ⇒ Class

Returns the class of a device based on the name. If :disk were given, for example, then a Disk class would be returned. Note that since the class is returned, and not an instance, it is up to the caller to instantiate the returned class.

Parameters:

  • name (Symbol)

Returns:

  • (Class)


30
31
32
# File 'lib/libvirt/spec/device.rb', line 30

def self.get(name)
  const_get(name.to_s.capitalize)
end

.load!(xml) ⇒ Device

Loads a device from an XML string. This will automatically find the proper class to load and return that.

Returns:



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

def self.load!(xml)
  xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
  get(xml.name).new(xml)
end