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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8e5086cc3efac6612e4e1631b5af6d14c6c5280
4
- data.tar.gz: 25b06d7e055266368c2a3bf5ce9348a464459a9a
3
+ metadata.gz: 330b709a4d48c804372bb18010dc08b36c17f09e
4
+ data.tar.gz: ade6e0ffc14e1b355b8310fa82b812b96a5d6006
5
5
  SHA512:
6
- metadata.gz: d0fd8d69ed5af1e4392a023307b4165baea65a35c009d6da188f01e072d1caf5c2e06d2cc8d9683b0879d7fc204a233e334171f999812a3eac047b9c1f8e1ed7
7
- data.tar.gz: daad3060acc9154fb9271c9e24ca2e3202ba5b82d7075cc21809a9a0c45312050fabb95dbcd85ea775dc3c19e1a85ac195c384f9a2f593af214d55b13dbf20a2
6
+ metadata.gz: 2b172bcb7fbdf20875b56ac693a3acd65b83c2e1d0f8c9fdfe4bd5bcbaaacb87746890270f1d06e8b0dc2861c3fc7dfa4582e415e3872a488e3fd0ea3cf5c1c0
7
+ data.tar.gz: 6b4adbd7bad28b51b166bab493b4fa71c6a0b3821eef90f6eee5b741153d6c4b2e1f97275ea9dc68ef606720d850802439deb42c865a202bfdf9f65a60a8efbd
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
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](http://img.shields.io/coveralls/ManageIQ/ovirt.svg)](https://coveralls.io/r/ManageIQ/ovirt)
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 => [:name, :vendor])
5
+ :node => [:name, :vendor])
6
6
 
7
7
  parse_first_node_with_hash(node, 'product_info/version', hash[:product_info][:version] = {},
8
- :attribute => [:major, :minor, :build, :revision])
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
- :node_to_i => [:total, :active])
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
- self.new(service, parse_xml(xml))
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 = xml_to_nokogiri(xml)
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 = text_node.text unless text_node.nil?
42
- self.set_value(value, hash, key, modifier)
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
- self.set_value(value, hash, key, modifier)
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
- when :to_i then value.to_i
54
- when :to_f then value.to_f
55
- when :to_bool then self.parse_boolean(value)
56
- else value
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
- self.parse_first_node_with_hash(node, path, nh = {}, options)
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| self.parse_attribute( xnode, hash, key)}
72
- options[:attribute_to_i].to_a.each {|key| self.parse_attribute( xnode, hash, key, :to_i)}
73
- options[:attribute_to_f].to_a.each {|key| self.parse_attribute( xnode, hash, key, :to_f)}
74
- options[:node].to_a.each {|key| self.parse_first_text(xnode, hash, key)}
75
- options[:node_to_i].to_a.each {|key| self.parse_first_text(xnode, hash, key, :to_i)}
76
- options[:node_to_bool].to_a.each {|key| self.parse_first_text(xnode, hash, key, :to_bool)}
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
- def self.top_level_objects=(keys)
85
- @top_level_objects = keys
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
- def self.top_level_strings=(keys)
93
- @top_level_strings = keys
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
- def self.top_level_integers=(keys)
101
- @top_level_integers = keys
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
- def self.top_level_booleans=(keys)
109
- @top_level_booleans = keys
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
- def self.top_level_timestamps=(keys)
117
- @top_level_timestamps = keys
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
- objects = doc.xpath("//#{element_names}/#{element_name}")
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| self.create_from_xml(service, 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 = self.create_from_xml(service, xml)
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 = Nokogiri::XML(response)
233
- xml = doc.xpath("//#{element_name}").first
234
- self.create_from_xml(service, xml)
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
- self.replace(self.class.find_by_href(@service, self[:href]))
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.has_key?(m)
262
+ if @relationships.key?(m)
260
263
  relationship(m)
261
- elsif @operations.has_key?(m)
264
+ elsif @operations.key?(m)
262
265
  operation(m, args)
263
- elsif @attributes.has_key?(m)
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, *args)
271
- if @operations.has_key?(method.to_sym)
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.has_key?(rel.to_sym)
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
- self.replace(obj)
317
+ replace(obj)
315
318
  end
316
319
 
317
320
  def update
data/lib/ovirt/cluster.rb CHANGED
@@ -16,7 +16,7 @@ module Ovirt
16
16
  end
17
17
 
18
18
  def find_network_by_name(network_name)
19
- self.networks.detect { |n| n[:name] == network_name }
19
+ networks.detect { |n| n[:name] == network_name }
20
20
  end
21
21
  end
22
22
  end
@@ -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| { :major => version_node['major'].to_i, :minor => version_node['minor'].to_i } }
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