rbovirt 0.0.38 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.rdoc +16 -0
- data/lib/client/disk_profile_api.rb +16 -0
- data/lib/client/vm_api.rb +4 -6
- data/lib/ovirt/disk_profile.rb +16 -0
- data/lib/ovirt/template.rb +5 -3
- data/lib/ovirt/template_version.rb +2 -2
- data/lib/ovirt/version.rb +1 -1
- data/lib/ovirt/vm.rb +45 -24
- data/lib/ovirt/volume.rb +9 -1
- data/lib/rbovirt.rb +27 -40
- data/rbovirt.gemspec +3 -1
- data/spec/integration/api_spec.rb +0 -22
- data/spec/integration/vm_crud_spec.rb +1 -5
- metadata +12 -18
- data/lib/client/instance_type_api.rb +0 -20
- data/lib/client/operating_system_api.rb +0 -10
- data/lib/ovirt/instance_type.rb +0 -73
- data/lib/ovirt/operating_system.rb +0 -11
- data/lib/restclient_ext/request.rb +0 -60
- data/spec/integration/instance_type_spec.rb +0 -16
- data/spec/unit/volume_spec.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37364775867c2c85d2ce024df84520d268709c11
|
4
|
+
data.tar.gz: cfc11b0e00842a67a37aaf00402313af04f13564
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd9cd881cc6a1da9e596830af2d73af02bd21ef48abd6f29fd0da7428e9297bfdb1d10fe33424f671198ce6a9badd5dbb9c885e504897f70b19050700f067224
|
7
|
+
data.tar.gz: 2d347cf659fe0f17ede50ed5f99efe143dff113f03f4e0d1484a08b3f65cee14b8da7bc643eabd60444d1a83592366ef138ece1c7245b5d9b54aa4796c1f0e74
|
data/CHANGES.rdoc
CHANGED
@@ -6,6 +6,22 @@ _rbovirt_ project.
|
|
6
6
|
Note that this list of changes was added with the 0.0.30 release,
|
7
7
|
previous releases aren't described here.
|
8
8
|
|
9
|
+
== 0.1.0 / 2015-05-07
|
10
|
+
|
11
|
+
New features:
|
12
|
+
|
13
|
+
* Updated the Ruby required version to 1.9.3.
|
14
|
+
* Updated the _rest_client_ required version to 1.7.0.
|
15
|
+
* Added +wipe_after_delete+ flag for volumes.
|
16
|
+
* Added +comment+ attribute to VMs.
|
17
|
+
* Added +clone+ attribute to VMs in order to support creation of full
|
18
|
+
clones.
|
19
|
+
* Added +ha_priority+ attribute to VMs.
|
20
|
+
* Added support for the top level +disks+ collection (also known as
|
21
|
+
floating disks).
|
22
|
+
* Added +alias+ attribute to volumes.
|
23
|
+
* Added support for affinity groups.
|
24
|
+
|
9
25
|
== 0.0.32 / 2015-01-14
|
10
26
|
|
11
27
|
New features:
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OVIRT
|
2
|
+
class Client
|
3
|
+
def diskprofile(dp_id)
|
4
|
+
dp = http_get("/diskprofiles/%s" % dp_id)
|
5
|
+
OVIRT::DiskProfile::new(self, dp.root)
|
6
|
+
end
|
7
|
+
|
8
|
+
def diskprofiles(opts={})
|
9
|
+
path = "/diskprofiles"
|
10
|
+
path += search_url(opts) unless filtered_api
|
11
|
+
http_get(path).xpath('/disk_profiles/disk_profile').collect do |dp|
|
12
|
+
OVIRT::DiskProfile::new(self,dp)
|
13
|
+
end.compact
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/client/vm_api.rb
CHANGED
@@ -6,11 +6,7 @@ module OVIRT
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def vms(opts={})
|
9
|
-
|
10
|
-
headers = {:accept => "application/xml"}
|
11
|
-
else
|
12
|
-
headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
|
13
|
-
end
|
9
|
+
headers = {:accept => "application/xml; detail=disks; detail=nics; detail=hosts"}
|
14
10
|
path = "/vms"
|
15
11
|
path += search_url(opts) unless filtered_api
|
16
12
|
http_get(path, headers).xpath('/vms/vm').collect do |vm|
|
@@ -23,7 +19,9 @@ module OVIRT
|
|
23
19
|
|
24
20
|
if opts[:user_data] and not opts[:user_data].empty?
|
25
21
|
if api_version?('3') and cluster_major_ver >= 3
|
26
|
-
if cluster_minor_ver >=
|
22
|
+
if cluster_minor_ver >= 3
|
23
|
+
opts[:user_data_method] = :payload_v3_3
|
24
|
+
elsif cluster_minor_ver >= 1
|
27
25
|
opts[:user_data_method] = :payload
|
28
26
|
elsif floppy_hook?
|
29
27
|
opts[:user_data_method] = :custom_property
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OVIRT
|
2
|
+
class DiskProfile < BaseObject
|
3
|
+
def initialize(client, xml)
|
4
|
+
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
5
|
+
parse_xml_attributes!(xml)
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def parse_xml_attributes!(xml)
|
11
|
+
@disk_profile = ((xml/'disk_profile').first[:id] rescue nil)
|
12
|
+
@name = ((xml/'name').first.text rescue nil)
|
13
|
+
@storage_domain = ((xml/'storagedomains').first[:id] rescue nil)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ovirt/template.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module OVIRT
|
2
2
|
class Template < BaseObject
|
3
|
-
attr_reader :description, :status, :cluster, :creation_time, :os, :storage, :display, :profile, :memory, :version
|
3
|
+
attr_reader :description, :comment, :status, :cluster, :creation_time, :os, :storage, :display, :profile, :memory, :version
|
4
4
|
|
5
5
|
def initialize(client, xml)
|
6
6
|
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
@@ -13,6 +13,7 @@ module OVIRT
|
|
13
13
|
template_ {
|
14
14
|
name_ opts[:name] || "t-#{Time.now.to_i}"
|
15
15
|
description opts[:description] || ''
|
16
|
+
comment opts[:comment] || ''
|
16
17
|
vm(:id => opts[:vm])
|
17
18
|
}
|
18
19
|
end
|
@@ -30,14 +31,15 @@ module OVIRT
|
|
30
31
|
private
|
31
32
|
def parse_xml_attributes!(xml)
|
32
33
|
@description = ((xml/'description').first.text rescue '')
|
34
|
+
@comment = ((xml/'comment').first.text rescue '')
|
33
35
|
@version = TemplateVersion.new((xml/'version').first)
|
34
36
|
@status = ((xml/'status').first.text rescue 'unknown')
|
35
37
|
@memory = (xml/'memory').first.text
|
36
38
|
@profile = (xml/'type').first.text
|
37
39
|
@cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
|
38
40
|
@display = {
|
39
|
-
:type => (
|
40
|
-
:monitors => (
|
41
|
+
:type => (xml/'display/type').first.text,
|
42
|
+
:monitors => (xml/'display/monitors').first.text
|
41
43
|
}
|
42
44
|
@cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
|
43
45
|
@storage = ((xml/'disks/disk/size').first.text rescue nil)
|
@@ -8,7 +8,7 @@ module OVIRT
|
|
8
8
|
def parse_xml_attributes(xml)
|
9
9
|
@base_template = (xml/"base_template").first[:id]
|
10
10
|
@version_number = (xml/"version_number").first.text
|
11
|
-
@version_name = (
|
11
|
+
@version_name = (xml/"version_name").first.text
|
12
12
|
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
data/lib/ovirt/version.rb
CHANGED
data/lib/ovirt/vm.rb
CHANGED
@@ -4,8 +4,8 @@ module OVIRT
|
|
4
4
|
FILEINJECT_PATH = "user-data.txt"
|
5
5
|
|
6
6
|
class VM < BaseObject
|
7
|
-
attr_reader :description, :status, :memory, :profile, :display, :host, :cluster, :template
|
8
|
-
attr_reader :storage, :cores, :creation_time, :os, :ips, :vnc, :quota
|
7
|
+
attr_reader :description, :comment, :status, :memory, :profile, :display, :host, :cluster, :template
|
8
|
+
attr_reader :storage, :cores, :creation_time, :os, :ha, :ha_priority, :ips, :vnc, :quota, :clone
|
9
9
|
attr_accessor :interfaces, :volumes
|
10
10
|
|
11
11
|
def initialize(client, xml)
|
@@ -50,6 +50,9 @@ module OVIRT
|
|
50
50
|
builder = Nokogiri::XML::Builder.new do
|
51
51
|
vm{
|
52
52
|
name_ opts[:name] || "i-#{Time.now.to_i}"
|
53
|
+
if opts[:comment]
|
54
|
+
comment_ opts[:comment]
|
55
|
+
end
|
53
56
|
if opts[:template] && !opts[:template].empty?
|
54
57
|
template_ :id => (opts[:template])
|
55
58
|
elsif opts[:template_name] && !opts[:template_name].empty?
|
@@ -76,24 +79,26 @@ module OVIRT
|
|
76
79
|
end
|
77
80
|
# os element must not be sent when template is present (RHBZ 1104235)
|
78
81
|
if opts[:template].nil? || opts[:template].empty?
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
os_opts[:boot] = os_opts[:boot].sort_by.with_index do |device, index|
|
87
|
-
device == opts[:first_boot_dev] ? -1 : index
|
82
|
+
os({:type => opts[:os_type] || 'unassigned' }){
|
83
|
+
if(opts[:first_boot_dev] && opts[:first_boot_dev] == 'network')
|
84
|
+
boot(:dev=> opts[:boot_dev1] || 'network')
|
85
|
+
boot(:dev=> opts[:boot_dev2] || 'hd')
|
86
|
+
else
|
87
|
+
boot(:dev=> opts[:boot_dev2] || 'hd')
|
88
|
+
boot(:dev=> opts[:boot_dev1] || 'network')
|
88
89
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
kernel (opts[:os_kernel])
|
91
|
+
initrd (opts[:os_initrd])
|
92
|
+
cmdline (opts[:os_cmdline])
|
93
|
+
}
|
94
|
+
end
|
95
|
+
if !opts[:ha].nil? || !opts[:ha_priority].nil?
|
96
|
+
high_availability_{
|
97
|
+
enabled_(opts[:ha]) unless opts[:ha].nil?
|
98
|
+
priority_(opts[:ha_priority]) unless opts[:ha_priority].nil?
|
99
|
+
}
|
96
100
|
end
|
101
|
+
disks_ { clone_(opts[:clone]) } if opts[:clone]
|
97
102
|
display_{
|
98
103
|
type_(opts[:display][:type])
|
99
104
|
} if opts[:display]
|
@@ -108,6 +113,16 @@ module OVIRT
|
|
108
113
|
file(:name => "#{opts[:fileinject_path] || OVIRT::FILEINJECT_PATH}") { content(Base64::decode64(opts[:user_data])) }
|
109
114
|
}
|
110
115
|
} if(opts[:user_data_method] && opts[:user_data_method] == :payload)
|
116
|
+
payloads {
|
117
|
+
payload(:type => 'floppy') {
|
118
|
+
files {
|
119
|
+
file {
|
120
|
+
name_ "#{opts[:fileinject_path] || OVIRT::FILEINJECT_PATH}"
|
121
|
+
content Base64::decode64(opts[:user_data])
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
} if(opts[:user_data_method] && opts[:user_data_method] == :payload_v3_3)
|
111
126
|
}
|
112
127
|
end
|
113
128
|
Nokogiri::XML(builder.to_xml).root.to_s
|
@@ -121,6 +136,7 @@ module OVIRT
|
|
121
136
|
gateway = opts[:gateway]
|
122
137
|
domain = opts[:domain]
|
123
138
|
nicname = opts[:nicname]
|
139
|
+
user = opts[:user] || 'root'
|
124
140
|
password = opts[:password]
|
125
141
|
ssh_authorized_keys = opts[:ssh_authorized_keys]
|
126
142
|
fileslist = opts[:files]
|
@@ -163,7 +179,7 @@ module OVIRT
|
|
163
179
|
unless password.nil?
|
164
180
|
users {
|
165
181
|
user {
|
166
|
-
user_name
|
182
|
+
user_name user
|
167
183
|
password password
|
168
184
|
}
|
169
185
|
}
|
@@ -171,13 +187,13 @@ module OVIRT
|
|
171
187
|
unless ssh_authorized_keys.nil?
|
172
188
|
authorized_keys {
|
173
189
|
authorized_key {
|
174
|
-
user { user_name
|
190
|
+
user { user_name user }
|
175
191
|
ssh_authorized_keys.each do |sshkey|
|
176
192
|
key sshkey
|
177
193
|
end
|
178
194
|
}
|
179
195
|
}
|
180
|
-
|
196
|
+
end
|
181
197
|
network_configuration {
|
182
198
|
unless nicname.nil?
|
183
199
|
nics {
|
@@ -206,7 +222,7 @@ module OVIRT
|
|
206
222
|
}
|
207
223
|
regenerate_ssh_keys 'true'
|
208
224
|
files {
|
209
|
-
|
225
|
+
unless extracmd.nil?
|
210
226
|
file {
|
211
227
|
name_ 'ignored'
|
212
228
|
content extracmd
|
@@ -235,6 +251,7 @@ module OVIRT
|
|
235
251
|
|
236
252
|
def parse_xml_attributes!(xml)
|
237
253
|
@description = ((xml/'description').first.text rescue '')
|
254
|
+
@comment = ((xml/'comment').first.text rescue '')
|
238
255
|
@status = ((xml/'status').first.text rescue 'unknown')
|
239
256
|
@memory = (xml/'memory').first.text
|
240
257
|
@profile = (xml/'type').first.text
|
@@ -242,12 +259,12 @@ module OVIRT
|
|
242
259
|
@host = Link::new(@client, (xml/'host').first[:id], (xml/'host').first[:href]) rescue nil
|
243
260
|
@cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
|
244
261
|
@display = {
|
245
|
-
:type => (
|
262
|
+
:type => (xml/'display/type').first.text,
|
246
263
|
:address => ((xml/'display/address').first.text rescue nil),
|
247
264
|
:port => ((xml/'display/port').first.text rescue nil),
|
248
265
|
:secure_port => ((xml/'display/secure_port').first.text rescue nil),
|
249
266
|
:subject => ((xml/'display/certificate/subject').first.text rescue nil),
|
250
|
-
:monitors => (
|
267
|
+
:monitors => (xml/'display/monitors').first.text
|
251
268
|
}
|
252
269
|
@cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
|
253
270
|
@storage = ((xml/'disks/disk/size').first.text rescue nil)
|
@@ -261,6 +278,8 @@ module OVIRT
|
|
261
278
|
:type => (xml/'os').first[:type],
|
262
279
|
:boot => (xml/'os/boot').collect {|boot| boot[:dev] }
|
263
280
|
}
|
281
|
+
@ha = ((xml/'high_availability/enabled').first.text rescue nil)
|
282
|
+
@ha_priority = ((xml/'high_availability/priority').first.text rescue nil)
|
264
283
|
@quota = ((xml/'quota').first[:id] rescue nil)
|
265
284
|
|
266
285
|
disks = xml/'disks/disk'
|
@@ -268,6 +287,8 @@ module OVIRT
|
|
268
287
|
|
269
288
|
interfaces = xml/'nics/nic'
|
270
289
|
@interfaces = interfaces.length > 0 ? interfaces.collect {|nic| OVIRT::Interface::new(@client, nic)} : nil
|
290
|
+
|
291
|
+
@clone = ((xml/'disks/clone').first.text rescue nil)
|
271
292
|
end
|
272
293
|
|
273
294
|
end
|
data/lib/ovirt/volume.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module OVIRT
|
2
2
|
|
3
3
|
class Volume < BaseObject
|
4
|
-
attr_reader :size, :disk_type, :bootable, :interface, :format, :sparse, :status, :storage_domain, :vm, :quota, :alias
|
4
|
+
attr_reader :size, :disk_type, :bootable, :interface, :format, :sparse, :status, :storage_domain, :vm, :quota, :alias, :disk_profile
|
5
5
|
|
6
6
|
def initialize(client, xml)
|
7
7
|
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
@@ -26,6 +26,9 @@ module OVIRT
|
|
26
26
|
if opts[:bootable]
|
27
27
|
bootable_(opts[:bootable])
|
28
28
|
end
|
29
|
+
if opts[:disk_profile]
|
30
|
+
disk_profile_(:id => opts[:disk_profile])
|
31
|
+
end
|
29
32
|
if opts[:interface]
|
30
33
|
interface_(opts[:interface])
|
31
34
|
end
|
@@ -41,6 +44,9 @@ module OVIRT
|
|
41
44
|
if opts[:alias]
|
42
45
|
alias_(opts[:alias])
|
43
46
|
end
|
47
|
+
if opts[:wipe_after_delete]
|
48
|
+
wipe_after_delete(opts[:wipe_after_delete])
|
49
|
+
end
|
44
50
|
}
|
45
51
|
end
|
46
52
|
Nokogiri::XML(builder.to_xml).root.to_s
|
@@ -55,9 +61,11 @@ module OVIRT
|
|
55
61
|
@format = ((xml/'format').first.text rescue nil)
|
56
62
|
@sparse = ((xml/'sparse').first.text rescue nil)
|
57
63
|
@status = ((xml/'status/state').first.text rescue nil)
|
64
|
+
@disk_profile = Link::new(@client, (xml/'disk_profile').first[:id], (xml/'disk_profile').first[:href]) rescue nil
|
58
65
|
@vm = Link::new(@client, (xml/'vm').first[:id], (xml/'vm').first[:href]) rescue nil
|
59
66
|
@quota = ((xml/'quota').first[:id] rescue nil)
|
60
67
|
@alias = ((xml/'alias').first.text rescue nil)
|
68
|
+
@wipe_after_delete = ((xml/'wipe_after_delete').first.text rescue nil)
|
61
69
|
end
|
62
70
|
|
63
71
|
end
|
data/lib/rbovirt.rb
CHANGED
@@ -3,6 +3,7 @@ require "ovirt/cluster"
|
|
3
3
|
require "ovirt/datacenter"
|
4
4
|
require "ovirt/host"
|
5
5
|
require "ovirt/storage_domain"
|
6
|
+
require "ovirt/disk_profile"
|
6
7
|
require "ovirt/template"
|
7
8
|
require "ovirt/template_version"
|
8
9
|
require "ovirt/vm"
|
@@ -11,9 +12,7 @@ require "ovirt/interface"
|
|
11
12
|
require "ovirt/network"
|
12
13
|
require "ovirt/quota"
|
13
14
|
require "ovirt/affinity_group"
|
14
|
-
require "ovirt/instance_type"
|
15
15
|
require "ovirt/version"
|
16
|
-
require "ovirt/operating_system"
|
17
16
|
|
18
17
|
require "client/vm_api"
|
19
18
|
require "client/template_api"
|
@@ -24,12 +23,10 @@ require "client/storage_domain_api"
|
|
24
23
|
require "client/quota_api"
|
25
24
|
require "client/disk_api"
|
26
25
|
require "client/affinity_group_api"
|
27
|
-
require "client/
|
28
|
-
require "client/operating_system_api"
|
26
|
+
require "client/disk_profile_api"
|
29
27
|
|
30
28
|
require "nokogiri"
|
31
29
|
require "rest_client"
|
32
|
-
require "restclient_ext/request"
|
33
30
|
require "restclient_ext/resource"
|
34
31
|
|
35
32
|
module OVIRT
|
@@ -48,7 +45,7 @@ module OVIRT
|
|
48
45
|
|
49
46
|
class Client
|
50
47
|
|
51
|
-
attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify
|
48
|
+
attr_reader :credentials, :api_entrypoint, :datacenter_id, :cluster_id, :filtered_api, :ca_cert_file, :ca_cert_store, :ca_no_verify
|
52
49
|
|
53
50
|
# Construct a new ovirt client class.
|
54
51
|
# mandatory parameters
|
@@ -70,16 +67,14 @@ module OVIRT
|
|
70
67
|
:cluster_id => backward_compatibility_cluster,
|
71
68
|
:filtered_api => backward_compatibility_filtered}
|
72
69
|
end
|
73
|
-
@api_entrypoint
|
74
|
-
@credentials
|
75
|
-
@datacenter_id
|
76
|
-
@cluster_id
|
77
|
-
@filtered_api
|
78
|
-
@ca_cert_file
|
79
|
-
@ca_cert_store
|
80
|
-
@ca_no_verify
|
81
|
-
@persistent_auth = options[:persistent_auth]
|
82
|
-
@jsessionid = options[:jsessionid]
|
70
|
+
@api_entrypoint = api_entrypoint
|
71
|
+
@credentials = { :username => username, :password => password }
|
72
|
+
@datacenter_id = options[:datacenter_id]
|
73
|
+
@cluster_id = options[:cluster_id]
|
74
|
+
@filtered_api = options[:filtered_api]
|
75
|
+
@ca_cert_file = options[:ca_cert_file]
|
76
|
+
@ca_cert_store = options[:ca_cert_store]
|
77
|
+
@ca_no_verify = options[:ca_no_verify]
|
83
78
|
end
|
84
79
|
|
85
80
|
def api_version
|
@@ -98,13 +93,9 @@ module OVIRT
|
|
98
93
|
end
|
99
94
|
|
100
95
|
private
|
101
|
-
|
102
96
|
def search_url opts
|
103
|
-
search = opts[:search] ||
|
104
|
-
search
|
105
|
-
search += " page #{opts[:page]}" if opts[:page]
|
106
|
-
max = opts[:max] ? ";max=#{opts[:max]}" : ''
|
107
|
-
"#{max}?search=#{CGI.escape(search)}"
|
97
|
+
search = opts[:search] || ("datacenter=%s" % current_datacenter.name)
|
98
|
+
"?search=%s" % CGI.escape(search)
|
108
99
|
end
|
109
100
|
|
110
101
|
def current_datacenter
|
@@ -117,7 +108,9 @@ module OVIRT
|
|
117
108
|
|
118
109
|
def http_get(suburl, headers={})
|
119
110
|
begin
|
120
|
-
|
111
|
+
res = rest_client(suburl).get(http_headers(headers))
|
112
|
+
puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
|
113
|
+
Nokogiri::XML(res)
|
121
114
|
rescue
|
122
115
|
handle_fault $!
|
123
116
|
end
|
@@ -125,7 +118,9 @@ module OVIRT
|
|
125
118
|
|
126
119
|
def http_post(suburl, body, headers={})
|
127
120
|
begin
|
128
|
-
|
121
|
+
res = rest_client(suburl).post(body, http_headers(headers))
|
122
|
+
puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
|
123
|
+
Nokogiri::XML(res)
|
129
124
|
rescue
|
130
125
|
handle_fault $!
|
131
126
|
end
|
@@ -133,7 +128,9 @@ module OVIRT
|
|
133
128
|
|
134
129
|
def http_put(suburl, body, headers={})
|
135
130
|
begin
|
136
|
-
|
131
|
+
res = rest_client(suburl).put(body, http_headers(headers))
|
132
|
+
puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
|
133
|
+
Nokogiri::XML(res)
|
137
134
|
rescue
|
138
135
|
handle_fault $!
|
139
136
|
end
|
@@ -142,8 +139,10 @@ module OVIRT
|
|
142
139
|
def http_delete(suburl, body=nil, headers={})
|
143
140
|
begin
|
144
141
|
headers = body ? http_headers(headers) :
|
145
|
-
{:accept => 'application/xml'
|
146
|
-
|
142
|
+
{:accept => 'application/xml'}.merge(auth_header).merge(filter_header)
|
143
|
+
res = rest_client(suburl).delete_with_payload(body, headers)
|
144
|
+
puts "#{res}\n" if ENV['RBOVIRT_LOG_RESPONSE']
|
145
|
+
Nokogiri::XML(res)
|
147
146
|
rescue
|
148
147
|
handle_fault $!
|
149
148
|
end
|
@@ -152,12 +151,7 @@ module OVIRT
|
|
152
151
|
def auth_header
|
153
152
|
# This is the method for strict_encode64:
|
154
153
|
encoded_credentials = ["#{@credentials[:username]}:#{@credentials[:password]}"].pack("m0").gsub(/\n/,'')
|
155
|
-
|
156
|
-
if persistent_auth
|
157
|
-
headers[:prefer] = 'persistent-auth'
|
158
|
-
headers[:cookie] = "JSESSIONID=#{jsessionid}" if jsessionid
|
159
|
-
end
|
160
|
-
headers
|
154
|
+
{ :authorization => "Basic " + encoded_credentials }
|
161
155
|
end
|
162
156
|
|
163
157
|
def rest_client(suburl)
|
@@ -192,16 +186,9 @@ module OVIRT
|
|
192
186
|
filter_header.merge(auth_header).merge({
|
193
187
|
:content_type => 'application/xml',
|
194
188
|
:accept => 'application/xml',
|
195
|
-
:version => '3',
|
196
189
|
}).merge(headers)
|
197
190
|
end
|
198
191
|
|
199
|
-
def handle_success(response)
|
200
|
-
puts "#{response}\n" if ENV['RBOVIRT_LOG_RESPONSE']
|
201
|
-
@jsessionid ||= response.cookies['JSESSIONID']
|
202
|
-
Nokogiri::XML(response)
|
203
|
-
end
|
204
|
-
|
205
192
|
def handle_fault(f)
|
206
193
|
if f.is_a?(RestClient::BadRequest) || f.is_a?(RestClient::Conflict)
|
207
194
|
fault = (Nokogiri::XML(f.http_body)/'//fault/detail')
|
data/rbovirt.gemspec
CHANGED
@@ -21,11 +21,13 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.require_paths = ["lib"]
|
22
22
|
|
23
23
|
gem.add_runtime_dependency('nokogiri')
|
24
|
-
gem.add_runtime_dependency('rest-client')
|
24
|
+
gem.add_runtime_dependency('rest-client', '> 1.7.0')
|
25
25
|
gem.add_development_dependency('shoulda')
|
26
26
|
gem.add_development_dependency('rspec-rails', '~> 2.6')
|
27
27
|
gem.add_development_dependency('rake')
|
28
28
|
|
29
|
+
gem.required_ruby_version = '>= 1.9.3'
|
30
|
+
|
29
31
|
gem.rdoc_options << '--title' << gem.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
|
30
32
|
gem.extra_rdoc_files = ['README.rdoc', 'CHANGES.rdoc']
|
31
33
|
end
|
@@ -58,28 +58,6 @@ describe OVIRT, "Https authentication" do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe OVIRT, "Persistent authentication" do
|
62
|
-
context 'use persistent authentication' do
|
63
|
-
|
64
|
-
it "test_request_with_persistent_authentication" do
|
65
|
-
user, password, url, datacenter = endpoint
|
66
|
-
cert = ca_cert(url)
|
67
|
-
store = OpenSSL::X509::Store.new().add_cert(
|
68
|
-
OpenSSL::X509::Certificate.new(cert))
|
69
|
-
|
70
|
-
client = ::OVIRT::Client.new(user, password, url, {:ca_cert_store => store, :persistent_auth => true})
|
71
|
-
client.api_version.class.should eql(String)
|
72
|
-
client.persistent_auth.should eql(true)
|
73
|
-
client.jsessionid.should_not be_nil
|
74
|
-
|
75
|
-
# When performing a new request the jsessionid should remain the same
|
76
|
-
orig_jsession_id = client.jsessionid
|
77
|
-
client.datacenters.class.should eql(Array)
|
78
|
-
client.jsessionid.should eql(orig_jsession_id)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
61
|
describe OVIRT, "Admin API" do
|
84
62
|
|
85
63
|
before(:all) do
|
@@ -19,7 +19,7 @@ shared_examples_for "Basic VM Life cycle" do
|
|
19
19
|
|
20
20
|
it "test_should_create_template" do
|
21
21
|
template_name = "tmplt-"+Time.now.to_i.to_s
|
22
|
-
template = @client.create_template(:vm => @vm.id, :name => template_name, :description => "test_template")
|
22
|
+
template = @client.create_template(:vm => @vm.id, :name => template_name, :description => "test_template", :comment => "test_template")
|
23
23
|
template.class.to_s.should eql("OVIRT::Template")
|
24
24
|
while !@client.vm(@vm.id).ready? do
|
25
25
|
end
|
@@ -42,8 +42,6 @@ shared_examples_for "Basic VM Life cycle" do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "test_should_start_with_cloudinit" do
|
45
|
-
while @client.vm(@vm.id).status.strip != 'down' do
|
46
|
-
end
|
47
45
|
hostname = "host-"+Time.now.to_i.to_s
|
48
46
|
user_data={ :hostname => hostname }
|
49
47
|
@client.vm_start_with_cloudinit(@vm.id, user_data)
|
@@ -53,8 +51,6 @@ shared_examples_for "Basic VM Life cycle" do
|
|
53
51
|
end
|
54
52
|
|
55
53
|
it "test_should_set_vm_ticket" do
|
56
|
-
while @client.vm(@vm.id).status.strip != 'down' do
|
57
|
-
end
|
58
54
|
@client.vm_action(@vm.id, :start)
|
59
55
|
while !@client.vm(@vm.id).running? do
|
60
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbovirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.7.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.7.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: shoulda
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,8 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: |2
|
84
|
+
A Ruby client for oVirt REST API
|
84
85
|
email:
|
85
86
|
- abenari@redhat.com
|
86
87
|
executables: []
|
@@ -100,9 +101,8 @@ files:
|
|
100
101
|
- lib/client/cluster_api.rb
|
101
102
|
- lib/client/datacenter_api.rb
|
102
103
|
- lib/client/disk_api.rb
|
104
|
+
- lib/client/disk_profile_api.rb
|
103
105
|
- lib/client/host_api.rb
|
104
|
-
- lib/client/instance_type_api.rb
|
105
|
-
- lib/client/operating_system_api.rb
|
106
106
|
- lib/client/quota_api.rb
|
107
107
|
- lib/client/storage_domain_api.rb
|
108
108
|
- lib/client/template_api.rb
|
@@ -111,11 +111,10 @@ files:
|
|
111
111
|
- lib/ovirt/base_object.rb
|
112
112
|
- lib/ovirt/cluster.rb
|
113
113
|
- lib/ovirt/datacenter.rb
|
114
|
+
- lib/ovirt/disk_profile.rb
|
114
115
|
- lib/ovirt/host.rb
|
115
|
-
- lib/ovirt/instance_type.rb
|
116
116
|
- lib/ovirt/interface.rb
|
117
117
|
- lib/ovirt/network.rb
|
118
|
-
- lib/ovirt/operating_system.rb
|
119
118
|
- lib/ovirt/quota.rb
|
120
119
|
- lib/ovirt/storage_domain.rb
|
121
120
|
- lib/ovirt/template.rb
|
@@ -124,17 +123,14 @@ files:
|
|
124
123
|
- lib/ovirt/vm.rb
|
125
124
|
- lib/ovirt/volume.rb
|
126
125
|
- lib/rbovirt.rb
|
127
|
-
- lib/restclient_ext/request.rb
|
128
126
|
- lib/restclient_ext/resource.rb
|
129
127
|
- rbovirt.gemspec
|
130
128
|
- spec/endpoint.yml.example
|
131
129
|
- spec/integration/api_spec.rb
|
132
|
-
- spec/integration/instance_type_spec.rb
|
133
130
|
- spec/integration/vm_crud_spec.rb
|
134
131
|
- spec/spec_helper.rb
|
135
132
|
- spec/unit/client_spec.rb
|
136
133
|
- spec/unit/vm_spec.rb
|
137
|
-
- spec/unit/volume_spec.rb
|
138
134
|
homepage: http://github.com/abenari/rbovirt
|
139
135
|
licenses:
|
140
136
|
- MIT
|
@@ -153,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
149
|
requirements:
|
154
150
|
- - ">="
|
155
151
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
152
|
+
version: 1.9.3
|
157
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
154
|
requirements:
|
159
155
|
- - ">="
|
@@ -161,16 +157,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
157
|
version: '0'
|
162
158
|
requirements: []
|
163
159
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.2.2
|
165
161
|
signing_key:
|
166
162
|
specification_version: 4
|
167
163
|
summary: A Ruby client for oVirt REST API
|
168
164
|
test_files:
|
169
165
|
- spec/endpoint.yml.example
|
170
166
|
- spec/integration/api_spec.rb
|
171
|
-
- spec/integration/instance_type_spec.rb
|
172
167
|
- spec/integration/vm_crud_spec.rb
|
173
168
|
- spec/spec_helper.rb
|
174
169
|
- spec/unit/client_spec.rb
|
175
170
|
- spec/unit/vm_spec.rb
|
176
|
-
- spec/unit/volume_spec.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module OVIRT
|
2
|
-
class Client
|
3
|
-
def instance_type(instance_type_id)
|
4
|
-
begin
|
5
|
-
instance_type = http_get("/instancetypes/%s" % instance_type_id)
|
6
|
-
OVIRT::InstanceType::new(self, instance_type.root)
|
7
|
-
rescue
|
8
|
-
handle_fault $!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def instance_types(opts={})
|
13
|
-
search = opts[:search] ||""
|
14
|
-
instance_types = http_get("/instancetypes?search=%s" % CGI.escape(search))
|
15
|
-
instance_types.xpath('/instance_types/instance_type').collect do |it|
|
16
|
-
OVIRT::InstanceType::new(self, it)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/ovirt/instance_type.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
module OVIRT
|
2
|
-
# Instance types are added to oVirt 3.5 and have been updated in oVirt 3.6
|
3
|
-
class InstanceType < BaseObject
|
4
|
-
# Common attributes to all oVirt version supported at this time
|
5
|
-
attr_reader :name, :description, :memory, :cores, :os, :creation_time
|
6
|
-
attr_reader :ha, :ha_priority, :display, :usb, :migration_downtime
|
7
|
-
|
8
|
-
# oVirt 3.5 attributes
|
9
|
-
attr_reader :type, :status, :cpu_shares, :boot_menu, :origin, :stateless
|
10
|
-
attr_reader :delete_protected, :sso, :timezone
|
11
|
-
|
12
|
-
# oVirt 3.6 attributes
|
13
|
-
attr_reader :migration, :io_threads, :memory_guaranteed
|
14
|
-
|
15
|
-
def initialize(client, xml)
|
16
|
-
super(client, xml[:id], xml[:href], (xml/'name').first.text)
|
17
|
-
parse_xml_attributes!(xml)
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def parse_xml_attributes!(xml)
|
23
|
-
# Common attributes
|
24
|
-
@description = ((xml/'description').first.text rescue '')
|
25
|
-
@memory = (xml/'memory').first.text
|
26
|
-
@cores = ((xml/'cpu/topology').first[:cores].to_i * (xml/'cpu/topology').first[:sockets].to_i rescue nil)
|
27
|
-
@os = {
|
28
|
-
:type => (xml/'os').first[:type],
|
29
|
-
:boot => (xml/'os/boot').collect {|boot| boot[:dev] }
|
30
|
-
}
|
31
|
-
@creation_time = (xml/'creation_time').text
|
32
|
-
@ha = parse_bool((xml/'high_availability/enabled').first.text)
|
33
|
-
@ha_priority = ((xml/'high_availability/priority').first.text rescue nil)
|
34
|
-
@display = {
|
35
|
-
:type => (xml/'display/type').first.text,
|
36
|
-
:monitors => (xml/'display/monitors').first.text,
|
37
|
-
:single_qxl_pci => parse_bool((xml/'display/single_qxl_pci').first.text),
|
38
|
-
:smartcard_enabled => parse_bool((xml/'display/smartcard_enabled').first.text),
|
39
|
-
|
40
|
-
}
|
41
|
-
@usb = parse_bool((xml/'usb/enabled').first.text)
|
42
|
-
@migration_downtime = ((xml/'migration_downtime').first.text)
|
43
|
-
|
44
|
-
# oVirt 3.5 attributes
|
45
|
-
@type = ((xml/'type').first.text rescue nil)
|
46
|
-
@status = ((xml/'status').first.text rescue nil)
|
47
|
-
@cpu_shares = (((xml/'cpu_shares').first.text) rescue nil)
|
48
|
-
potential_bool = ((xml/'bios/boot_menu/enabled').first.text rescue nil)
|
49
|
-
@boot_menu = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
50
|
-
@origin = ((xml/'origin').text rescue nil)
|
51
|
-
potential_bool = ((xml/'stateless').first.text rescue nil)
|
52
|
-
@stateless = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
53
|
-
potential_bool = ((xml/'delete_protected').first.text rescue nil)
|
54
|
-
@delete_protected = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
55
|
-
#@sso = ((xml/'sso/methods').first.text rescue nil)
|
56
|
-
@timezone = ((xml/'timezone').first.text rescue nil)
|
57
|
-
potential_bool = ((xml/'display/allow_override').first.text rescue nil)
|
58
|
-
@display[:allow_override] = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
59
|
-
potential_bool = ((xml/'display/file_transfer_enabled').first.text rescue nil)
|
60
|
-
@display[:file_transfer_enabled] = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
61
|
-
potential_bool = ((xml/'display/copy_paste_enabled').first.text rescue nil)
|
62
|
-
@display[:copy_paste_enabled] = potential_bool.nil? ? nil : parse_bool(potential_bool)
|
63
|
-
|
64
|
-
# oVirt 3.6 attributes
|
65
|
-
@migration = {
|
66
|
-
:auto_converge => ((xml/'migration/auto_converge').first.text rescue nil),
|
67
|
-
:compressed => ((xml/'migration/compressed').first.text rescue nil)
|
68
|
-
}
|
69
|
-
@io_threads = ((xml/'io/threads').first.text rescue nil)
|
70
|
-
@memory_guaranteed = ((xml/'memory_policy/guaranteed').first.text rescue nil)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# rest-client extension
|
2
|
-
module RestClient
|
3
|
-
# This class enhance the rest-client request by accepting a parameter for ca certificate store,
|
4
|
-
# this file can be removed once https://github.com/rest-client/rest-client/pull/254
|
5
|
-
# get merged upstream.
|
6
|
-
#
|
7
|
-
# :ssl_cert_store - an x509 certificate store.
|
8
|
-
class Request
|
9
|
-
|
10
|
-
def transmit uri, req, payload, & block
|
11
|
-
setup_credentials req
|
12
|
-
|
13
|
-
net = net_http_class.new(uri.host, uri.port)
|
14
|
-
net.use_ssl = uri.is_a?(URI::HTTPS)
|
15
|
-
if (@verify_ssl == false) || (@verify_ssl == OpenSSL::SSL::VERIFY_NONE)
|
16
|
-
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
17
|
-
elsif @verify_ssl.is_a? Integer
|
18
|
-
net.verify_mode = @verify_ssl
|
19
|
-
net.verify_callback = lambda do |preverify_ok, ssl_context|
|
20
|
-
if (!preverify_ok) || ssl_context.error != 0
|
21
|
-
err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})"
|
22
|
-
raise SSLCertificateNotVerified.new(err_msg)
|
23
|
-
end
|
24
|
-
true
|
25
|
-
end
|
26
|
-
end
|
27
|
-
net.cert = @ssl_client_cert if @ssl_client_cert
|
28
|
-
net.key = @ssl_client_key if @ssl_client_key
|
29
|
-
net.ca_file = @ssl_ca_file if @ssl_ca_file
|
30
|
-
net.cert_store = args[:ssl_cert_store] if args[:ssl_cert_store]
|
31
|
-
net.read_timeout = @timeout if @timeout
|
32
|
-
net.open_timeout = @open_timeout if @open_timeout
|
33
|
-
|
34
|
-
# disable the timeout if the timeout value is -1
|
35
|
-
net.read_timeout = nil if @timeout == -1
|
36
|
-
net.out_timeout = nil if @open_timeout == -1
|
37
|
-
|
38
|
-
RestClient.before_execution_procs.each do |before_proc|
|
39
|
-
before_proc.call(req, args)
|
40
|
-
end
|
41
|
-
|
42
|
-
log_request
|
43
|
-
|
44
|
-
net.start do |http|
|
45
|
-
if @block_response
|
46
|
-
http.request(req, payload ? payload.to_s : nil, & @block_response)
|
47
|
-
else
|
48
|
-
res = http.request(req, payload ? payload.to_s : nil) { |http_response| fetch_body(http_response) }
|
49
|
-
log_response res
|
50
|
-
process_result res, & block
|
51
|
-
end
|
52
|
-
end
|
53
|
-
rescue EOFError
|
54
|
-
raise RestClient::ServerBrokeConnection
|
55
|
-
rescue Timeout::Error
|
56
|
-
raise RestClient::RequestTimeout
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
-
|
3
|
-
describe "Basic Instance type life cycle" do
|
4
|
-
before(:all) do
|
5
|
-
setup_client
|
6
|
-
end
|
7
|
-
|
8
|
-
it "test_should_return_instance_types" do
|
9
|
-
@client.instance_types
|
10
|
-
end
|
11
|
-
|
12
|
-
it "test_should_return_an_instance_type" do
|
13
|
-
@instance_type = @client.instance_types.first
|
14
|
-
@client.instance_type(@instance_type.id).id.should eql(@instance_type.id)
|
15
|
-
end
|
16
|
-
end
|
data/spec/unit/volume_spec.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/../spec_helper"
|
2
|
-
|
3
|
-
describe OVIRT::Volume do
|
4
|
-
|
5
|
-
xml = <<END_HEREDOC
|
6
|
-
<disk href="/api/vms/76d29095-bc27-4cd0-8178-07e942aea549/nics/12345678-1234-1234-1234-123456789012" id="12345678-1234-1234-1234-123456789012">
|
7
|
-
<name>disk1</name>
|
8
|
-
<size>53687091200</size>
|
9
|
-
<provisioned_size>53687091200</provisioned_size>
|
10
|
-
<actual_size>143360</actual_size>
|
11
|
-
<shareable>false</shareable>
|
12
|
-
<propagate_errors>false</propagate_errors>
|
13
|
-
<active>true</active>
|
14
|
-
</disk>
|
15
|
-
END_HEREDOC
|
16
|
-
vol = OVIRT::Volume::new(nil, Nokogiri::XML(xml).xpath('/').first)
|
17
|
-
|
18
|
-
it "volume's bootable should be nil, since it was not specified" do
|
19
|
-
vol.bootable.should eql(nil)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "volume's interface should be nil, since it was not specified" do
|
23
|
-
vol.interface.should eql(nil)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|