ovirt 0.13.0 → 0.14.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: c82f2d658955528e5e35c3c3eceafa20d0757168
4
- data.tar.gz: 73b2a0d08d55af23d29d8cda5efc7d2a942b78ef
3
+ metadata.gz: 3724f18a89bdd277ad1a7cb8da15f55ef3ae65c3
4
+ data.tar.gz: a99bfba080edfd9a0413ae5f03a3318df1b27475
5
5
  SHA512:
6
- metadata.gz: 64f341695af226e85a2ed87d237e5481ace077c554f2180219665b523d27ed2148d21dfda1182189bb476c3f353f3f71a48a6063a361290af3852ed5e97db025
7
- data.tar.gz: 7e181ac7fbdd65a6a0a123d4dabb41d55733df29b6d0850a8b3577a3e0eb04ee24e5f134e88f2d28b3b7ac8c6284698390b221f9e516e838b72fe253edb6b813
6
+ metadata.gz: 4fd4402bbbe81b263372b324ddbf01ce20a9966b9c14f1732a24a3c4fca74995bdb5bf1263e4bdcca9fdb44f6ed9055357aa8bb6cb762ef4ae9977475b3bec98
7
+ data.tar.gz: b7441b0506e7b99680bcdbf6f1fa72b3d78c91be9a1b7731b361fc8039bd5684f913f15ddf656d94c687176286abaf5a6026f16a642a3e9c6554b445f1efd569
data/lib/ovirt/base.rb CHANGED
@@ -307,20 +307,21 @@ module Ovirt
307
307
  self[:href] || "#{self.class.api_endpoint}/#{self[:id]}"
308
308
  end
309
309
 
310
- def update!(&block)
311
- response = update(&block)
310
+ def update!(matrix = {}, &block)
311
+ response = update(matrix, &block)
312
312
 
313
313
  obj = self.class.create_from_xml(@service, response)
314
314
  replace(obj)
315
315
  end
316
316
 
317
- def update
317
+ def update(matrix = {})
318
318
  builder = Nokogiri::XML::Builder.new do |xml|
319
319
  xml.send(self.class.namespace.last.downcase) { yield xml if block_given? }
320
320
  end
321
321
  data = builder.doc.root.to_xml
322
+ suffix = build_matrix_suffix(matrix)
322
323
 
323
- @service.resource_put(api_endpoint, data)
324
+ @service.resource_put(api_endpoint + suffix, data)
324
325
  end
325
326
 
326
327
  def keys
@@ -330,5 +331,19 @@ module Ovirt
330
331
  def [](key)
331
332
  @attributes[key]
332
333
  end
334
+
335
+ private
336
+
337
+ #
338
+ # Builds the string to be added to the request path for the given matrix parameters. For example, if the given
339
+ # parameters contain the `next_run` key with the value `true` and the `max` key with the value `10`, then the
340
+ # resulting string will be `;next_run=true;max=10`.
341
+ #
342
+ # @param parameters [Hash] A hash containing the names and values of the matrix parameters.
343
+ # @return [String] The string to add to the request path.
344
+ #
345
+ def build_matrix_suffix(parameters)
346
+ parameters.map { |key, value| value.nil? ? '' : ";#{key}=#{value}" }.join
347
+ end
333
348
  end
334
349
  end
data/lib/ovirt/event.rb CHANGED
@@ -306,7 +306,7 @@ module Ovirt
306
306
  529 => "USER_EJECT_VM_FLOPPY",
307
307
  530 => "HOST_MANUAL_FENCE_FAILED_CALL_FENCE_SPM",
308
308
  531 => "HOST_LOW_MEM",
309
- 533 => "HOST_FAILED_CONNECTION_TO_DATA_CENTER",
309
+ 533 => "VDS_HIGH_NETWORK_USE",
310
310
  555 => "USER_MOVE_TAG",
311
311
  556 => "USER_MOVE_TAG_FAILED",
