class OVIRT::Template

Attributes

cluster[R]
comment[RW]
creation_time[R]
description[R]
display[R]
memory[R]
os[R]
profile[R]
status[R]
storage[R]
version[R]

Public Class Methods

new(client, xml) click to toggle source
Calls superclass method OVIRT::BaseObject::new
   # File lib/ovirt/template.rb
 6 def initialize(client, xml)
 7   super(client, xml[:id], xml[:href], (xml/'name').first.text)
 8   parse_xml_attributes!(xml)
 9   self
10 end
to_xml(opts={}) click to toggle source
   # File lib/ovirt/template.rb
12 def self.to_xml(opts={})
13   builder = Nokogiri::XML::Builder.new do
14     template_ {
15       name_ opts[:name] || "t-#{Time.now.to_i}"
16       description opts[:description] || ''
17       comment opts[:comment] || ''
18       vm(:id => opts[:vm])
19     }
20   end
21   Nokogiri::XML(builder.to_xml).root.to_s
22 end

Public Instance Methods

interfaces() click to toggle source
   # File lib/ovirt/template.rb
24 def interfaces
25   @interfaces ||= @client.template_interfaces(id)
26 end
volumes() click to toggle source
   # File lib/ovirt/template.rb
28 def volumes
29   @volumes ||= @client.template_volumes(id)
30 end

Private Instance Methods

parse_xml_attributes!(xml) click to toggle source
   # File lib/ovirt/template.rb
33 def parse_xml_attributes!(xml)
34   @description = ((xml/'description').first.text rescue '')
35   @comment = ((xml/'comment').first.text rescue '')
36   @version = TemplateVersion.new((xml/'version').first)
37   @status = ((xml/'status').first.text rescue 'unknown')
38   @memory = (xml/'memory').first.text
39   @profile = (xml/'type').first.text
40   @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
41   @display = {
42     :type => ((xml/'display/type').first.text rescue ''),
43     :monitors => ((xml/'display/monitors').first.text rescue 0)
44   }
45   @cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
46   @storage = ((xml/'disks/disk/size').first.text rescue nil)
47   @creation_time = (xml/'creation_time').text
48   @os = {
49       :type => (xml/'os').first[:type],
50       :boot => (xml/'os/boot').collect {|boot| boot[:dev] }
51   }
52 end