ovirt 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/README.md +1 -1
- data/lib/ovirt/api.rb +3 -4
- data/lib/ovirt/base.rb +47 -44
- data/lib/ovirt/cluster.rb +1 -1
- data/lib/ovirt/data_center.rb +1 -1
- data/lib/ovirt/event.rb +424 -424
- data/lib/ovirt/exception.rb +2 -2
- data/lib/ovirt/inventory.rb +7 -7
- data/lib/ovirt/logging.rb +5 -0
- data/lib/ovirt/null_logger.rb +11 -0
- data/lib/ovirt/service.rb +35 -45
- data/lib/ovirt/snapshot.rb +2 -2
- data/lib/ovirt/statistic.rb +4 -5
- data/lib/ovirt/storage_domain.rb +1 -1
- data/lib/ovirt/template.rb +28 -31
- data/lib/ovirt/user.rb +1 -1
- data/lib/ovirt/version.rb +1 -1
- data/lib/ovirt/vm.rb +18 -24
- data/lib/ovirt.rb +12 -0
- data/spec/base_spec.rb +7 -9
- data/spec/event_spec.rb +3 -13
- data/spec/factories/template.rb +37 -0
- data/spec/factories/vm.rb +1 -3
- data/spec/service_spec.rb +22 -23
- data/spec/spec_helper.rb +89 -9
- data/spec/template_spec.rb +23 -54
- data/spec/vm_spec.rb +47 -49
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330b709a4d48c804372bb18010dc08b36c17f09e
|
4
|
+
data.tar.gz: ade6e0ffc14e1b355b8310fa82b812b96a5d6006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b172bcb7fbdf20875b56ac693a3acd65b83c2e1d0f8c9fdfe4bd5bcbaaacb87746890270f1d06e8b0dc2861c3fc7dfa4582e415e3872a488e3fd0ea3cf5c1c0
|
7
|
+
data.tar.gz: 6b4adbd7bad28b51b166bab493b4fa71c6a0b3821eef90f6eee5b741153d6c4b2e1f97275ea9dc68ef606720d850802439deb42c865a202bfdf9f65a60a8efbd
|
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ovirt.svg)](http://badge.fury.io/rb/ovirt)
|
4
4
|
[![Build Status](https://travis-ci.org/ManageIQ/ovirt.svg)](https://travis-ci.org/ManageIQ/ovirt)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ManageIQ/ovirt.svg)](https://codeclimate.com/github/ManageIQ/ovirt)
|
6
|
-
[![Coverage Status](
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/ManageIQ/ovirt/badge.svg)](https://coveralls.io/github/ManageIQ/ovirt)
|
7
7
|
[![Dependency Status](https://gemnasium.com/ManageIQ/ovirt.svg)](https://gemnasium.com/ManageIQ/ovirt)
|
8
8
|
|
9
9
|
Ovirt provides a simple Object Oriented interface to the REST API of oVirt and RHEV-M servers.
|
data/lib/ovirt/api.rb
CHANGED
@@ -2,15 +2,15 @@ module Ovirt
|
|
2
2
|
class Api < Base
|
3
3
|
def self.parse_node_extended(node, hash)
|
4
4
|
parse_first_node(node, :product_info, hash,
|
5
|
-
:node
|
5
|
+
:node => [:name, :vendor])
|
6
6
|
|
7
7
|
parse_first_node_with_hash(node, 'product_info/version', hash[:product_info][:version] = {},
|
8
|
-
|
8
|
+
:attribute => [:major, :minor, :build, :revision])
|
9
9
|
|
10
10
|
hash[:summary] = {}
|
11
11
|
[:vms, :hosts, :users, :storage_domains].each do |type|
|
12
12
|
parse_first_node_with_hash(node, "summary/#{type}", hash[:summary][type] = {},
|
13
|
-
|
13
|
+
:node_to_i => [:total, :active])
|
14
14
|
end
|
15
15
|
|
16
16
|
hash[:special_objects] = {}
|
@@ -18,7 +18,6 @@ module Ovirt
|
|
18
18
|
hash[:special_objects][link['rel'].to_sym] = link['href']
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
# There should not be any actions defined on the api
|
23
22
|
hash.delete(:actions) if hash[:actions].empty?
|
24
23
|
end
|
data/lib/ovirt/base.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module Ovirt
|
2
2
|
class Base
|
3
|
+
extend Logging
|
4
|
+
include Logging
|
5
|
+
|
3
6
|
def self.create_from_xml(service, xml)
|
4
|
-
|
7
|
+
new(service, parse_xml(xml))
|
5
8
|
end
|
6
9
|
|
7
10
|
def self.xml_to_relationships(xml)
|
@@ -15,7 +18,7 @@ module Ovirt
|
|
15
18
|
end
|
16
19
|
|
17
20
|
def self.xml_to_actions(xml)
|
18
|
-
node
|
21
|
+
node = xml_to_nokogiri(xml)
|
19
22
|
actions = {}
|
20
23
|
node.xpath('actions/link').each do |link|
|
21
24
|
actions[link['rel'].to_sym] = link['href']
|
@@ -36,29 +39,29 @@ module Ovirt
|
|
36
39
|
raise "Cannot parse boolean for value: <#{what.inspect}>"
|
37
40
|
end
|
38
41
|
|
39
|
-
def self.parse_first_text(node, hash, key, modifier=nil)
|
42
|
+
def self.parse_first_text(node, hash, key, modifier = nil)
|
40
43
|
text_node = node.xpath(key.to_s).first
|
41
|
-
value
|
42
|
-
|
44
|
+
value = text_node.text unless text_node.nil?
|
45
|
+
set_value(value, hash, key, modifier)
|
43
46
|
end
|
44
47
|
|
45
|
-
def self.parse_attribute(node, hash, key, modifier=nil)
|
48
|
+
def self.parse_attribute(node, hash, key, modifier = nil)
|
46
49
|
value = node[key.to_s]
|
47
|
-
|
50
|
+
set_value(value, hash, key, modifier)
|
48
51
|
end
|
49
52
|
|
50
53
|
def self.set_value(value, hash, key, modifier)
|
51
54
|
return if value.nil?
|
52
55
|
hash[key] = case modifier
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
when :to_i then value.to_i
|
57
|
+
when :to_f then value.to_f
|
58
|
+
when :to_bool then parse_boolean(value)
|
59
|
+
else value
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
63
|
def self.parse_first_node(node, path, hash, options)
|
61
|
-
|
64
|
+
parse_first_node_with_hash(node, path, nh = {}, options)
|
62
65
|
unless nh.empty?
|
63
66
|
hash[path.to_sym] = hash[path.to_sym].nil? ? nh : hash[path.to_sym].merge(nh)
|
64
67
|
end
|
@@ -68,12 +71,12 @@ module Ovirt
|
|
68
71
|
def self.parse_first_node_with_hash(node, path, hash, options)
|
69
72
|
xnode = node.xpath(path.to_s).first
|
70
73
|
unless xnode.blank?
|
71
|
-
options[:attribute].to_a.each {|key|
|
72
|
-
options[:attribute_to_i].to_a.each {|key|
|
73
|
-
options[:attribute_to_f].to_a.each {|key|
|
74
|
-
options[:node].to_a.each {|key|
|
75
|
-
options[:node_to_i].to_a.each {|key|
|
76
|
-
options[:node_to_bool].to_a.each {|key|
|
74
|
+
options[:attribute].to_a.each { |key| parse_attribute(xnode, hash, key) }
|
75
|
+
options[:attribute_to_i].to_a.each { |key| parse_attribute(xnode, hash, key, :to_i) }
|
76
|
+
options[:attribute_to_f].to_a.each { |key| parse_attribute(xnode, hash, key, :to_f) }
|
77
|
+
options[:node].to_a.each { |key| parse_first_text(xnode, hash, key) }
|
78
|
+
options[:node_to_i].to_a.each { |key| parse_first_text(xnode, hash, key, :to_i) }
|
79
|
+
options[:node_to_bool].to_a.each { |key| parse_first_text(xnode, hash, key, :to_bool) }
|
77
80
|
end
|
78
81
|
end
|
79
82
|
|
@@ -81,40 +84,40 @@ module Ovirt
|
|
81
84
|
node.xpath(path.to_s).first.present?
|
82
85
|
end
|
83
86
|
|
84
|
-
|
85
|
-
|
87
|
+
class << self
|
88
|
+
attr_writer :top_level_objects
|
86
89
|
end
|
87
90
|
|
88
91
|
def self.top_level_objects
|
89
92
|
@top_level_objects ||= []
|
90
93
|
end
|
91
94
|
|
92
|
-
|
93
|
-
|
95
|
+
class << self
|
96
|
+
attr_writer :top_level_strings
|
94
97
|
end
|
95
98
|
|
96
99
|
def self.top_level_strings
|
97
100
|
@top_level_strings ||= []
|
98
101
|
end
|
99
102
|
|
100
|
-
|
101
|
-
|
103
|
+
class << self
|
104
|
+
attr_writer :top_level_integers
|
102
105
|
end
|
103
106
|
|
104
107
|
def self.top_level_integers
|
105
108
|
@top_level_integers ||= []
|
106
109
|
end
|
107
110
|
|
108
|
-
|
109
|
-
|
111
|
+
class << self
|
112
|
+
attr_writer :top_level_booleans
|
110
113
|
end
|
111
114
|
|
112
115
|
def self.top_level_booleans
|
113
116
|
@top_level_booleans ||= []
|
114
117
|
end
|
115
118
|
|
116
|
-
|
117
|
-
|
119
|
+
class << self
|
120
|
+
attr_writer :top_level_timestamps
|
118
121
|
end
|
119
122
|
|
120
123
|
def self.top_level_timestamps
|
@@ -173,7 +176,7 @@ module Ovirt
|
|
173
176
|
def self.href_from_creation_status_link(link)
|
174
177
|
# "/api/vms/5024ab49-19b5-4176-9568-c004d1c9f256/creation_status/d0e45003-d490-4551-9911-05b3bec682dc"
|
175
178
|
# => "/api/vms/5024ab49-19b5-4176-9568-c004d1c9f256"
|
176
|
-
link.split("/")[0,4].join("/")
|
179
|
+
link.split("/")[0, 4].join("/")
|
177
180
|
end
|
178
181
|
|
179
182
|
def self.href_to_guid(href)
|
@@ -208,16 +211,16 @@ module Ovirt
|
|
208
211
|
def self.all_xml_objects(service)
|
209
212
|
response = service.resource_get(api_endpoint)
|
210
213
|
doc = Nokogiri::XML(response)
|
211
|
-
|
214
|
+
doc.xpath("//#{element_names}/#{element_name}")
|
212
215
|
end
|
213
216
|
|
214
217
|
def self.all(service)
|
215
|
-
all_xml_objects(service).collect { |xml|
|
218
|
+
all_xml_objects(service).collect { |xml| create_from_xml(service, xml) }
|
216
219
|
end
|
217
220
|
|
218
221
|
def self.find_by_name(service, name)
|
219
222
|
all_xml_objects(service).each do |xml|
|
220
|
-
obj =
|
223
|
+
obj = create_from_xml(service, xml)
|
221
224
|
return obj if obj[:name] == name
|
222
225
|
end
|
223
226
|
nil
|
@@ -229,9 +232,9 @@ module Ovirt
|
|
229
232
|
|
230
233
|
def self.find_by_href(service, href)
|
231
234
|
response = service.resource_get(href)
|
232
|
-
doc
|
233
|
-
xml
|
234
|
-
|
235
|
+
doc = Nokogiri::XML(response)
|
236
|
+
xml = doc.xpath("//#{element_name}").first
|
237
|
+
create_from_xml(service, xml)
|
235
238
|
rescue RestClient::ResourceNotFound
|
236
239
|
return nil
|
237
240
|
end
|
@@ -241,7 +244,7 @@ module Ovirt
|
|
241
244
|
def initialize(service, options = {})
|
242
245
|
@service = service
|
243
246
|
@relationships = options.delete(:relationships) || {}
|
244
|
-
@operations = options.delete(:actions)
|
247
|
+
@operations = options.delete(:actions) || {}
|
245
248
|
@attributes = options
|
246
249
|
end
|
247
250
|
|
@@ -252,23 +255,23 @@ module Ovirt
|
|
252
255
|
end
|
253
256
|
|
254
257
|
def reload
|
255
|
-
|
258
|
+
replace(self.class.find_by_href(@service, self[:href]))
|
256
259
|
end
|
257
260
|
|
258
261
|
def method_missing(m, *args)
|
259
|
-
if @relationships.
|
262
|
+
if @relationships.key?(m)
|
260
263
|
relationship(m)
|
261
|
-
elsif @operations.
|
264
|
+
elsif @operations.key?(m)
|
262
265
|
operation(m, args)
|
263
|
-
elsif @attributes.
|
266
|
+
elsif @attributes.key?(m)
|
264
267
|
@attributes[m]
|
265
268
|
else
|
266
269
|
super
|
267
270
|
end
|
268
271
|
end
|
269
272
|
|
270
|
-
def operation(method, *
|
271
|
-
if @operations.
|
273
|
+
def operation(method, *_args)
|
274
|
+
if @operations.key?(method.to_sym)
|
272
275
|
builder = Nokogiri::XML::Builder.new do |xml|
|
273
276
|
xml.action { yield xml if block_given? }
|
274
277
|
end
|
@@ -281,7 +284,7 @@ module Ovirt
|
|
281
284
|
end
|
282
285
|
|
283
286
|
def relationship(rel)
|
284
|
-
if @relationships.
|
287
|
+
if @relationships.key?(rel.to_sym)
|
285
288
|
rel_str = rel.to_s
|
286
289
|
rel_str = 'storage_domains' if rel_str == 'storagedomains'
|
287
290
|
rel_str = 'data_centers' if rel_str == 'datacenters'
|
@@ -311,7 +314,7 @@ module Ovirt
|
|
311
314
|
response = update(&block)
|
312
315
|
|
313
316
|
obj = self.class.create_from_xml(@service, response)
|
314
|
-
|
317
|
+
replace(obj)
|
315
318
|
end
|
316
319
|
|
317
320
|
def update
|
data/lib/ovirt/cluster.rb
CHANGED
data/lib/ovirt/data_center.rb
CHANGED
@@ -12,7 +12,7 @@ module Ovirt
|
|
12
12
|
|
13
13
|
supported_versions_node = node.xpath('supported_versions').first
|
14
14
|
supported_versions = {}
|
15
|
-
supported_versions[:versions] = supported_versions_node.xpath('version').collect { |version_node| {
|
15
|
+
supported_versions[:versions] = supported_versions_node.xpath('version').collect { |version_node| {:major => version_node['major'].to_i, :minor => version_node['minor'].to_i} }
|
16
16
|
hash[:supported_versions] = supported_versions
|
17
17
|
end
|
18
18
|
end
|