312
312
  600 => "USER_HOST_MAINTENANCE",
data/lib/ovirt/service.rb CHANGED
@@ -21,6 +21,16 @@ module Ovirt
21
21
  '/ovirt-engine/api',
22
22
  ].freeze
23
23
 
24
+ # The list of absolute URI paths where the engine SSH public key can be available (this is used only to detect if
25
+ # the engine is installed or not):
26
+ CANDIDATE_SSH_PUBLIC_KEY_PATHS = [
27
+ # This will work for newer versions of the engine, including 3.5, 3.6 and 4.0:
28
+ '/ovirt-engine/services/pki-resource?resource=engine-certificate&format=OPENSSH-PUBKEY',
29
+
30
+ # This will work for older versions of the engine older thatn 3.5:
31
+ '/engine.ssh.key.txt',
32
+ ].freeze
33
+
24
34
  attr_accessor :session_id
25
35
 
26
36
  def self.name_to_class(name)
@@ -217,13 +227,19 @@ module Ovirt
217
227
 
218
228
  def self.ovirt?(options)
219
229
  options[:username] = options[:password] = "_unused"
220
- !new(options).engine_ssh_public_key.to_s.blank?
221
- rescue RestClient::ResourceNotFound, NoMethodError
222
- false
230
+ !new(options).engine_ssh_public_key.blank?
223
231
  end
224
232
 
225
233
  def engine_ssh_public_key
226
- RestClient::Resource.new("#{base_uri}/engine.ssh.key.txt", resource_options).get
234
+ CANDIDATE_SSH_PUBLIC_KEY_PATHS.each do |path|
235
+ begin
236
+ key = RestClient::Resource.new("#{base_uri}#{path}", resource_options).get
237
+ return key unless key.blank?
238
+ rescue RestClient::ResourceNotFound, NoMethodError
239
+ # Do nothing, just try the next candidate.
240
+ end
241
+ end
242
+ nil
227
243
  end
228
244
 
229
245
  def paginate_resource_get(path = nil, sort_by = :name, direction = :asc)
data/lib/ovirt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ovirt
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0".freeze
3
3
  end
data/lib/ovirt/vm.rb CHANGED
@@ -122,18 +122,36 @@ module Ovirt
122
122
  end
123
123
  end
124
124
 
125
- def memory=(value)
126
- update! do |xml|
127
- xml.memory value
125
+ #
126
+ # Updates the memory of the virtual machine.
127
+ #
128
+ # @param memory [Integer] The virtual memory assigned to the virtual machine, in bytes. If it is `nil` then
129
+ # the virtual memory won't be updated.
130
+ #
131
+ # @param guaranteed [Integer] The amount of physical memory reserved for the virtual machine, in bytes. If
132
+ # it is `nil` then the guaranteed memory won't be updated.
133
+ #
134
+ # @param matrix [Hash] Optional matrix parameters to pass to the update operation, for example `next_run => true`.
135
+ #
136
+ def update_memory(memory, guaranteed, matrix = {})
137
+ update!(matrix) do |xml|
138
+ if memory
139
+ xml.memory memory
140
+ end
141
+ if guaranteed
142
+ xml.memory_policy do
143
+ xml.guaranteed guaranteed
144
+ end
145
+ end
128
146
  end
129
147
  end
130
148
 
149
+ def memory=(value)
150
+ update_memory(value, nil)
151
+ end
152
+
131
153
  def memory_reserve=(value)
132
- update! do |xml|
133
- xml.memory_policy do
134
- xml.guaranteed(value)
135
- end
136
- end
154
+ update_memory(nil, value)
137
155
  end
138
156
 
139
157
  def cloud_init=(content)
data/spec/service_spec.rb CHANGED
@@ -147,17 +147,62 @@ EOX
147
147
  end
148
148
  end
149
149
 
