opennebula 5.13.80.pre → 6.0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/nsx_rule.rb CHANGED
@@ -33,14 +33,27 @@ module NSXDriver
33
33
  unless defined?(GEMS_LOCATION)
34
34
  end
35
35
 
36
- if File.directory?(GEMS_LOCATION)
37
- real_gems_path = File.realpath(GEMS_LOCATION)
38
- if !defined?(Gem) || Gem.path != [real_gems_path]
39
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
36
+ # rubocop: disable all
37
+ # %%RUBYGEMS_SETUP_BEGIN%%
38
+ if File.directory?(GEMS_LOCATION)
39
+ real_gems_path = File.realpath(GEMS_LOCATION)
40
+ if !defined?(Gem) || Gem.path != [real_gems_path]
41
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
42
+
43
+ # Suppress warnings from Rubygems
44
+ # https://github.com/OpenNebula/one/issues/5379
45
+ begin
46
+ verb = $VERBOSE
47
+ $VERBOSE = nil
40
48
  require 'rubygems'
41
49
  Gem.use_paths(real_gems_path)
50
+ ensure
51
+ $VERBOSE = verb
42
52
  end
43
53
  end
54
+ end
55
+ # %%RUBYGEMS_SETUP_END%%
56
+ # rubocop: enable all
44
57
 
45
58
  $LOAD_PATH << RUBY_LIB_LOCATION
46
59
 
data/lib/nsxt_client.rb CHANGED
@@ -29,14 +29,27 @@ module NSXDriver
29
29
  unless defined?(GEMS_LOCATION)
30
30
  end
31
31
 
32
- if File.directory?(GEMS_LOCATION)
33
- real_gems_path = File.realpath(GEMS_LOCATION)
34
- if !defined?(Gem) || Gem.path != [real_gems_path]
35
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
32
+ # rubocop: disable all
33
+ # %%RUBYGEMS_SETUP_BEGIN%%
34
+ if File.directory?(GEMS_LOCATION)
35
+ real_gems_path = File.realpath(GEMS_LOCATION)
36
+ if !defined?(Gem) || Gem.path != [real_gems_path]
37
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
38
+
39
+ # Suppress warnings from Rubygems
40
+ # https://github.com/OpenNebula/one/issues/5379
41
+ begin
42
+ verb = $VERBOSE
43
+ $VERBOSE = nil
36
44
  require 'rubygems'
37
45
  Gem.use_paths(real_gems_path)
46
+ ensure
47
+ $VERBOSE = verb
38
48
  end
39
49
  end
50
+ end
51
+ # %%RUBYGEMS_SETUP_END%%
52
+ # rubocop: enable all
40
53
 
41
54
  $LOAD_PATH << RUBY_LIB_LOCATION
42
55
 
data/lib/nsxv_client.rb CHANGED
@@ -29,14 +29,27 @@ module NSXDriver
29
29
  unless defined?(GEMS_LOCATION)
30
30
  end
31
31
 
32
- if File.directory?(GEMS_LOCATION)
33
- real_gems_path = File.realpath(GEMS_LOCATION)
34
- if !defined?(Gem) || Gem.path != [real_gems_path]
35
- $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
32
+ # rubocop: disable all
33
+ # %%RUBYGEMS_SETUP_BEGIN%%
34
+ if File.directory?(GEMS_LOCATION)
35
+ real_gems_path = File.realpath(GEMS_LOCATION)
36
+ if !defined?(Gem) || Gem.path != [real_gems_path]
37
+ $LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
38
+
39
+ # Suppress warnings from Rubygems
40
+ # https://github.com/OpenNebula/one/issues/5379
41
+ begin
42
+ verb = $VERBOSE
43
+ $VERBOSE = nil
36
44
  require 'rubygems'
37
45
  Gem.use_paths(real_gems_path)
46
+ ensure
47
+ $VERBOSE = verb
38
48
  end
39
49
  end
50
+ end
51
+ # %%RUBYGEMS_SETUP_END%%
52
+ # rubocop: enable all
40
53
 
41
54
  $LOAD_PATH << RUBY_LIB_LOCATION
42
55
 
data/lib/opennebula.rb CHANGED
@@ -77,5 +77,5 @@ require 'opennebula/flow'
77
77
  module OpenNebula
78
78
 
79
79
  # OpenNebula version
80
- VERSION = '5.13.80'
80
+ VERSION = '6.0.0.2'
81
81
  end
@@ -88,7 +88,7 @@ module OpenNebula
88
88
  NO_ONE_AUTH_ERROR = "ONE_AUTH file not present"
89
89
 
90
90
  attr_accessor :one_auth
91
- attr_reader :one_endpoint
91
+ attr_reader :one_endpoint, :one_zmq
92
92
 
