ovirt 0.7.2 → 0.8.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: 592fb6a64d52fa897faad834c4c5874bea89ac63
4
- data.tar.gz: 3b38a6108e3fa79e073929bc461fab31961c0c4e
3
+ metadata.gz: f0f4293560478cd39aa761c4aaec2b68b4b48fb6
4
+ data.tar.gz: ae54f822fcb29c456eb8216b99e49e829eb666b0
5
5
  SHA512:
6
- metadata.gz: bfa70c2fffa484403532a59f74184727bd65ca46e0976034f049383ca16d59f59403adaebe7a03a544e4d55b0dee5012876d8deb9014f7433e55f64a43a3e5de
7
- data.tar.gz: ea20ead44f3d4cf96bbc3b667d5d257a31745b32b6651e51377818e98fa3a67ffe56f347f99c0c4ffe41d485ffe1ce7a1e9fdfe169b00eb7149fd08e3acb51cf
6
+ metadata.gz: b820d2f7680c71664d9f4a066701ec9380c1527903ca747fc98b4e35f1362e3bcb2d19bed15fe58c523009e787e22a5e2526fe63a97e50ea82d16888a6d4e7c6
7
+ data.tar.gz: 86fc253644730f32b29bba7b83b8738af5cfac1ec1b7d1389212036467411c17a66007308be2d4f7b2c1c9164951ae4ed8f8b16d74645de889cb68d9585fcbbe
data/lib/ovirt/base.rb CHANGED
@@ -165,12 +165,9 @@ module Ovirt
165
165
  end
166
166
 
167
167
  def self.xml_to_nokogiri(xml)
168
- if xml.kind_of?(Nokogiri::XML::Element)
169
- nokogiri = xml
170
- else
171
- nokogiri = Nokogiri::XML(xml).root
172
- end
173
- nokogiri
168
+ return xml if xml.kind_of?(Nokogiri::XML::Element)
169
+
170
+ Nokogiri::XML(xml).root
174
171
  end
175
172
 
176
173
  def self.href_from_creation_status_link(link)
@@ -3,6 +3,7 @@ module Ovirt
3
3
  class Error < StandardError; end
4
4
 
5
5
  # Existence
6
+ class MissingResourceError < Error; end
6
7
  class TemplateAlreadyExists < Error; end
7
8
  class VmAlreadyExists < Error; end
8
9
 
@@ -90,8 +90,13 @@ module Ovirt
90
90
  def refresh
91
91
  # TODO: Change to not return native objects to the caller. The caller
92
92
  # should just expect raw data.
93
- primary_items = collect_primary_items
94
- collect_secondary_items(primary_items)
93
+ primary_items = collect_primary_jobs(primary_item_jobs)
94
+ collect_secondary_items(primary_items, SECONDARY_ITEMS)
95
+ end
96
+
97
+ def targeted_refresh(methods)
98
+ primary_items = collect_primary_targeted_jobs(methods[:primary].to_a)
99
+ collect_secondary_items(primary_items, methods[:secondary])
95
100
  end
96
101
 
97
102
  private
@@ -130,15 +135,13 @@ module Ovirt
130
135
  #
131
136
  # > secondary_item_jobs({:vm, => [v1, v2]})
132
137
  # => [[v1, :disks], [v1, :snapshots], [v1, :nics], [v2, :disks], [v2, :snapshots], [v2, :nics]]
133
- def secondary_item_jobs(primary_items)
134
- SECONDARY_ITEMS.flat_map do |key, methods|
138
+ def secondary_item_jobs(primary_items, secondary_items)
139
+ secondary_items.flat_map do |key, methods|
135
140
  primary_items[key].product(methods)
136
141
  end
137
142
  end
138
143
 
139
- def collect_primary_items
140
- jobs = primary_item_jobs
141
-
144
+ def collect_primary_jobs(jobs)
142
145
  results = collect_in_parallel(jobs) do |_, method|
143
146
  send(method)
144
147
  end
@@ -148,8 +151,18 @@ module Ovirt
148
151
  end
149
152
  end
150
153
 
151
- def collect_secondary_items(primary_items)
152
- jobs = secondary_item_jobs(primary_items)
154
+ def collect_primary_targeted_jobs(jobs)
155
+ results = collect_in_parallel(jobs) do |key, ems_ref|
156
+ get_resource_by_ems_ref(ems_ref, key.to_s)
157
+ end
158
+
159
+ jobs.zip(results).each_with_object({}) do |((key, _), result), hash|
160
+ hash[key] = result
161
+ end
162
+ end
163
+
164
+ def collect_secondary_items(primary_items, secondary_items)
165
+ jobs = secondary_item_jobs(primary_items, secondary_items)
153
166
 
154
167
  results = collect_in_parallel(jobs) do |resource, method|
155
168
  resource.send(method) rescue nil
data/lib/ovirt/service.rb CHANGED
@@ -68,6 +68,24 @@ module Ovirt
68
68
  api(true)[:summary] # This is volatile information