150
- context ".ovirt?" do
151
- it "false when ResourceNotFound" do
152
- expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_raise(RestClient::ResourceNotFound)
153
- expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
150
+ context "#ssh_public_key" do
151
+ let(:base_uri) { "https://nobody.com" }
152
+ let(:old_path) { "/engine.ssh.key.txt" }
153
+ let(:new_path) { "/ovirt-engine/services/pki-resource?resource=engine-certificate&format=OPENSSH-PUBKEY" }
154
+ let(:ssh_key) { "ssh-rsa " + ("A" * 372) + " ovirt-engine\n" }
155
+
156
+ before do
157
+ allow(service).to receive(:base_uri).and_return(base_uri)
154
158
  end
155
159
 
156
- it "false when invalid content encoding returned" do
157
- expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_raise(NoMethodError)
158
- expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
160
+ it "returns valid key for engine older than 3.5" do
161
+ old_resource = double("RestClient::Resource")
162
+ expect(old_resource).to receive(:get).and_return(ssh_key)
163
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{old_path}", anything).and_return(old_resource)
164
+
165
+ new_resource = double("RestClient::Resource")
166
+ expect(new_resource).to receive(:get).and_raise(RestClient::ResourceNotFound)
167
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{new_path}", anything).and_return(new_resource)
168
+
169
+ expect(service.engine_ssh_public_key).to eql(ssh_key)
170
+ end
171
+
172
+ it "returns valid key for engine 3.5 or newer" do
173
+ new_resource = double("RestClient::Resource")
174
+ expect(new_resource).to receive(:get).and_return(ssh_key)
175
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{new_path}", anything).and_return(new_resource)
176
+
177
+ expect(service.engine_ssh_public_key).to eql(ssh_key)
178
+ end
179
+
180
+ it "returns nil if there is no engine" do
181
+ old_resource = double("RestClient::Resource")
182
+ expect(old_resource).to receive(:get).and_raise(RestClient::ResourceNotFound)
183
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{old_path}", anything).and_return(old_resource)
184
+
185
+ new_resource = double("RestClient::Resource")
186
+ expect(new_resource).to receive(:get).and_raise(RestClient::ResourceNotFound)
187
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{new_path}", anything).and_return(new_resource)
188
+
189
+ expect(service.engine_ssh_public_key).to be nil
190
+ end
191
+
192
+ it "returns nil when using a wrong REST client method" do
193
+ old_resource = double("RestClient::Resource")
194
+ expect(old_resource).to receive(:get).and_raise(NoMethodError)
195
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{old_path}", anything).and_return(old_resource)
196
+
197
+ new_resource = double("RestClient::Resource")
198
+ expect(new_resource).to receive(:get).and_raise(NoMethodError)
199
+ expect(RestClient::Resource).to receive(:new).with("#{base_uri}#{new_path}", anything).and_return(new_resource)
200
+
201
+ expect(service.engine_ssh_public_key).to be nil
159
202
  end
203
+ end
160
204
 
205
+ context ".ovirt?" do
161
206
  it "true when key non-empty" do
162
207
  fake_key = "ssh-rsa " + ("A" * 372) + " ovirt-engine\n"
163
208
  expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_return(fake_key)
@@ -169,6 +214,12 @@ EOX
169
214
  expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_return(fake_key)
170
215
  expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
171
216
  end
217
+
218
+ it "false when key nil" do
219
+ fake_key = nil
220
+ expect_any_instance_of(described_class).to receive(:engine_ssh_public_key).and_return(fake_key)
221
+ expect(described_class.ovirt?(:server => "127.0.0.1")).to be false
222
+ end
172
223
  end
173
224
 
174
225
  context "#base_uri" do
@@ -207,24 +258,24 @@ EOX
207
258
  end
208
259
 
209
260
  context "#api_uri" do
210
- BASE_URI = "https://nobody.com"
211
- API_PATH = "/ovirt-engine/api"
261
+ let(:base_uri) { "https://nobody.com" }
262
+ let(:api_path) { "/ovirt-engine/api" }
212
263
 
