Class: OVIRT::Volume

Inherits:
BaseObject show all
Defined in:
lib/ovirt/volume.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#client, #href, #id, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObject

#parse_version

Constructor Details

#initialize(client, xml) ⇒ Volume

Returns a new instance of Volume.



6
7
8
9
10
# File 'lib/ovirt/volume.rb', line 6

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

Instance Attribute Details

#bootableObject (readonly)

Returns the value of attribute bootable.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def bootable
  @bootable
end

#disk_typeObject (readonly)

Returns the value of attribute disk_type.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def disk_type
  @disk_type
end

#formatObject (readonly)

Returns the value of attribute format.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def format
  @format
end

#interfaceObject (readonly)

Returns the value of attribute interface.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def interface
  @interface
end

#quotaObject (readonly)

Returns the value of attribute quota.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def quota
  @quota
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def size
  @size
end

#sparseObject (readonly)

Returns the value of attribute sparse.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def sparse
  @sparse
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def status
  @status
end

#storage_domainObject (readonly)

Returns the value of attribute storage_domain.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def storage_domain
  @storage_domain
end

#vmObject (readonly)

Returns the value of attribute vm.



4
5
6
# File 'lib/ovirt/volume.rb', line 4

def vm
  @vm
end

Class Method Details

.to_xml(storage_domain_id, opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ovirt/volume.rb', line 12

def self.to_xml(storage_domain_id,opts={})
   builder = Nokogiri::XML::Builder.new do
    disk_{
      storage_domains_{
        storage_domain_(:id => storage_domain_id)
      }
      size_(opts[:size] || 8589934592)
      type_(opts[:type] || 'data')
      bootable_(opts[:bootable] || 'true')
      interface_(opts[:interface] || 'virtio')
      format_(opts[:format] || 'cow')
      sparse_(opts[:sparse] || 'true')
      if opts[:quota]
        quota_( :id => opts[:quota])
      end
    }
  end
  Nokogiri::XML(builder.to_xml).root.to_s
end

Instance Method Details

#parse_xml_attributes!(xml) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ovirt/volume.rb', line 32

def parse_xml_attributes!(xml)
 @storage_domain = (xml/'storage_domains/storage_domain').first[:id]
 @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
 @sparse = (xml/'sparse').first.text
 @status = ((xml/'status').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