ovirt 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/ovirt/inventory.rb +4 -1
- data/lib/ovirt/service.rb +3 -0
- data/lib/ovirt/template.rb +12 -3
- data/lib/ovirt/version.rb +1 -1
- data/spec/factories/template.rb +31 -0
- data/spec/service_spec.rb +41 -0
- data/spec/template_spec.rb +82 -3
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f613c2d824b0dbb9ba03acef085787bb0a173c35
|
4
|
+
data.tar.gz: d3678ad7665af01b60c8b2c9bdb2e1a1c013db76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9acc652791095ccdaf69511f4fb51fc0b2b5a8c009ef2d68cf949c94a8848f29249f79e125f89f70811c78db247fdad41c3d4ea37412d9531f817465cdb7978
|
7
|
+
data.tar.gz: 3ad7fb06019661a9899bdf3dbc058b4fc2140c4c76ecc67be09c6c1ab0253a1b7ed6b5edea07fcd008bb6be779ed5250be5c270b6a4586280523574aa65787d5
|
data/README.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ManageIQ/ovirt.svg)](https://codeclimate.com/github/ManageIQ/ovirt)
|
6
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
|
+
[![Security](https://hakiri.io/github/ManageIQ/ovirt/master.svg)](https://hakiri.io/github/ManageIQ/ovirt/master)
|
8
9
|
|
9
10
|
Ovirt provides a simple Object Oriented interface to the REST API of oVirt and RHEV-M servers.
|
10
11
|
|
data/lib/ovirt/inventory.rb
CHANGED
@@ -130,7 +130,7 @@ module Ovirt
|
|
130
130
|
SECONDARY_ITEMS = {
|
131
131
|
# Key RHEVM API methods
|
132
132
|
:datacenter => [:storagedomains],
|
133
|
-
:host => [:statistics, :
|
133
|
+
:host => [:statistics, :host_nics], # :cdroms, tags
|
134
134
|
:vm => [:disks, :snapshots, :nics],
|
135
135
|
:template => [:disks]
|
136
136
|
}
|
@@ -163,6 +163,9 @@ module Ovirt
|
|
163
163
|
results = collect_in_parallel(jobs) do |key, ems_ref|
|
164
164
|
if ems_ref.kind_of?(Array)
|
165
165
|
ems_ref.flat_map { |item| get_resources_by_uri_path(item) rescue Array.new }
|
166
|
+
elsif ems_ref.kind_of?(Hash)
|
167
|
+
collection, element_name = ems_ref.first
|
168
|
+
standard_collection(collection, element_name, true)
|
166
169
|
else
|
167
170
|
get_resources_by_uri_path(ems_ref) rescue Array.new
|
168
171
|
end
|
data/lib/ovirt/service.rb
CHANGED
@@ -173,6 +173,8 @@ module Ovirt
|
|
173
173
|
request.get
|
174
174
|
rescue RestClient::Exception => exception
|
175
175
|
response = exception.response
|
176
|
+
logger.error "#{self.class.name}#probe_api_path: exception probing uri: '#{uri}'. Exception: #{$ERROR_INFO}"
|
177
|
+
return false if response.nil?
|
176
178
|
if response.code == 401
|
177
179
|
www_authenticate = response.headers[:www_authenticate]
|
178
180
|
if www_authenticate =~ /^Basic realm="?(RESTAPI|ENGINE)"?$/
|
@@ -307,6 +309,7 @@ module Ovirt
|
|
307
309
|
def parse_error_response(response, resource)
|
308
310
|
logger.error "#{self.class.name}#parse_error_response Return from URL: <#{resource.url}> Data:#{response}"
|
309
311
|
raise Ovirt::MissingResourceError if response.code == 404
|
312
|
+
raise RestClient::Unauthorized if response.code == 401
|
310
313
|
doc = Nokogiri::XML(response)
|
311
314
|
action = doc.xpath("action").first
|
312
315
|
node = action || doc
|
data/lib/ovirt/template.rb
CHANGED
@@ -44,6 +44,10 @@ module Ovirt
|
|
44
44
|
attributes.fetch_path(:os, :type) || 'unassigned'
|
45
45
|
end
|
46
46
|
|
47
|
+
def boot_order
|
48
|
+
attributes.fetch_path(:os, :boot_order) || []
|
49
|
+
end
|
50
|
+
|
47
51
|
def getCfg(_snap = nil)
|
48
52
|
# TODO: Remove the following MiqException and any others
|
49
53
|
raise MiqException::MiqVimError, "Failed to retrieve configuration information for VM" if attributes.nil?
|
@@ -102,7 +106,8 @@ module Ovirt
|
|
102
106
|
(CLONE_ATTRIBUTES_WITH_SCALARS + CLONE_ATTRIBUTES_WITH_HASHES).each do |key|
|
103
107
|
options[key] ||= self[key]
|
104
108
|
end
|
105
|
-
options[:
|
109
|
+
options[:os] = self[:os].dup
|
110
|
+
options[:os][:type] = options[:os_type] || os_type
|
106
111
|
|
107
112
|
skeleton_options = options.dup
|
108
113
|
skeleton_options[:clone_type] = :linked
|
@@ -152,8 +157,12 @@ module Ovirt
|
|
152
157
|
end
|
153
158
|
end
|
154
159
|
|
155
|
-
|
156
|
-
|
160
|
+
options_os_type = options.fetch_path(:os, :type) || options[:os_type]
|
161
|
+
xml.os(:type => options_os_type || os_type) do
|
162
|
+
options_boot_order = options.fetch_path(:os, :boot_order)
|
163
|
+
(options_boot_order || boot_order).each do |boot|
|
164
|
+
xml.boot(:dev => boot[:dev])
|
165
|
+
end
|
157
166
|
end
|
158
167
|
|
159
168
|
if options[:clone_type] == :full
|
data/lib/ovirt/version.rb
CHANGED
data/spec/factories/template.rb
CHANGED
@@ -34,4 +34,35 @@ FactoryGirl.define do
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
factory :template_blank, :parent => :template do
|
39
|
+
initialize_with do
|
40
|
+
new(service,
|
41
|
+
:id => "00000000-0000-0000-0000-000000000000",
|
42
|
+
:href => "/api/vms/00000000-0000-0000-0000-000000000000",
|
43
|
+
:cluster => {
|
44
|
+
:id => "5be5d08a-a60b-11e2-bee6-005056a217db",
|
45
|
+
:href => "/api/clusters/5be5d08a-a60b-11e2-bee6-005056a217db"},
|
46
|
+
:template => {
|
47
|
+
:id => "00000000-0000-0000-0000-000000000000",
|
48
|
+
:href => "/api/templates/00000000-0000-0000-0000-000000000000"},
|
49
|
+
:name => "Blank",
|
50
|
+
:origin => "rhev",
|
51
|
+
:type => "server",
|
52
|
+
:memory => 1_073_741_824,
|
53
|
+
:stateless => false,
|
54
|
+
:creation_time => "2013-09-04 16:24:20 -0400",
|
55
|
+
:status => {:state => "down"},
|
56
|
+
:display => {:type => "spice", :monitors => 1},
|
57
|
+
:usb => {:enabled => false},
|
58
|
+
:cpu => {:topology => {:sockets => 1, :cores => 1}},
|
59
|
+
:high_availability => {:priority => 1, :enabled => false},
|
60
|
+
:os => {:type => "other", :boot_order => [{:dev => "hd"}]},
|
61
|
+
:custom_attributes => [],
|
62
|
+
:placement_policy => {:affinity => "migratable", :host => {}},
|
63
|
+
:memory_policy => {:guaranteed => 536_870_912},
|
64
|
+
:guest_info => {}
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
37
68
|
end
|
data/spec/service_spec.rb
CHANGED
@@ -229,6 +229,47 @@ EOX
|
|
229
229
|
|
230
230
|
end
|
231
231
|
|
232
|
+
context "#probe_api_path" do
|
233
|
+
let(:rest_client_resource_double) { double("RestClient::Resource") }
|
234
|
+
|
235
|
+
before do
|
236
|
+
allow(RestClient::Resource).to receive(:new).and_return(rest_client_resource_double)
|
237
|
+
end
|
238
|
+
|
239
|
+
def rest_exception(code = nil, headers = {})
|
240
|
+
response = double('response').as_null_object
|
241
|
+
expect(response).to receive(:code).and_return(code)
|
242
|
+
allow(response).to receive(:headers).and_return(headers)
|
243
|
+
RestClient::Exception.new(response)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns false for nil response" do
|
247
|
+
allow(rest_client_resource_double).to receive(:get).and_raise(RestClient::Exception.new)
|
248
|
+
expect(service.probe_api_path('http://some', 'path')).to eq(false)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "returns false for 401 and empty headers" do
|
252
|
+
allow(rest_client_resource_double).to receive(:get).and_raise(rest_exception(401))
|
253
|
+
expect(service.probe_api_path('http://some', 'path')).to eq(false)
|
254
|
+
end
|
255
|
+
|
256
|
+
it "returns false for other code" do
|
257
|
+
allow(rest_client_resource_double).to receive(:get).and_raise(rest_exception(404))
|
258
|
+
expect(service.probe_api_path('http://some', 'path')).to eq(false)
|
259
|
+
end
|
260
|
+
|
261
|
+
it "returns false if no exception thrown" do
|
262
|
+
allow(rest_client_resource_double).to receive(:get)
|
263
|
+
expect(service.probe_api_path('http://some', 'path')).to eq(false)
|
264
|
+
end
|
265
|
+
|
266
|
+
it "returns true for 401 and correct headers" do
|
267
|
+
allow(rest_client_resource_double).to receive(:get).and_raise(
|
268
|
+
rest_exception(401, :www_authenticate => "Basic realm=RESTAPI"))
|
269
|
+
expect(service.probe_api_path('http://some', 'path')).to eq(true)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
232
273
|
context "#version" do
|
233
274
|
it "with :full_version" do
|
234
275
|
allow(service).to receive(:product_info).and_return(:full_version => "3.4.5-0.3.el6ev", :version => {:major => "3", :minor => "4", :build => "0", :revision => "0"})
|
data/spec/template_spec.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
describe Ovirt::Template do
|
2
2
|
let(:service) { template.service }
|
3
3
|
let(:template) { build(:template_full) }
|
4
|
+
let(:blank_template) { build(:template_blank) }
|
4
5
|
|
5
6
|
context "#create_vm" do
|
6
7
|
it "clones properties for skeletal clones" do
|
7
8
|
options = {:clone_type => :skeletal}
|
8
|
-
|
9
|
+
expected_options = {
|
9
10
|
:clone_type => :linked,
|
10
11
|
:memory => 536_870_912,
|
11
12
|
:stateless => false,
|
@@ -14,14 +15,61 @@ describe Ovirt::Template do
|
|
14
15
|
:usb => {:enabled => false},
|
15
16
|
:cpu => {:topology => {:sockets => 1, :cores => 1}},
|
16
17
|
:high_availability => {:priority => 1, :enabled => false},
|
17
|
-
:
|
18
|
+
:os => {:type => 'rhel5_64', :boot_order => [{:dev => 'hd'}]}}
|
18
19
|
allow(template).to receive(:nics).and_return([])
|
19
20
|
allow(template).to receive(:disks).and_return([])
|
20
21
|
allow(service).to receive(:blank_template).and_return(double('blank template'))
|
21
|
-
expect(service.blank_template).to receive(:create_vm).once.with(
|
22
|
+
expect(service.blank_template).to receive(:create_vm).once.with(expected_options)
|
22
23
|
template.create_vm(options)
|
23
24
|
end
|
24
25
|
|
26
|
+
it "clones boot order from blank template" do
|
27
|
+
options = {
|
28
|
+
:clone_type => :linked,
|
29
|
+
:name => 'new name',
|
30
|
+
:memory => 536_870_912,
|
31
|
+
:cluster => 'fb27f9a0-cb75-4e0f-8c07-8dec0c5ab483',
|
32
|
+
:os => {:type => 'test', :boot_order => [{:dev => 'net'}, {:dev => 'iso'}]}}
|
33
|
+
allow(blank_template).to receive(:nics).and_return([])
|
34
|
+
allow(blank_template).to receive(:disks).and_return([])
|
35
|
+
expected_xml = <<-EOX.chomp
|
36
|
+
<vm>
|
37
|
+
<name>new name</name>
|
38
|
+
<cluster id=\"fb27f9a0-cb75-4e0f-8c07-8dec0c5ab483\"/>
|
39
|
+
<template id=\"00000000-0000-0000-0000-000000000000\"/>
|
40
|
+
<memory>536870912</memory>
|
41
|
+
<stateless>false</stateless>
|
42
|
+
<type>server</type>
|
43
|
+
<display>
|
44
|
+
<type>spice</type>
|
45
|
+
<monitors>1</monitors>
|
46
|
+
</display>
|
47
|
+
<usb>
|
48
|
+
<enabled>false</enabled>
|
49
|
+
</usb>
|
50
|
+
<cpu>
|
51
|
+
<topology sockets="1" cores="1"/>
|
52
|
+
</cpu>
|
53
|
+
<high_availability>
|
54
|
+
<priority>1</priority>
|
55
|
+
<enabled>false</enabled>
|
56
|
+
</high_availability>
|
57
|
+
<os type=\"test\">
|
58
|
+
<boot dev=\"net\"/>
|
59
|
+
<boot dev=\"iso\"/>
|
60
|
+
</os>
|
61
|
+
</vm>
|
62
|
+
EOX
|
63
|
+
response_xml = <<-EOX.chomp
|
64
|
+
<vm>
|
65
|
+
<os type='foo'/>
|
66
|
+
<placement_policy><affinity>foo</affinity></placement_policy>
|
67
|
+
</vm>
|
68
|
+
EOX
|
69
|
+
expect(blank_template.service).to receive(:resource_post).with(:vms, expected_xml).and_return(response_xml)
|
70
|
+
blank_template.create_vm(options)
|
71
|
+
end
|
72
|
+
|
25
73
|
it "overrides properties for linked clones" do
|
26
74
|
expected_data = <<-EOX.chomp
|
27
75
|
<vm>
|
@@ -105,6 +153,37 @@ EOX
|
|
105
153
|
expect(node["cores"].to_i).to eq(1)
|
106
154
|
expect(node["sockets"].to_i).to eq(1)
|
107
155
|
end
|
156
|
+
|
157
|
+
it "Properly sets vm/os/boot_order from template when passed :os_type" do
|
158
|
+
allow(Ovirt::Base).to receive(:object_to_id)
|
159
|
+
xml = template.send(:build_clone_xml, :os_type => 'test_os')
|
160
|
+
nodeset = Nokogiri::XML.parse(xml).xpath('//vm/os')
|
161
|
+
expect(nodeset.length).to eq(1)
|
162
|
+
|
163
|
+
os = nodeset.first
|
164
|
+
expect_os(os, :type => 'test_os', :boot_order => %w(hd))
|
165
|
+
end
|
166
|
+
|
167
|
+
it "Properly sets vm/os/boot_order from :os hash" do
|
168
|
+
allow(Ovirt::Base).to receive(:object_to_id)
|
169
|
+
xml = template.send(:build_clone_xml,
|
170
|
+
:os => {:type => "test_os", :boot_order => [{:dev => 'net'}, {:dev => 'iso'}]})
|
171
|
+
nodeset = Nokogiri::XML.parse(xml).xpath('//vm/os')
|
172
|
+
expect(nodeset.length).to eq(1)
|
173
|
+
|
174
|
+
os = nodeset.first
|
175
|
+
expect_os(os, :type => 'test_os', :boot_order => %w(net iso))
|
176
|
+
end
|
177
|
+
|
178
|
+
def expect_os(os, type: nil, boot_order: nil)
|
179
|
+
expect(os['type']).to eq(type)
|
180
|
+
boot_devices = []
|
181
|
+
os.xpath('boot').each do |boot|
|
182
|
+
dev = boot['dev']
|
183
|
+
boot_devices << dev unless dev.blank?
|
184
|
+
end
|
185
|
+
expect(boot_devices).to eq(boot_order)
|
186
|
+
end
|
108
187
|
end
|
109
188
|
end
|
110
189
|
end
|
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.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
@@ -17,11 +17,14 @@ authors:
|
|
17
17
|
- Dávid Halász
|
18
18
|
- pkliczewski
|
19
19
|
- Juan Hernandez
|
20
|
+
- Oleg Barenboim
|
20
21
|
- Martin Betak
|
22
|
+
- Tomas Jelinek
|
23
|
+
- Piotr Kliczewski
|
21
24
|
autorequire:
|
22
25
|
bindir: bin
|
23
26
|
cert_chain: []
|
24
|
-
date: 2016-08-
|
27
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
25
28
|
dependencies:
|
26
29
|
- !ruby/object:Gem::Dependency
|
27
30
|
name: activesupport
|
@@ -127,14 +130,14 @@ dependencies:
|
|
127
130
|
requirements:
|
128
131
|
- - ">="
|
129
132
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
133
|
+
version: 1.6.8
|
131
134
|
type: :runtime
|
132
135
|
prerelease: false
|
133
136
|
version_requirements: !ruby/object:Gem::Requirement
|
134
137
|
requirements:
|
135
138
|
- - ">="
|
136
139
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
140
|
+
version: 1.6.8
|
138
141
|
- !ruby/object:Gem::Dependency
|
139
142
|
name: parallel
|
140
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,7 +182,10 @@ email:
|
|
179
182
|
- dhalasz@redhat.com
|
180
183
|
- piotr.kliczewski@gmail.com
|
181
184
|
- juan.hernandez@redhat.com
|
185
|
+
- chessbyte@gmail.com
|
182
186
|
- mbetak@redhat.com
|
187
|
+
- tjelinek@redhat.com
|
188
|
+
- piotr.kliczewski@gmail.com
|
183
189
|
executables: []
|
184
190
|
extensions: []
|
185
191
|
extra_rdoc_files: []
|