Sha256: bcd92279e516e25e6cac6bc621835dfeaa40d5c49e182bc57bc0a79728a7e163

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

module OVIRT
  class Template < BaseObject
    attr_reader :description, :status, :cluster

    def initialize(client, xml)
      super(client, xml[:id], xml[:href], (xml/'name').first.text)
      parse_xml_attributes!(xml)
      self
    end

    def self.to_xml(opts={})
      builder = Nokogiri::XML::Builder.new do
        template_ {
          name_ opts[:name] || "t-#{Time.now.to_i}"
          description opts[:description] || ''
          vm(:id => opts[:vm])
        }
      end
      Nokogiri::XML(builder.to_xml).root.to_s
    end

    def interfaces
      @interfaces ||= @client.template_interfaces(id)
    end

    def volumes
      @volumes ||= @client.send(:volumes, "/templates/%s/disks" % id)
    end

    private
    def parse_xml_attributes!(xml)
      @description = ((xml/'description').first.text rescue '')
      @status = ((xml/'status').first.text rescue 'unknown')
      @memory = (xml/'memory').first.text
      @profile = (xml/'type').first.text
      @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
      @display = {
        :type => (xml/'display/type').first.text,
        :monitors => (xml/'display/monitors').first.text
      }
      @cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
      @storage = ((xml/'disks/disk/size').first.text rescue nil)
      @creation_time = (xml/'creation_time').text
      @os = {
          :type => (xml/'os').first[:type],
          :boot => (xml/'os/boot').collect {|boot| boot[:dev] }
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbovirt-0.0.12 lib/ovirt/template.rb
rbovirt-0.0.11 lib/ovirt/template.rb
rbovirt-0.0.10 lib/ovirt/template.rb
rbovirt-0.0.9 lib/ovirt/template.rb
rbovirt-0.0.8 lib/ovirt/template.rb