1
|
module OVIRT
|
2
|
|
3
|
class Volume < BaseObject
|
4
|
attr_reader :size, :disk_type, :bootable, :interface, :format, :sparse, :status, :storage_domain, :vm, :quota
|
5
|
|
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
|
11
|
|
12
|
def self.to_xml(storage_domain_id,opts={})
|
13
|
builder = Nokogiri::XML::Builder.new do
|
14
|
disk_{
|
15
|
storage_domains_{
|
16
|
storage_domain_(:id => storage_domain_id)
|
17
|
}
|
18
|
size_(opts[:size] || 8589934592)
|
19
|
type_(opts[:type] || 'data')
|
20
|
bootable_(opts[:bootable] || 'true')
|
21
|
interface_(opts[:interface] || 'virtio')
|
22
|
format_(opts[:format] || 'cow')
|
23
|
sparse_(opts[:sparse] || 'true')
|
24
|
if opts[:quota]
|
25
|
quota_( :id => opts[:quota])
|
26
|
end
|
27
|
}
|
28
|
end
|
29
|
Nokogiri::XML(builder.to_xml).root.to_s
|
30
|
end
|
31
|
|
32
|
def parse_xml_attributes!(xml)
|
33
|
@storage_domain = (xml/'storage_domains/storage_domain').first[:id] rescue nil
|
34
|
@size = (xml/'size').first.text
|
35
|
@disk_type = ((xml/'type').first.text rescue nil)
|
36
|
@bootable = (xml/'bootable').first.text
|
37
|
@interface = (xml/'interface').first.text
|
38
|
@format = (xml/'format').first.text rescue nil
|
39
|
@sparse = (xml/'sparse').first.text rescue nil
|
40
|
@status = ((xml/'status').first.text rescue nil)
|
41
|
@status ||= ((xml/'status/state').first.text rescue nil)
|
42
|
@vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href]) rescue nil
|
43
|
@quota = ((xml/'quota').first[:id] rescue nil)
|
44
|
end
|
45
|
|
46
|
end
|
47
|
end
|