Sha256: a9b9ba581c97c656d189e0389bba27293b399712ba971973cbbae2c9f04e2e02

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

module OVIRT

  class Volume < BaseObject
    attr_reader :size, :disk_type, :bootable, :interface, :format, :sparse, :status, :storage_domain, :vm, :quota 

    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
        disk_{
          if opts[:storage_domain_id]
            storage_domains_{
              storage_domain_(:id => opts[:storage_domain_id])
            }
          end
          if opts[:size]
            size_(opts[:size])
          end
          if opts[:type]
            type_(opts[:type])
          end
          if opts[:bootable]
            bootable_(opts[:bootable])
          end
          if opts[:interface]
            interface_(opts[:interface])
          end
          if opts[:format]
            format_(opts[:format])
          end
          if opts[:sparse]
            sparse_(opts[:sparse])
          end
          if opts[:quota]
            quota_( :id => opts[:quota])
          end
        }
      end
      Nokogiri::XML(builder.to_xml).root.to_s
    end

    def parse_xml_attributes!(xml)
     @storage_domain = ((xml/'storage_domains/storage_domain').first[:id] rescue nil)
     @size = (xml/'size').first.text
     @disk_type = ((xml/'type').first.text rescue nil)
     @bootable = (xml/'bootable').first.text
     @interface = (xml/'interface').first.text
     @format = ((xml/'format').first.text rescue nil)
     @sparse = ((xml/'sparse').first.text rescue nil)
     @status = ((xml/'status/state').first.text rescue nil)
     @vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href]) rescue nil
     @quota = ((xml/'quota').first[:id] rescue nil)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbovirt-0.0.34 lib/ovirt/volume.rb
rbovirt-0.0.33 lib/ovirt/volume.rb
rbovirt-0.0.32 lib/ovirt/volume.rb
rbovirt-0.0.31 lib/ovirt/volume.rb
rbovirt-0.0.30 lib/ovirt/volume.rb