213
264
  before do
214
- expect(service).to receive(:base_uri).and_return(BASE_URI)
215
- expect(service).to receive(:api_path).and_return(API_PATH)
265
+ expect(service).to receive(:base_uri).and_return(base_uri)
266
+ expect(service).to receive(:api_path).and_return(api_path)
216
267
  end
217
268
 
218
269
  it "removes slash" do
219
- expect(service.api_uri("/vms/123")).to eq("#{BASE_URI}#{API_PATH}/vms/123")
270
+ expect(service.api_uri("/vms/123")).to eq("#{base_uri}#{api_path}/vms/123")
220
271
  end
221
272
 
222
273
  it "removes /api" do
223
- expect(service.api_uri("/api/vms/123")).to eq("#{BASE_URI}#{API_PATH}/vms/123")
274
+ expect(service.api_uri("/api/vms/123")).to eq("#{base_uri}#{api_path}/vms/123")
224
275
  end
225
276
 
226
277
  it "removes /ovirt-engine/api" do
227
- expect(service.api_uri("/ovirt-engine/api/vms/123")).to eq("#{BASE_URI}#{API_PATH}/vms/123")
278
+ expect(service.api_uri("/ovirt-engine/api/vms/123")).to eq("#{base_uri}#{api_path}/vms/123")
228
279
  end
229
280
 
230
281
  end
data/spec/vm_spec.rb CHANGED
@@ -112,7 +112,7 @@ EOX
112
112
  context "#boot_order" do
113
113
  it "with a single string, updates the boot order" do
114
114
  devices = 'hd'
115
- expected_data = <<-EOX.chomp
115
+ expected_data = <<-EOX.chomp
116
116
  <vm>
117
117
  <os>
118
118
  <boot dev="hd"/>
@@ -139,7 +139,7 @@ EOX
139
139
 
140
140
  it "with an array of strings, updates the boot order" do
141
141
  devices = ['network', 'hd']
142
- expected_data = <<-EOX.chomp
142
+ expected_data = <<-EOX.chomp
143
143
  <vm>
144
144
  <os>
145
145
  <boot dev="network"/>
@@ -167,10 +167,35 @@ EOX
167
167
  end
168
168
  end
169
169
 
170
+ context '#memory=' do
171
+ it 'updates the memory' do
172
+ memory = 1_073_741_824 # 1.gigabyte
173
+ expected_data = <<-EOX.chomp
174
+ <vm>
175
+ <memory>#{memory}</memory>
176
+ </vm>
177
+ EOX
178
+
179
+ return_data = <<-EOX.chomp
180
+ <vm>
181
+ <os type='dummy'/>
182
+ <placement_policy>
183
+ <affinity>dummy</affinity>
184
+ </placement_policy>
185
+ </vm>
186
+ EOX
187
+
188
+ expect(service).to receive(:resource_put).once.with(
189
+ vm.attributes[:href],
190
+ expected_data).and_return(return_data)
191
+ vm.memory = memory
192
+ end
193
+ end
194
+
170
195
  context "#memory_reserve" do
171
196
  it "updates the memory policy guarantee" do
172
197
  memory_reserve = 1_073_741_824 # 1.gigabyte
173
- expected_data = <<-EOX.chomp
198
+ expected_data = <<-EOX.chomp
174
199
  <vm>
175
200
  <memory_policy>
176
201
  <guaranteed>#{memory_reserve}</guaranteed>
@@ -194,6 +219,110 @@ EOX
194
219
  end
195
220
  end
196
221
 