69
69
  end
70
70
 
71
+ def ca_certificate
72
+ @ca_certificate ||= verify_certificate(get_ca_certificate)
73
+ end
74
+
75
+ def verify_certificate(certificate)
76
+ return if certificate.to_s.strip.empty?
77
+
78
+ require 'openssl'
79
+ OpenSSL::X509::Certificate.new(certificate).to_s
80
+ rescue OpenSSL::X509::CertificateError
81
+ end
82
+
83
+ def get_ca_certificate
84
+ require "rest-client"
85
+ RestClient::Resource.new("#{base_uri}/ca.crt", resource_options).get
86
+ rescue RestClient::ResourceNotFound
87
+ end
88
+
71
89
  def special_objects
72
90
  @special_objects ||= api[:special_objects]
73
91
  end
@@ -102,7 +120,8 @@ module Ovirt
102
120
  doc = Nokogiri::XML(xml)
103
121
  element_name ||= doc.root.name
104
122
  klass = self.class.name_to_class(element_name)
105
- xml_to_object(klass, doc.root)
123
+ objects = doc.xpath("//#{element_name}")
124
+ objects.collect { |obj| xml_to_object(klass, obj) }
106
125
  end
107
126
 
108
127
  def standard_collection(uri_suffix, element_name = nil, paginate = false, sort_by = :name, direction = :asc)
@@ -202,8 +221,8 @@ module Ovirt
202
221
  case response.code
203
222
  when 200..206
204
223
  parse_normal_response(response, resource)
205
- when 400, 409
206
- parse_error_response(response)
224
+ when 400..409
225
+ parse_error_response(response, resource)
207
226
  else
208
227
  response.return!(request, result, &block)
209
228
  end
@@ -230,7 +249,9 @@ module Ovirt
230
249
  response
231
250
  end
232
251
 
233
- def parse_error_response(response)
252
+ def parse_error_response(response, resource)
253
+ logger.error "#{self.class.name}#parse_error_response Return from URL: <#{resource.url}> Data:#{response}"
254
+ raise Ovirt::MissingResourceError if response.code == 404
234
255
  doc = Nokogiri::XML(response)
235
256
  action = doc.xpath("action").first
236
257
  node = action || doc
data/lib/ovirt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ovirt
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  factory :service, :class => "Ovirt::Service" do
3
- initialize_with { new(:server => "", :username => "", :password => "") }
3
+ server ""
4
+ initialize_with { new(:server => server, :username => "", :password => "") }
4
5
  end
5
6
  end
data/spec/service_spec.rb CHANGED
@@ -43,11 +43,110 @@ EOX
43
43
  end
44
44
  end
45
45
 
46
+ describe "#ca_certificate" do
47
+ let(:letsencrypt_org_certificate) do
48
+ <<-EOC
49
+ -----BEGIN CERTIFICATE-----
50
+ MIIFYDCCA0igAwIBAgIQCgFCgAAAAUUjyES1AAAAAjANBgkqhkiG9w0BAQsFADBK
51
+ MQswCQYDVQQGEwJVUzESMBAGA1UEChMJSWRlblRydXN0MScwJQYDVQQDEx5JZGVu
52
+ VHJ1c3QgQ29tbWVyY2lhbCBSb290IENBIDEwHhcNMTQwMTE2MTgxMjIzWhcNMzQw
53
+ MTE2MTgxMjIzWjBKMQswCQYDVQQGEwJVUzESMBAGA1UEChMJSWRlblRydXN0MScw
54
+ JQYDVQQDEx5JZGVuVHJ1c3QgQ29tbWVyY2lhbCBSb290IENBIDEwggIiMA0GCSqG
55
+ SIb3DQEBAQUAA4ICDwAwggIKAoICAQCnUBneP5k91DNG8W9RYYKyqU+PZ4ldhNlT
56
+ 3Qwo2dfw/66VQ3KZ+bVdfIrBQuExUHTRgQ18zZshq0PirK1ehm7zCYofWjK9ouuU
57
+ +ehcCuz/mNKvcbO0U59Oh++SvL3sTzIwiEsXXlfEU8L2ApeN2WIrvyQfYo3fw7gp
58
+ S0l4PJNgiCL8mdo2yMKi1CxUAGc1bnO/AljwpN3lsKImesrgNqUZFvX9t++uP0D1
59
+ bVoE/c40yiTcdCMbXTMTEl3EASX2MN0CXZ/g1Ue9tOsbobtJSdifWwLziuQkkORi
60
+ T0/Br4sOdBeo0XKIanoBScy0RnnGF7HamB4HWfp1IYVl3ZBWzvurpWCdxJ35UrCL
61
+ vYf5jysjCiN2O/cz4ckA82n5S6LgTrx+kzmEB/dEcH7+B1rlsazRGMzyNeVJSQjK
62
+ Vsk9+w8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aOjfAHN3Gf8qv8QfXBi+wAN10J5U6A
78
+ 7/qxXDgGpRtK4dw4LTzcqx+QGtVKnO7RcGzM7vRX+Bi6hG6H
79
+ -----END CERTIFICATE-----
80
+ EOC
81
+ end
82
+ let(:rest_client_resource_double) { double("RestClient::Resource") }
83
+ let(:service) { build(:service, :server => "test.example.com") }
84
+
85
+ before { allow(RestClient::Resource).to receive(:new).and_return(rest_client_resource_double) }
86
+
87
+ it 'with a valid certificate' do
88
+ expect(rest_client_resource_double).to receive(:get).once.and_return(letsencrypt_org_certificate)
89
+
90
+ 2.times { expect(service.ca_certificate).to eq(letsencrypt_org_certificate) }
91
+ end
92
+
93
+ it "with invalid certificate" do
94
+ expect(rest_client_resource_double).to receive(:get).and_return("ABCDEFG", " ", nil)
95
+
96
+ 3.times { expect(service.ca_certificate).to eq(nil) }
97
+ end
98
+
99
+ it "server doesn't respond" do
100
+ expect(rest_client_resource_double).to receive(:get).and_raise(RestClient::ResourceNotFound)
101
+
102
+ expect(service.ca_certificate).to eq(nil)
103
+ end
104
+ end
105
+
46
106
  it "#resource_get on exception" do
47
107
  allow(service).to receive(:create_resource).and_raise(Exception, "BLAH")
48
108
  expect { service.resource_get('api') }.to raise_error(Exception, "BLAH")
49
109
  end
50
110
 
111
+ context "#get_resource_by_ems_ref" do
112
+ it "fetches data_center" do
113
+ return_message = <<-EOX.chomp
114
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
115
+ <data_center href="/api/datacenters/00000001-0001-0001-0001-0000000000f1" id="00000001-0001-0001-0001-0000000000f1">
116
+ <name>Default</name>
117
+ <description>The default Data Center</description>
118
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/storagedomains" rel="storagedomains"/>
119
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/clusters" rel="clusters"/>
120
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/networks" rel="networks"/>
121
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/permissions" rel="permissions"/>
122
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/quotas" rel="quotas"/>
123
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/qoss" rel="qoss"/>
124
+ <link href="/api/datacenters/00000001-0001-0001-0001-0000000000f1/iscsibonds" rel="iscsibonds"/>
125
+ <local>false</local>
126
+ <storage_format>v3</storage_format>
127
+ <version major="3" minor="6"/>
128
+ <supported_versions>
129
+ <version major="3" minor="6"/>
130
+ </supported_versions>
131
+ <status>
132
+ <state>up</state>
133
+ </status>
134
+ <mac_pool href="/api/macpools/0000000d-000d-000d-000d-00000000037a" id="0000000d-000d-000d-000d-00000000037a"/>
135
+ <quota_mode>disabled</quota_mode>
136
+ </data_center>
137
+ EOX
138
+ expect(service).to receive(:resource_get).and_return(return_message)
139
+
140
+ data_center = service.get_resource_by_ems_ref("/api/datacenters/00000001-0001-0001-0001-0000000000f1")
141
+ expect(data_center[0].name).to eq "Default"
142
+ end
143
+
144
+ it "returns 404" do
145
+ expect(service).to receive(:resource_get).and_raise(Ovirt::MissingResourceError)
146
+ expect { service.get_resource_by_ems_ref("/api/vms/1234") }.to raise_error(Ovirt::MissingResourceError)
147
+ end
148
+ end
149
+
51
150
  context ".ovirt?" do
52
151
  it "false when ResourceNotFound" do
53
152
  expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_raise(RestClient::ResourceNotFound)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Frey
@@ -14,10 +14,12 @@ authors:
14
14
  - Richard Oliveri
15
15
  - Chris Portman
16
16
  - Adam Grare
17
+ - Dávid Halász
18
+ - pkliczewski
17
19
  autorequire:
18
20
  bindir: bin
19
21
  cert_chain: []
20
- date: 2016-02-23 00:00:00.000000000 Z
22
+ date: 2016-04-16 00:00:00.000000000 Z
21
23
  dependencies:
22
24
  - !ruby/object:Gem::Dependency
23
25
  name: bundler
@@ -163,7 +165,7 @@ description: Ovirt provides a simple Object Oriented interface to the REST API o
163
165
  oVirt and RHEV-M servers.
164
166
  email:
165
167
  - fryguy9@gmail.com
166
- - bdunne@redhat.com
168
+ - brandondunne@hotmail.com
167
169
  - keenan@thebrocks.net
168
170
  - jrafanie@redhat.com
169
171
  - gblomqui@redhat.com
@@ -172,6 +174,8 @@ email:
172
174
  - roliveri@redhat.com
173
175
  - chris.portman@optusnet.com.au
174
176
  - agrare@redhat.com
177
+ - dhalasz@redhat.com
178
+ - piotr.kliczewski@gmail.com
175
179
  executables: []
176
180
  extensions: []
177
181
  extra_rdoc_files: []