93
93
  begin
94
94
  require 'xmlparser'
@@ -152,6 +152,14 @@ module OpenNebula
152
152
 
153
153
  @async = !options[:sync]
154
154
 
155
+ if options[:subscriber_endpoint]
156
+ @one_zmq = options[:subscriber_endpoint]
157
+ elsif ENV["ONE_ZMQ"]
158
+ @one_zmq = ENV["ONE_ZMQ"]
159
+ else
160
+ @one_zmq = 'tcp://localhost:2101'
161
+ end
162
+
155
163
  timeout=nil
156
164
  if options[:timeout]
157
165
  timeout = options[:timeout]
@@ -357,7 +357,15 @@ module OpenNebula
357
357
 
358
358
  break rc if OpenNebula.is_error?(rc)
359
359
 
360
- rc = template.clone("#{template.name}-#{name}", recursive)
360
+ # The maximum size is 128, so crop the template name if it
361
+ # exceeds the limit
362
+ new_name = "#{template.name}-#{name}"
363
+
364
+ if new_name.size > 119
365
+ new_name = "#{template.name[0..(119 - name.size)]}-#{name}"
366
+ end
367
+
368
+ rc = template.clone(new_name, recursive)
361
369
 
362
370
  break rc if OpenNebula.is_error?(rc)
363
371
 
@@ -384,6 +392,9 @@ module OpenNebula
384
392
  return rc
385
393
  end
386
394
 
395
+ # add registration time, as the template is new
396
+ body['registration_time'] = Integer(Time.now)
397
+
387
398
  # update the template with the new body
388
399
  doc.update(body.to_json)
389
400
 
@@ -391,6 +402,31 @@ module OpenNebula
391
402
  new_id
392
403
  end
393
404
 
405
+ # Clones a service template
406
+ #
407
+ # @param name [Stirng] New name
408
+ #
409
+ # @return [Integer] New template ID
410
+ def clone(name)
411
+ new_id = super
412
+
413
+ doc = OpenNebula::ServiceTemplate.new_with_id(new_id, @client)
414
+ rc = doc.info
415
+
416
+ return rc if OpenNebula.is_error?(rc)
417
+
418
+ body = JSON.parse(doc["TEMPLATE/#{TEMPLATE_TAG}"])
419
+
420
+ # add registration time, as the template is new
421
+ body['registration_time'] = Integer(Time.now)
422
+
423
+ # update the template with the new body
424
+ DocumentJSON.instance_method(:update).bind(doc).call(body.to_json)
425
+
426
+ # return the new document ID
427
+ new_id
428
+ end
429
+
394
430
  # Replaces the raw template contents
395
431
  #
396
432
  # @param template [String] New template contents, in the form KEY = VAL
@@ -308,6 +308,8 @@ module OpenNebula
308
308
  end
309
309
 
310
310
  def wait_state(state, timeout=120)
311
+ require 'opennebula/wait_ext'
312
+
311
313
  extend OpenNebula::WaitExt
312
314
 
313
315
  rc = wait(state, timeout)
@@ -155,6 +155,10 @@ module OpenNebula::MarketPlaceAppExt
155
155
  is_vcenter = !OpenNebula.is_error?(rc) &&
156
156
  (ds['TEMPLATE/DRIVER'] == 'vcenter')
157
157
 
158
+ if is_vcenter && options[:template].nil?
159
+ options = update_options_with_template(options)
160
+ end
161
+
158
162
  #---------------------------------------------------------------
159
163
  # Allocate the image in OpenNebula
160
164
  #---------------------------------------------------------------
@@ -181,15 +185,17 @@ module OpenNebula::MarketPlaceAppExt
181
185
  #---------------------------------------------------------------
182
186
  # Created an associated VMTemplate if needed
183
187
  #---------------------------------------------------------------
184
- if self['TEMPLATE/VMTEMPLATE64'].nil? || options[:notemplate]
188
+ if (self['TEMPLATE/VMTEMPLATE64'].nil? && !is_vcenter) ||
189
+ options[:notemplate] ||
190
+ options[:template] == -1
185
191
  return rc_info
186
192
  end
187
193
 
188
194
  if !options[:template].nil?
189
195
  template_id = options[:template]
190
196
 
191
- if template_id == -1
192
- template_id = options[:default_template]
197
+ if template_id < 0
198
+ raise 'Invalid option, template_id must be a valid ID'
193
199
  end
194
200
 
195
201
  template = Template.new_with_id(template_id, @client)
@@ -280,6 +286,33 @@ module OpenNebula::MarketPlaceAppExt
280
286
  rc
281
287
  end
282
288
 
289
+ def update_options_with_template(options, _validate = false)
290
+ vcenterrc_path =
291
+ "#{VAR_LOCATION}/remotes/etc/vmm/vcenter/vcenterrc"
292
+
293
+ if File.file?(vcenterrc_path)
294
+ config_vcenter = YAML.load_file(vcenterrc_path)
295
+
296
+ if config_vcenter.key?(:default_template)
297
+ options[:template] =
298
+ config_vcenter[:default_template]
299
+
300
+ options
301
+ else
302
+ raise "Couldn't find default_template " \
303
+ 'configuration in vcenterrc conf ' \
304
+ 'file. Please use the --template ' \
305
+ 'file to define a VM Template ID if ' \
306
+ 'needed or add default_template to' \
307
+ ' vcenterrc conf file'
308
+ end
309
+ else
310
+ raise "Couldn't find vcenterrc conf file. " \
311
+ ' Please use the --template file to define' \
312
+ ' a VM Template ID if needed.'
313
+ end
314
+ end
315
+
283
316
  # Creates a VM template based on the APPTEMPLATE64 attribute
284
317
  # @param [Hash] options
285
318
  # :export_name [String] name of the vm template
@@ -288,19 +321,50 @@ module OpenNebula::MarketPlaceAppExt
288
321
  #
289
322
  # @return [Integer, OpenNebula::Error] template id or error
290
323
  def create_vm_template(options, disks)
291
- # --------------------------------------------------------------
292
- # Allocate Template
293
- # --------------------------------------------------------------
294
- if self['TEMPLATE/APPTEMPLATE64'].nil?
295
- return Error.new("Missing APPTEMPLATE64 for App #{id}")
296
- end
324
+ dsid = options[:dsid]
325
+ ds = OpenNebula::Datastore.new_with_id(dsid, @client)
326
+ rc = ds.info
297
327
 
298
- tmpl = Base64.decode64(self['TEMPLATE/APPTEMPLATE64'])
328
+ is_vcenter =
329
+ !OpenNebula.is_error?(rc) &&
330
+ (ds['TEMPLATE/DRIVER'] == 'vcenter')
331
+
332
+ if is_vcenter
333
+ if options[:template].nil?
334
+ options = update_options_with_template(options)
335
+ end
336
+
337
+ template_id = options[:template]
338
+
339
+ if template_id < 0
340
+ return
341
+ end
342
+
343
+ template = Template.new_with_id(template_id, @client)
344
+
345
+ vmtpl_id = template.clone(
346
+ options[:vmtemplate_name] || options[:name]
347
+ )
348
+
349
+ vmtpl = Template.new_with_id(vmtpl_id, @client)
350
+ rc = vmtpl.info
351
+ else
352
+ # ----------------------------------------------------------
353
+ # Allocate Template
354
+ # ----------------------------------------------------------
355
+ if self['TEMPLATE/APPTEMPLATE64'].nil?
356
+ return Error.new(
357
+ "Missing APPTEMPLATE64 for App #{id}"
358
+ )
359
+ end
360
+
361
+ tmpl = Base64.decode64(self['TEMPLATE/APPTEMPLATE64'])
299
362
 
300
- tmpl << "\nNAME=\"#{options[:name]}\"\n"
363
+ tmpl << "\nNAME=\"#{options[:name]}\"\n"
301
364
 
302
- vmtpl = Template.new(Template.build_xml, @client)
303
- rc = vmtpl.allocate(tmpl)
365
+ vmtpl = Template.new(Template.build_xml, @client)
366
+ rc = vmtpl.allocate(tmpl)
367
+ end
304
368
 
305
369
  return rc if OpenNebula.is_error?(rc)
306
370
 
@@ -322,5 +322,7 @@ module OpenNebula
322
322
  def is_paginated?
323
323
  PAGINATED_POOLS.include?(@pool_name)
324
324
  end
325
+
325
326
  end
327
+
326
328
  end
@@ -75,6 +75,17 @@ module OpenNebula::TemplateExt
75
75
  return [image, ids]
76
76
  end
77
77
 
78
+ i_state = OpenNebula::Image::IMAGE_STATES[
79
+ image['STATE'].to_i
80
+ ]
81
+
82
+ unless %w[LOCKED READY USED].include?(i_state)
83
+ logger.fatal "Wrong image state #{i_state}" if logger
84
+
85
+ rollback(ids)
86
+ return [image, ids]
87
+ end
88
+
78
89
  logger.info "Adding disk with image #{image.id}" if logger
79
90
 
80
91
  tmpl, main = create_app_template(image, idx)
@@ -209,8 +220,14 @@ module OpenNebula::TemplateExt
209
220
  # - content for VM template
210
221
  #-------------------------------------------------------------------
211
222
  def create_app_template(image, idx = 0)
212
- # Wait until the image is READY to safe copy it to the MP
213
- image.wait('READY') if Integer(image['STATE']) != 1
223
+ i_state = OpenNebula::Image::IMAGE_STATES[image['STATE'].to_i]
224
+
225
+ # If the image is used, there is no need to wait until it is
226
+ # ready because the image is already ready to be copied
227
+ if i_state != 'USED' && Integer(image['STATE']) != 1
228
+ # Wait until the image is READY to safe copy it to the MP
229
+ image.wait('READY')
230
+ end
214
231
 
215
232
  # Rename to avoid clashing names
216
233
  app_name = "#{image['NAME']}-#{SecureRandom.hex[0..9]}"
@@ -771,6 +771,8 @@ module OpenNebula
771
771
  end
772
772
 
773
773
  def wait_state(state, timeout=120)
774
+ require 'opennebula/wait_ext'
775
+
774
776
  extend OpenNebula::WaitExt
775
777
 
776
778
  rc = wait2(state, 'LCM_INIT', timeout)
@@ -267,17 +267,20 @@ module OpenNebula::VirtualMachineExt
267
267
  # --------------------------------------------------------------
268
268
  # Check backup consistency
269
269
  # --------------------------------------------------------------
270
- unless binfo
271
- rc = info
272
- raise rc.message if OpenNebula.is_error?(rc)
270
+ rc = info
271
+
272
+ raise rc.message if OpenNebula.is_error?(rc)
273
273
 
274
- binfo = backup_info
274
+ binfo.merge!(backup_info) do |key, old_val, new_val|
275
+ new_val.nil? ? old_val : new_val
275
276
  end
276
277
 
277
278
  raise 'No backup information' if binfo.nil?
278
279
 
279
280
  raise 'No frequency defined' unless valid?(binfo[:freq])
280
281
 
282
+ raise 'No marketplace defined' unless valid?(binfo[:market])
283
+
281
284
  return if Time.now.to_i - binfo[:last].to_i < binfo[:freq].to_i
282
285
 
283
286
  # --------------------------------------------------------------
@@ -319,19 +322,12 @@ module OpenNebula::VirtualMachineExt
319
322
  # --------------------------------------------------------------
320
323
  # Cleanup
321
324
  # --------------------------------------------------------------
322
- logger.info "Deleting template #{tmp.id}" if logger
323
-
324
- tmp.delete(true)
325
-
326
- binfo[:apps].each do |id|
327
- log "Deleting applicance #{id}" if logger
328
-
329
- papp = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
330
-
331
- papp.delete
332
- end if !keep && binfo[:apps]
325
+ backup_cleanup(keep, logger, binfo, tmp)
333
326
  rescue Error, StandardError => e
327
+ backup_cleanup(keep, logger, binfo, tmp)
328
+
334
329
  logger.fatal(e.inspect) if logger
330
+
335
331
  raise
336
332
  end
337
333
 
@@ -421,9 +417,9 @@ module OpenNebula::VirtualMachineExt
421
417
 
422
418
  private
423
419
 
424
- # --------------------------------------------------------------
420
+ #-------------------------------------------------------------------
425
421
  # Check an attribute is defined and valid
426
- # --------------------------------------------------------------
422
+ #-------------------------------------------------------------------
427
423
  def valid?(att)
428
424
  return false if att.nil?
429
425
 
@@ -454,6 +450,9 @@ module OpenNebula::VirtualMachineExt
454
450
  binfo
455
451
  end
456
452
 
453
+ #-------------------------------------------------------------------
454
+ # Generate backup information string
455
+ #-------------------------------------------------------------------
457
456
  def backup_attr(binfo, ids)
458
457
  'BACKUP=[' \
459
458
  " MARKETPLACE_APP_IDS = \"#{ids.join(',')}\"," \
@@ -462,6 +461,25 @@ module OpenNebula::VirtualMachineExt
462
461
  " MARKETPLACE_ID = \"#{binfo[:market]}\" ]"
463
462
  end
464
463
 
464
+ #-------------------------------------------------------------------
465
+ # Cleanup backup leftovers in case of failure
466
+ #-------------------------------------------------------------------
467
+ def backup_cleanup(keep, logger, binfo, template)
468
+ if template
469
+ logger.info "Deleting template #{template.id}" if logger
470
+
471
+ template.delete(true)
472
+ end
473
+
474
+ binfo[:apps].each do |id|
475
+ logger.info "Deleting applicance #{id}" if logger
476
+
477
+ papp = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
478
+
479
+ papp.delete
480
+ end if !keep && binfo[:apps]
481
+ end
482
+
465
483
  end
466
484
  end
467
485