Class: Libvirt::Spec::Device::VideoModel

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

Overview

Represents a model in the specific video device.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#raise_if_unparseables, #try

Constructor Details

#initialize(xml = nil) ⇒ VideoModel

Initializes a new video model device. If an XML string is given, it will be used to attempt to initialize the attributes.



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

def initialize(xml=nil)
  load!(xml) if xml
end

Instance Attribute Details

#accel2dObject

Returns the value of attribute accel2d.



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

def accel2d
  @accel2d
end

#accel3dObject

Returns the value of attribute accel3d.



11
12
13
# File 'lib/libvirt/spec/device/video_model.rb', line 11

def accel3d
  @accel3d
end

#headsObject

Returns the value of attribute heads.



10
11
12
# File 'lib/libvirt/spec/device/video_model.rb', line 10

def heads
  @heads
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/libvirt/spec/device/video_model.rb', line 8

def type
  @type
end

#vramObject

Returns the value of attribute vram.



9
10
11
# File 'lib/libvirt/spec/device/video_model.rb', line 9

def vram
  @vram
end

Instance Method Details

#load!(xml) ⇒ Object

Attempts to initialize object attributes based on the XML strings given.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/libvirt/spec/device/video_model.rb', line 22

def load!(xml)
  xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
  try(xml.xpath("//model[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym }
  try(xml.xpath("//model[@vram]"), :preserve => true) { |result| self.vram = result["vram"] }
  try(xml.xpath("//model[@heads]"), :preserve => true) { |result| self.heads = result["heads"] }
  try(xml.xpath("//model/acceleration")) do |result|
    self.accel3d = result["accel3d"] == "yes"
    self.accel2d = result["accel2d"] == "yes"
  end

  raise_if_unparseables(xml.xpath("//model/*"))
end

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

Returns the XML representation of this device.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/libvirt/spec/device/video_model.rb', line 36

def to_xml(xml=Nokogiri::XML::Builder.new)
  options = { :type => type }
  options[:vram] = vram if vram
  options[:heads] = heads if heads

  xml.model(options) do |m|
    a3d = accel3d ? "yes" : "no"
    a2d = accel2d ? "yes" : "no"

    m.acceleration(:accel3d => a3d, :accel2d => a2d)
  end

  xml.to_xml
end