222
+ context '#update_memory' do
223
+ it 'updates only "memory" if "guaranteed" is nil' do
224
+ memory = 1_073_741_824 # 1.gigabyte
225
+ guaranteed = nil
226
+ expected_data = <<-EOX.chomp
227
+ <vm>
228
+ <memory>#{memory}</memory>
229
+ </vm>
230
+ EOX
231
+
232
+ return_data = <<-EOX.chomp
233
+ <vm>
234
+ <os type='dummy'/>
235
+ <placement_policy>
236
+ <affinity>dummy</affinity>
237
+ </placement_policy>
238
+ </vm>
239
+ EOX
240
+
241
+ expect(service).to receive(:resource_put).once.with(
242
+ vm.attributes[:href],
243
+ expected_data).and_return(return_data)
244
+ vm.update_memory(memory, guaranteed)
245
+ end
246
+
247
+ it 'updates only "guaranteed" if "memory" is nil' do
248
+ memory = nil
249
+ guaranteed = 1_073_741_824 # 1.gigabyte
250
+ expected_data = <<-EOX.chomp
251
+ <vm>
252
+ <memory_policy>
253
+ <guaranteed>#{guaranteed}</guaranteed>
254
+ </memory_policy>
255
+ </vm>
256
+ EOX
257
+
258
+ return_data = <<-EOX.chomp
259
+ <vm>
260
+ <os type='dummy'/>
261
+ <placement_policy>
262
+ <affinity>dummy</affinity>
263
+ </placement_policy>
264
+ </vm>
265
+ EOX
266
+
267
+ expect(service).to receive(:resource_put).once.with(
268
+ vm.attributes[:href],
269
+ expected_data).and_return(return_data)
270
+ vm.update_memory(memory, guaranteed)
271
+ end
272
+
273
+ it 'updates both if both are not nil' do
274
+ memory = 1_073_741_824 # 1.gigabyte
275
+ guaranteed = 1_073_741_824 # 1.gigabyte
276
+ expected_data = <<-EOX.chomp
277
+ <vm>
278
+ <memory>#{memory}</memory>
279
+ <memory_policy>
280
+ <guaranteed>#{guaranteed}</guaranteed>
281
+ </memory_policy>
282
+ </vm>
283
+ EOX
284
+
285
+ return_data = <<-EOX.chomp
286
+ <vm>
287
+ <os type='dummy'/>
288
+ <placement_policy>
289
+ <affinity>dummy</affinity>
290
+ </placement_policy>
291
+ </vm>
292
+ EOX
293
+
294
+ expect(service).to receive(:resource_put).once.with(
295
+ vm.attributes[:href],
296
+ expected_data).and_return(return_data)
297
+ vm.update_memory(memory, guaranteed)
298
+ end
299
+
300
+ it 'adds the "next_run=true" matrix parameter correctly' do
301
+ memory = 1_073_741_824 # 1.gigabyte
302
+ guaranteed = nil
303
+ expected_data = <<-EOX.chomp
304
+ <vm>
305
+ <memory>#{memory}</memory>
306
+ </vm>
307
+ EOX
308
+
309
+ return_data = <<-EOX.chomp
310
+ <vm>
311
+ <os type='dummy'/>
312
+ <placement_policy>
313
+ <affinity>dummy</affinity>
314
+ </placement_policy>
315
+ </vm>
316
+ </vm>
317
+ EOX
318
+
319
+ expect(service).to receive(:resource_put).once.with(
320
+ vm.attributes[:href] + ';next_run=true',
321
+ expected_data).and_return(return_data)
322
+ vm.update_memory(memory, guaranteed, :next_run => true)
323
+ end
324
+ end
325
+
197
326
  context "#stop" do
198
327
  it "should raise Ovirt::VmIsNotRunning if the VM is not running" do
199
328
  return_data = <<-EOX.chomp
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.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Frey
@@ -25,7 +25,7 @@ authors:
25
25
  autorequire:
26
26
  bindir: bin
27
27
  cert_chain: []
28
- date: 2016-08-23 00:00:00.000000000 Z
28
+ date: 2016-11-21 00:00:00.000000000 Z
29
29
  dependencies:
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport