opennebula 6.2.0.1 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 386d417b0331ab8ad16270e5ae78b27efc0a319a45dc3cbad2805c6eef0f638b
4
- data.tar.gz: d27b0d68fdb8382d94b5b5dcd6d1139214147783e146496014edaa7c9b870f08
3
+ metadata.gz: 630fc82258e06265dd9308385f987452c2c9e97774f9c844567eb0512c699996
4
+ data.tar.gz: 4b19ee5faf356fc61ba4e8883dc7bb37137d54d34c251c6f0cbbfab5a8b0b27b
5
5
  SHA512:
6
- metadata.gz: 177d4446ad29cdcf12b7485010909ba6954155cfe83a9948c6fd0673fe2c260470b41c512b279872212355bb3435c74a1762bc8ea39c028623b809df0cf83167
7
- data.tar.gz: 7ba61e9e6c83aaeffc1f62e772be95028f8dba3bf7000397f8cf27d322fef9cee4c9c745d81d80c6763df336609b9aeebfbf23c5003507559726cef432f6a7d7
6
+ metadata.gz: ea3eba7d99bfc70cb7b94a2c8c2548b130d50ec3cf73d3344e0ed12a05b2e83780eec32e4790cfeef00bde6a38164468a0cfe91bb62cd1325c20aac7f9cca235
7
+ data.tar.gz: eeb5c702a03ef47f5ad8e37f95b94259e49019a78d5b58f8ce560d3b2afd50cb8828a7512afe14b1f3e25e262ab3b3974f9174e3109a20a98d89140a90fbca96
@@ -51,7 +51,7 @@ end
51
51
  module CloudClient
52
52
 
53
53
  # OpenNebula version
54
- VERSION = '6.2.0.1'
54
+ VERSION = '6.2.1'
55
55
 
56
56
  # #########################################################################
57
57
  # Default location for the authentication file
data/lib/datacenter.rb CHANGED
@@ -131,7 +131,10 @@ module VCenterDriver
131
131
 
132
132
  # Setting host import name and
133
133
  # replace spaces and weird characters
134
- cluster_name = (ccr['name']).to_s.tr(' ', '_')
134
+ cluster_name = ccr['name'].to_s.tr(' ', '_')
135
+ cluster_name = VCenterDriver::VcImporter.sanitize(
136
+ cluster_name
137
+ )
135
138
  cluster_name =
136
139
  VCenterDriver::VIHelper
137
140
  .one_name(
@@ -159,11 +162,28 @@ module VCenterDriver
159
162
  host_objects
160
163
  end
161
164
 
162
- def get_unimported_datastores(dpool, vcenter_instance_name, hpool)
165
+ # rubocop:disable Style/GlobalVars
166
+ def get_unimported_datastores(dpool, vcenter_instance_name, hpool, args)
163
167
  import_id = 0
164
168
  ds_objects = {}
165
169
  vcenter_uuid = vcenter_instance_uuid
166
170
 
171
+ # Selected host in OpenNebula
172
+ if $conf.nil?
173
+ one_client = OpenNebula::Client.new
174
+ else
175
+ one_client = OpenNebula::Client.new(
176
+ nil,
177
+ $conf[:one_xmlrpc]
178
+ )
179
+ end
180
+ one_host = OpenNebula::Host.new_with_id(args[:host], one_client)
181
+
182
+ rc = one_host.info
183
+ raise rc.message if OpenNebula.is_error? rc
184
+
185
+ cluster_id = one_host['CLUSTER_ID'].to_i
186
+
167
187
  # Get datacenters
168
188
  fetch! if @items.empty?
169
189
 
@@ -185,7 +205,10 @@ module VCenterDriver
185
205
  'summary.freeSpace'
186
206
  )
187
207
 
188
- ds_name = name.to_s
208
+ ds_name = VCenterDriver::VcImporter.sanitize(
209
+ name.to_s
210
+ )
211
+
189
212
  ds_total_mb = ((capacity.to_i / 1024) / 1024)
190
213
  ds_free_mb = ((free_space.to_i / 1024) / 1024)
191
214
  ds_ref = ds['_ref']
@@ -363,8 +386,15 @@ module VCenterDriver
363
386
  end
364
387
  end
365
388
 
389
+ ds_objects.keys.each do |key|
390
+ unless ds_objects[key][:cluster].include? cluster_id
391
+ ds_objects.delete key
392
+ end
393
+ end
394
+
366
395
  { vcenter_instance_name => ds_objects }
367
396
  end
397
+ # rubocop:enable Style/GlobalVars
368
398
 
369
399
  def get_unimported_templates(vi_client, tpool)
370
400
  template_objects = {}
data/lib/datastore.rb CHANGED
@@ -881,7 +881,7 @@ module VCenterDriver
881
881
  @one_class = OpenNebula::Datastore
882
882
  end
883
883
 
884
- def get_list(_args = {})
884
+ def get_list(args = {})
885
885
  dc_folder = VCenterDriver::DatacenterFolder.new(@vi_client)
886
886
 
887
887
  # one pool creation
@@ -908,7 +908,8 @@ module VCenterDriver
908
908
  .get_unimported_datastores(
909
909
  dpool,
910
910
  @vi_client.vc_name,
911
- hpool
911
+ hpool,
912
+ args
912
913
  )
913
914
  @list = rs
914
915
  end
@@ -948,7 +949,11 @@ module VCenterDriver
948
949
  clusters = opts['selected_clusters'].each.map(&:to_i)
949
950
  end
950
951
 
951
- res = { :id => [], :name => selected[:simple_name] }
952
+ name = VCenterDriver::VcImporter.sanitize(
953
+ selected[:simple_name]
954
+ )
955
+
956
+ res = { :id => [], :name => name }
952
957
  @info[:rollback] = []
953
958
  pair.each do |ds|
954
959
  create(ds[:one]) do |one_object, id|
@@ -1011,7 +1016,9 @@ module VCenterDriver
1011
1016
  message = 'Error creating the OpenNebula resource'
1012
1017
  info = selected[:one]
1013
1018
  dsid = selected[:dsid].to_i
1014
- name = selected[:name]
1019
+ name = VCenterDriver::VcImporter.sanitize(
1020
+ selected[:name]
1021
+ )
1015
1022
 
1016
1023
  rc = resource.allocate(info, dsid, false)
1017
1024
  VCenterDriver::VIHelper.check_error(rc, message)
@@ -15,7 +15,9 @@
15
15
  # ---------------------------------------------------------------------------- #
16
16
 
17
17
  require 'rubygems'
18
- require 'opennebula'
18
+ require 'opennebula/xml_utils'
19
+ require 'opennebula/client'
20
+ require 'opennebula/group_pool'
19
21
  require 'net/ldap'
20
22
  require 'yaml'
21
23
 
@@ -461,7 +461,7 @@ module OpenNebula::MarketPlaceAppExt
461
461
  def export_recursive(xpath, options)
462
462
  # Get marketplace apps pool to find roles apps
463
463
  pool = OpenNebula::MarketPlaceAppPool.new(@client)
464
- rc = pool.info
464
+ rc = pool.info_all
465
465
 
466
466
  return rc if OpenNebula.is_error?(rc)
467
467
 
@@ -89,8 +89,8 @@ module OpenNebula
89
89
  #######################################################################
90
90
 
91
91
  # Retrieves the information of the given User.
92
- def info()
93
- super(USER_METHODS[:info], 'USER')
92
+ def info(decrypt = false)
93
+ super(USER_METHODS[:info], 'USER', decrypt)
94
94
  end
95
95
 
96
96
  alias_method :info!, :info
@@ -94,6 +94,35 @@ module OpenNebula::VirtualMachineExt
94
94
  raise rc.message if OpenNebula.is_error?(rc)
95
95
  end
96
96
 
97
+ # --------------------------------------------------------------
98
+ # Ask if source VM is linked clone
99
+ # --------------------------------------------------------------
100
+ use_linked_clones = self['USER_TEMPLATE/VCENTER_LINKED_CLONES']
101
+
102
+ if use_linked_clones && use_linked_clones.downcase == 'yes'
103
+ # Delay the require until it is strictly needed
104
+ # This way we can avoid the vcenter driver dependency
105
+ # in no vCenter deployments
106
+ require 'vcenter_driver'
107
+
108
+ deploy_id = self['DEPLOY_ID']
109
+ vm_id = self['ID']
110
+ host_id = self['HISTORY_RECORDS/HISTORY[last()]/HID']
111
+ vi_client = VCenterDriver::VIClient.new_from_host(host_id)
112
+
113
+ vm = VCenterDriver::VirtualMachine.new(
114
+ vi_client,
115
+ deploy_id,
116
+ vm_id
117
+ )
118
+
119
+ error, vm_template_ref = vm.save_as_linked_clones(name)
120
+
121
+ raise error unless error.nil?
122
+
123
+ return vm_template_ref
124
+ end
125
+
97
126
  # --------------------------------------------------------------
98
127
  # Clone the source template
99
128
  # --------------------------------------------------------------
@@ -271,7 +300,7 @@ module OpenNebula::VirtualMachineExt
271
300
 
272
301
  raise rc.message if OpenNebula.is_error?(rc)
273
302
 
274
- binfo.merge!(backup_info) do |key, old_val, new_val|
303
+ binfo.merge!(backup_info) do |_key, old_val, new_val|
275
304
  new_val.nil? ? old_val : new_val
276
305
  end
277
306
 
@@ -472,7 +501,7 @@ module OpenNebula::VirtualMachineExt
472
501
  end
473
502
 
474
503
  binfo[:apps].each do |id|
475
- logger.info "Deleting applicance #{id}" if logger
504
+ logger.info "Deleting appliance #{id}" if logger
476
505
 
477
506
  papp = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
478
507
 
@@ -450,6 +450,10 @@ module OpenNebula
450
450
  private
451
451
 
452
452
  def build_accounting(filter_flag, options, &block)
453
+
454
+ options[:start_time] = -1 if options[:start_time].nil?
455
+ options[:end_time] = -1 if options[:end_time].nil?
456
+
453
457
  xml_str = @client.call(VM_POOL_METHODS[:accounting],
454
458
  filter_flag,
455
459
  options[:start_time],
data/lib/opennebula.rb CHANGED
@@ -77,5 +77,5 @@ require 'opennebula/flow'
77
77
  module OpenNebula
78
78
 
79
79
  # OpenNebula version
80
- VERSION = '6.2.0.1'
80
+ VERSION = '6.2.1'
81
81
  end
@@ -202,7 +202,7 @@ module VCenterDriver
202
202
  # index associated to his own resource opt
203
203
  #
204
204
  # Example:
205
- # {"vm-343" => {linked: '0', copy: '0'...}
205
+ # {"vm-343" => {:linked_clone: '0', :copy: '0'...}
206
206
  #
207
207
  # @ return [Hash] the list of unimported resources
208
208
  #
@@ -263,7 +263,10 @@ module VCenterDriver
263
263
 
264
264
  cluster_list = {}
265
265
  cpool.each do |c|
266
- cluster_list[c['ID']] = c['NAME'] if c['ID'].to_i != 0
266
+ name = VCenterDriver::VcImporter.sanitize(
267
+ c['NAME']
268
+ )
269
+ cluster_list[c['ID']] = name if c['ID'].to_i != 0
267
270
  end
268
271
 
269
272
  # Get OpenNebula's host pool
@@ -312,10 +315,13 @@ module VCenterDriver
312
315
 
313
316
  cluster_list_str = "\n"
314
317
  cluster_list.each do |key, value|
318
+ name = VCenterDriver::VcImporter.sanitize(
319
+ value
320
+ )
315
321
  cluster_list_str << " - \e[94mID: " \
316
322
  << key \
317
323
  << "\e[39m - NAME: " \
318
- << value << "\n"
324
+ << name << "\n"
319
325
  end
320
326
 
321
327
  STDOUT.print "\n #{cluster_list_str}"
@@ -330,15 +336,19 @@ module VCenterDriver
330
336
  end
331
337
  end
332
338
 
339
+ cluster_name = VCenterDriver::VcImporter.sanitize(
340
+ cluster[:cluster_name]
341
+ )
342
+
333
343
  # Check if the OpenNebula Cluster exists, and reuse it
334
344
  one_cluster_id ||= cluster_list
335
- .key(cluster[:cluster_name])
345
+ .key(cluster_name)
336
346
 
337
347
  if !one_cluster_id
338
348
  one_cluster = VCenterDriver::VIHelper
339
349
  .new_one_item(OpenNebula::Cluster)
340
350
  rc = one_cluster
341
- .allocate((cluster[:cluster_name]).to_s)
351
+ .allocate(cluster_name.to_s)
342
352
  if ::OpenNebula.is_error?(rc)
343
353
  # rubocop:disable Layout/LineLength
344
354
  STDOUT.puts " Error creating OpenNebula cluster: #{rc.message}\n"
@@ -355,7 +365,7 @@ module VCenterDriver
355
365
  rpool,
356
366
  one_cluster_id)
357
367
  # rubocop:disable Layout/LineLength
358
- STDOUT.puts "\n OpenNebula host \e[92m#{cluster[:cluster_name]}\e[39m with"\
368
+ STDOUT.puts "\n OpenNebula host \e[92m#{cluster_name}\e[39m with"\
359
369
  " ID \e[94m#{one_host.id}\e[39m successfully created."
360
370
  STDOUT.puts
361
371
  # rubocop:enable Layout/LineLength
@@ -579,8 +579,6 @@ end
579
579
  end
580
580
  end
581
581
 
582
- dc = cluster.datacenter
583
-
584
582
  vcenter_vm_folder = drv_action['USER_TEMPLATE/VCENTER_VM_FOLDER']
585
583
 
586
584
  if !vcenter_vm_folder.nil? && !vcenter_vm_folder.empty?
@@ -1983,7 +1981,7 @@ end
1983
1981
  end
1984
1982
 
1985
1983
  card_spec = {
1986
- :key => Time.now.utc.strftime('%Y%m%d%M%S%L').to_i,
1984
+ :key => 0,
1987
1985
  :deviceInfo => {
1988
1986
  :label => 'net' + card_num.to_s,
1989
1987
  :summary => pg_name
@@ -1993,6 +1991,9 @@ end
1993
1991
  :macAddress => mac,
1994
1992
  :unitNumber => unumber
1995
1993
  }
1994
+ if @vi_client.vim.serviceContent.about.apiVersion.to_f >= 7.0
1995
+ card_spec[:key] = Time.now.utc.strftime('%m%d%M%S%L').to_i
1996
+ end
1996
1997
 
1997
1998
  if (limit || rsrv) && (limit > 0)
1998
1999
  ra_spec = {}
@@ -2129,7 +2130,7 @@ end
2129
2130
  end
2130
2131
 
2131
2132
  card_spec = {
2132
- :key => Time.now.utc.strftime('%Y%m%d%M%S%L').to_i,
2133
+ :key => 0,
2133
2134
  :deviceInfo => {
2134
2135
  :label => 'net' + card_num.to_s,
2135
2136
  :summary => pg_name
@@ -2137,6 +2138,9 @@ end
2137
2138
  :backing => backing,
2138
2139
  :addressType => 'generated'
2139
2140
  }
2141
+ if @vi_client.vim.serviceContent.about.apiVersion.to_f >= 7.0
2142
+ card_spec[:key] = Time.now.utc.strftime('%m%d%M%S%L').to_i
2143
+ end
2140
2144
 
2141
2145
  if (limit || rsrv) && (limit > 0)
2142
2146
  ra_spec = {}
data/lib/vm_template.rb CHANGED
@@ -96,6 +96,90 @@ module VCenterDriver
96
96
  @vi_client.vim.serviceContent.about.instanceUuid rescue nil
97
97
  end
98
98
 
99
+ def save_as_linked_clones(name)
100
+ error = nil
101
+
102
+ disks = @item.config.hardware.device.grep(
103
+ RbVmomi::VIM::VirtualMachine
104
+ )
105
+ disks.select {|x| x.backing.parent.nil? }.each do |disk|
106
+ spec = {
107
+ :deviceChange => [
108
+ {
109
+ :operation => :remove,
110
+ :device => disk
111
+ },
112
+ {
113
+ :operation => :add,
114
+ :fileOperation => :create,
115
+ :device => disk.dup.tap do |x|
116
+ x.backing = x.backing.dup
117
+ x.backing.fileName =
118
+ "[#{disk.backing.datastore.name}]"
119
+ x.backing.parent = disk.backing
120
+ end
121
+ }
122
+ ]
123
+ }
124
+ @item.ReconfigVM_Task(
125
+ :spec => spec
126
+ ).wait_for_completion
127
+ end
128
+
129
+ relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec(
130
+ :diskMoveType => :moveChildMostDiskBacking
131
+ )
132
+
133
+ spec = RbVmomi::VIM.VirtualMachineCloneSpec(
134
+ :location => relocateSpec,
135
+ :powerOn => false,
136
+ :template => true
137
+ )
138
+
139
+ new_template = @item.CloneVM_Task(
140
+ :folder => @item.parent,
141
+ :name => name,
142
+ :spec => spec
143
+ ).wait_for_completion
144
+
145
+ new_vm_template_ref = new_template._ref
146
+
147
+ one_client = OpenNebula::Client.new
148
+ importer = VCenterDriver::VmImporter.new(
149
+ one_client,
150
+ @vi_client
151
+ )
152
+
153
+ importer.retrieve_resources({})
154
+ importer.get_indexes(new_vm_template_ref)
155
+
156
+ importer.process_import(
157
+ new_vm_template_ref,
158
+ {
159
+ new_vm_template_ref.to_s => {
160
+ :type => 'default',
161
+ :linked_clone => '1',
162
+ :copy => '0',
163
+ :name => '',
164
+ :folder => ''
165
+ }
166
+ }
167
+ )
168
+
169
+ begin
170
+ importer.output[:success][0][:id][0]
171
+ rescue StandardError => e
172
+ error = 'Creating linked clone VM Template' \
173
+ " failed due to \"#{e.message}\".\n"
174
+
175
+ if VCenterDriver::CONFIG[:debug_information]
176
+ error += " #{e.backtrace}\n"
177
+ end
178
+ end
179
+
180
+ [error, new_vm_template_ref]
181
+ end
182
+
99
183
  def create_template_copy(template_name)
100
184
  error = nil
101
185
  template_ref = nil
@@ -1835,12 +1919,10 @@ module VCenterDriver
1835
1919
  # the template if something go wrong
1836
1920
  if copy
1837
1921
  error, template_copy_ref =
1838
- selected[:template]
1839
- .create_template_copy(
1840
- opts[:name]
1841
- )
1922
+ selected[:template].save_as_linked_clones(opts[:name])
1923
+
1842
1924
  unless template_copy_ref
1843
- raise 'There is a problem creating creating' \
1925
+ raise 'There is a problem creating ' \
1844
1926
  "your copy: #{error}"
1845
1927
  end
1846
1928
 
@@ -1893,68 +1975,70 @@ module VCenterDriver
1893
1975
  working_template[:one] <<
1894
1976
  "VCENTER_TEMPLATE_NAME=\"#{selected[:name]}\"\n"
1895
1977
 
1896
- create(working_template[:one]) do |one_object, id|
1897
- res[:id] << id
1978
+ unless copy
1979
+ create(working_template[:one]) do |one_object, id|
1980
+ res[:id] << id
1898
1981
 
1899
- type = { :object => 'template', :id => id }
1900
- error, template_disks, allocated_images =
1901
- template
1902
- .import_vcenter_disks(
1903
- vc_uuid,
1904
- dpool,
1905
- ipool,
1906
- type
1907
- )
1982
+ type = { :object => 'template', :id => id }
1983
+ error, template_disks, allocated_images =
1984
+ template
1985
+ .import_vcenter_disks(
1986
+ vc_uuid,
1987
+ dpool,
1988
+ ipool,
1989
+ type
1990
+ )
1908
1991
 
1909
- if allocated_images
1910
- # rollback stack
1911
- allocated_images.reverse.each do |i|
1912
- @rollback.unshift(Raction.new(i, :delete))
1992
+ if allocated_images
1993
+ # rollback stack
1994
+ allocated_images.reverse.each do |i|
1995
+ @rollback.unshift(Raction.new(i, :delete))
1996
+ end
1913
1997
  end
1914
- end
1915
- raise error unless error.empty?
1998
+ raise error unless error.empty?
1916
1999
 
1917
- working_template[:one] << template_disks
2000
+ working_template[:one] << template_disks
1918
2001
 
1919
- if template_copy_ref
1920
- template_moref = template_copy_ref
1921
- else
1922
- template_moref = selected[:vcenter_ref]
1923
- end
2002
+ if template_copy_ref
2003
+ template_moref = template_copy_ref
2004
+ else
2005
+ template_moref = selected[:vcenter_ref]
2006
+ end
1924
2007
 
1925
- opts_nics = {
1926
- :vi_client => @vi_client,
1927
- :vc_uuid => vc_uuid,
1928
- :npool => npool,
1929
- :hpool => hpool,
1930
- :vcenter => vcenter,
1931
- :template_moref => template_moref,
1932
- :vm_object => nil
1933
- }
2008
+ opts_nics = {
2009
+ :vi_client => @vi_client,
2010
+ :vc_uuid => vc_uuid,
2011
+ :npool => npool,
2012
+ :hpool => hpool,
2013
+ :vcenter => vcenter,
2014
+ :template_moref => template_moref,
2015
+ :vm_object => nil
2016
+ }
1934
2017
 
1935
- error, template_nics, _ar_ids, allocated_nets =
1936
- template
1937
- .import_vcenter_nics(
1938
- opts_nics,
1939
- id,
1940
- dc
1941
- )
2018
+ error, template_nics, _ar_ids, allocated_nets =
2019
+ template
2020
+ .import_vcenter_nics(
2021
+ opts_nics,
2022
+ id,
2023
+ dc
2024
+ )
1942
2025
 
1943
- if allocated_nets
1944
- # rollback stack
1945
- allocated_nets.reverse.each do |n|
1946
- @rollback.unshift(Raction.new(n, :delete))
2026
+ if allocated_nets
2027
+ # rollback stack
2028
+ allocated_nets.reverse.each do |n|
2029
+ @rollback.unshift(Raction.new(n, :delete))
2030
+ end
1947
2031
  end
1948
- end
1949
- raise error unless error.empty?
2032
+ raise error unless error.empty?
1950
2033
 
1951
- working_template[:one] << template_nics
1952
- working_template[:one] << rp_opts(
1953
- opts[:type],
1954
- opts[:resourcepool]
1955
- )
2034
+ working_template[:one] << template_nics
2035
+ working_template[:one] << rp_opts(
2036
+ opts[:type],
2037
+ opts[:resourcepool]
2038
+ )
1956
2039
 
1957
- one_object.update(working_template[:one])
2040
+ one_object.update(working_template[:one])
2041
+ end
1958
2042
  end
1959
2043
 
1960
2044
  res
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opennebula
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0.1
4
+ version: 6.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-27 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri