opennebula 6.2.0 → 6.3.80.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/cloud/CloudClient.rb +1 -1
- data/lib/datacenter.rb +33 -3
- data/lib/datastore.rb +12 -5
- data/lib/file_helper.rb +1 -1
- data/lib/host.rb +3 -2
- data/lib/opennebula/flow/service_pool.rb +6 -2
- data/lib/opennebula/flow/service_template.rb +6 -0
- data/lib/opennebula/host.rb +12 -4
- data/lib/opennebula/ldap_auth.rb +3 -1
- data/lib/opennebula/marketplaceapp_ext.rb +142 -33
- data/lib/opennebula/oneflow_client.rb +12 -1
- data/lib/opennebula/user.rb +2 -2
- data/lib/opennebula/virtual_machine.rb +22 -1
- data/lib/opennebula/virtual_machine_ext.rb +31 -2
- data/lib/opennebula/virtual_machine_pool.rb +4 -0
- data/lib/opennebula.rb +1 -1
- data/lib/scripts_common.rb +5 -0
- data/lib/vcenter_importer.rb +25 -6
- data/lib/vi_helper.rb +17 -2
- data/lib/virtual_machine.rb +27 -14
- data/lib/vm_monitor.rb +4 -0
- data/lib/vm_template.rb +199 -59
- data/lib/vmm_importer.rb +10 -7
- metadata +65 -66
data/lib/vcenter_importer.rb
CHANGED
@@ -202,7 +202,7 @@ module VCenterDriver
|
|
202
202
|
# index associated to his own resource opt
|
203
203
|
#
|
204
204
|
# Example:
|
205
|
-
# {"vm-343" => {
|
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
|
-
|
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
|
@@ -276,6 +279,15 @@ module VCenterDriver
|
|
276
279
|
rs = dc_folder.get_unimported_hosts(hpool,
|
277
280
|
vcenter_instance_name)
|
278
281
|
|
282
|
+
# Select just cluster with this reference
|
283
|
+
if options[:cluster_ref]
|
284
|
+
rs.each do |_, clusters|
|
285
|
+
clusters.select! do |c|
|
286
|
+
c[:cluster_ref] == options[:cluster_ref]
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
279
291
|
STDOUT.print "done!\n\n"
|
280
292
|
|
281
293
|
rs.each do |dc, clusters|
|
@@ -312,10 +324,13 @@ module VCenterDriver
|
|
312
324
|
|
313
325
|
cluster_list_str = "\n"
|
314
326
|
cluster_list.each do |key, value|
|
327
|
+
name = VCenterDriver::VcImporter.sanitize(
|
328
|
+
value
|
329
|
+
)
|
315
330
|
cluster_list_str << " - \e[94mID: " \
|
316
331
|
<< key \
|
317
332
|
<< "\e[39m - NAME: " \
|
318
|
-
<<
|
333
|
+
<< name << "\n"
|
319
334
|
end
|
320
335
|
|
321
336
|
STDOUT.print "\n #{cluster_list_str}"
|
@@ -330,15 +345,19 @@ module VCenterDriver
|
|
330
345
|
end
|
331
346
|
end
|
332
347
|
|
348
|
+
cluster_name = VCenterDriver::VcImporter.sanitize(
|
349
|
+
cluster[:cluster_name]
|
350
|
+
)
|
351
|
+
|
333
352
|
# Check if the OpenNebula Cluster exists, and reuse it
|
334
353
|
one_cluster_id ||= cluster_list
|
335
|
-
.key(
|
354
|
+
.key(cluster_name)
|
336
355
|
|
337
356
|
if !one_cluster_id
|
338
357
|
one_cluster = VCenterDriver::VIHelper
|
339
358
|
.new_one_item(OpenNebula::Cluster)
|
340
359
|
rc = one_cluster
|
341
|
-
.allocate(
|
360
|
+
.allocate(cluster_name.to_s)
|
342
361
|
if ::OpenNebula.is_error?(rc)
|
343
362
|
# rubocop:disable Layout/LineLength
|
344
363
|
STDOUT.puts " Error creating OpenNebula cluster: #{rc.message}\n"
|
@@ -355,7 +374,7 @@ module VCenterDriver
|
|
355
374
|
rpool,
|
356
375
|
one_cluster_id)
|
357
376
|
# rubocop:disable Layout/LineLength
|
358
|
-
STDOUT.puts "\n OpenNebula host \e[92m#{
|
377
|
+
STDOUT.puts "\n OpenNebula host \e[92m#{cluster_name}\e[39m with"\
|
359
378
|
" ID \e[94m#{one_host.id}\e[39m successfully created."
|
360
379
|
STDOUT.puts
|
361
380
|
# rubocop:enable Layout/LineLength
|
data/lib/vi_helper.rb
CHANGED
@@ -97,7 +97,12 @@ module VCenterDriver
|
|
97
97
|
|
98
98
|
def self.one_item(the_class, id, exit_if_fail = true)
|
99
99
|
item = the_class.new_with_id(id, client)
|
100
|
-
rc
|
100
|
+
rc=nil
|
101
|
+
if the_class == OpenNebula::VirtualMachine
|
102
|
+
rc = item.info(true)
|
103
|
+
else
|
104
|
+
rc = item.info
|
105
|
+
end
|
101
106
|
return_if_error(rc, item, exit_if_fail)
|
102
107
|
end
|
103
108
|
|
@@ -118,6 +123,16 @@ module VCenterDriver
|
|
118
123
|
return_if_error(rc, item, exit_if_fail)
|
119
124
|
end
|
120
125
|
|
126
|
+
# Since https://github.com/OpenNebula/one/issues/5689
|
127
|
+
# there two deploy_ids allowed:
|
128
|
+
# * moref, eg: vm-567
|
129
|
+
# * moref +"_" + vcenter uuid, eg:
|
130
|
+
# 2499952a-6c85-480e-b7df-4cbd2137eb69_vm-456
|
131
|
+
# This function will always return the moref
|
132
|
+
def self.get_deploy_id(deploy_id)
|
133
|
+
deploy_id.split('_')[0]
|
134
|
+
end
|
135
|
+
|
121
136
|
def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
|
122
137
|
pool = one_pool(the_class, raise_if_fail) if pool.nil?
|
123
138
|
element = pool.find {|e| e['NAME'] == name.to_s }
|
@@ -251,7 +266,7 @@ module VCenterDriver
|
|
251
266
|
# Let's try to find the VM object only by its name
|
252
267
|
# Let's build the VM name
|
253
268
|
vm_prefix = host['TEMPLATE/VM_PREFIX']
|
254
|
-
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil?
|
269
|
+
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil?
|
255
270
|
vm_prefix.gsub!('$i', one_vm['ID'])
|
256
271
|
vm_name = vm_prefix + one_vm['NAME']
|
257
272
|
|
data/lib/virtual_machine.rb
CHANGED
@@ -103,6 +103,7 @@ end
|
|
103
103
|
|
104
104
|
def initialize(vi_client, ref, one_id)
|
105
105
|
if ref
|
106
|
+
ref = VCenterDriver::VIHelper.get_deploy_id(ref)
|
106
107
|
@item = RbVmomi::VIM::VirtualMachine.new(vi_client.vim, ref)
|
107
108
|
check_item(@item, RbVmomi::VIM::VirtualMachine)
|
108
109
|
end
|
@@ -470,7 +471,7 @@ end
|
|
470
471
|
# @return String vcenter name
|
471
472
|
def vc_name
|
472
473
|
vm_prefix = host['TEMPLATE/VM_PREFIX']
|
473
|
-
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil?
|
474
|
+
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil?
|
474
475
|
|
475
476
|
if !one_item['USER_TEMPLATE/VM_PREFIX'].nil?
|
476
477
|
vm_prefix = one_item['USER_TEMPLATE/VM_PREFIX']
|
@@ -579,8 +580,6 @@ end
|
|
579
580
|
end
|
580
581
|
end
|
581
582
|
|
582
|
-
dc = cluster.datacenter
|
583
|
-
|
584
583
|
vcenter_vm_folder = drv_action['USER_TEMPLATE/VCENTER_VM_FOLDER']
|
585
584
|
|
586
585
|
if !vcenter_vm_folder.nil? && !vcenter_vm_folder.empty?
|
@@ -1715,8 +1714,13 @@ end
|
|
1715
1714
|
def sync(deploy = {})
|
1716
1715
|
extraconfig = []
|
1717
1716
|
device_change = []
|
1717
|
+
sync_opt = nil
|
1718
|
+
|
1719
|
+
# Disk are only synced with :all option when VM is first created
|
1720
|
+
# NOTE: Detach actions are implemented through TM (not sync)
|
1721
|
+
sync_opt = :all if deploy[:new] == true
|
1718
1722
|
|
1719
|
-
disks = sync_disks(
|
1723
|
+
disks = sync_disks(sync_opt, false)
|
1720
1724
|
resize_unmanaged_disks
|
1721
1725
|
|
1722
1726
|
if deploy[:boot] && !deploy[:boot].empty?
|
@@ -1780,6 +1784,8 @@ end
|
|
1780
1784
|
end
|
1781
1785
|
|
1782
1786
|
def extraconfig_context
|
1787
|
+
one_item.info(true)
|
1788
|
+
|
1783
1789
|
context_text = "# Context variables generated by OpenNebula\n"
|
1784
1790
|
one_item.each('TEMPLATE/CONTEXT/*') do |context_element|
|
1785
1791
|
# next if !context_element.text
|
@@ -1983,7 +1989,7 @@ end
|
|
1983
1989
|
end
|
1984
1990
|
|
1985
1991
|
card_spec = {
|
1986
|
-
:key =>
|
1992
|
+
:key => 0,
|
1987
1993
|
:deviceInfo => {
|
1988
1994
|
:label => 'net' + card_num.to_s,
|
1989
1995
|
:summary => pg_name
|
@@ -1993,6 +1999,9 @@ end
|
|
1993
1999
|
:macAddress => mac,
|
1994
2000
|
:unitNumber => unumber
|
1995
2001
|
}
|
2002
|
+
if @vi_client.vim.serviceContent.about.apiVersion.to_f >= 7.0
|
2003
|
+
card_spec[:key] = Time.now.utc.strftime('%m%d%M%S%L').to_i
|
2004
|
+
end
|
1996
2005
|
|
1997
2006
|
if (limit || rsrv) && (limit > 0)
|
1998
2007
|
ra_spec = {}
|
@@ -2129,7 +2138,7 @@ end
|
|
2129
2138
|
end
|
2130
2139
|
|
2131
2140
|
card_spec = {
|
2132
|
-
:key =>
|
2141
|
+
:key => 0,
|
2133
2142
|
:deviceInfo => {
|
2134
2143
|
:label => 'net' + card_num.to_s,
|
2135
2144
|
:summary => pg_name
|
@@ -2137,6 +2146,9 @@ end
|
|
2137
2146
|
:backing => backing,
|
2138
2147
|
:addressType => 'generated'
|
2139
2148
|
}
|
2149
|
+
if @vi_client.vim.serviceContent.about.apiVersion.to_f >= 7.0
|
2150
|
+
card_spec[:key] = Time.now.utc.strftime('%m%d%M%S%L').to_i
|
2151
|
+
end
|
2140
2152
|
|
2141
2153
|
if (limit || rsrv) && (limit > 0)
|
2142
2154
|
ra_spec = {}
|
@@ -2302,6 +2314,7 @@ end
|
|
2302
2314
|
detach_disk_array = []
|
2303
2315
|
extra_config = []
|
2304
2316
|
keys = disk_keys.invert
|
2317
|
+
|
2305
2318
|
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
|
2306
2319
|
disks_each(:detached?) do |d|
|
2307
2320
|
key = d.key.to_s
|
@@ -2377,8 +2390,7 @@ end
|
|
2377
2390
|
# @param option [symbol] if :all is provided the
|
2378
2391
|
# method will try to sync
|
2379
2392
|
# all the disks (detached and not existing ones)
|
2380
|
-
#
|
2381
|
-
# the disks that are not existing
|
2393
|
+
# otherwise it will only sync the disks that are not existing
|
2382
2394
|
#
|
2383
2395
|
# @param execute [boolean] indicates if the reconfigure operation
|
2384
2396
|
# is going to
|
@@ -2428,8 +2440,8 @@ end
|
|
2428
2440
|
# https://github.com/OpenNebula/one/issues/5409
|
2429
2441
|
if snapshots? || one_snapshots?
|
2430
2442
|
error_msg = 'Existing sytem snapshots, cannot change disks. '
|
2431
|
-
error_msg << 'Please remove all snapshots and try again
|
2432
|
-
raise
|
2443
|
+
error_msg << 'Please remove all snapshots and try again'
|
2444
|
+
raise error_msg
|
2433
2445
|
end
|
2434
2446
|
|
2435
2447
|
spec_hash = {}
|
@@ -2615,7 +2627,7 @@ end
|
|
2615
2627
|
|
2616
2628
|
if snapshots? || one_snapshots?
|
2617
2629
|
error_message = 'Existing sytem snapshots, cannot change disks'
|
2618
|
-
error_message << '. Please remove all snapshots and try again
|
2630
|
+
error_message << '. Please remove all snapshots and try again'
|
2619
2631
|
raise error_message
|
2620
2632
|
end
|
2621
2633
|
|
@@ -3066,10 +3078,10 @@ end
|
|
3066
3078
|
@item.ReconfigVM_Task(:spec => vm_config_spec).wait_for_completion
|
3067
3079
|
|
3068
3080
|
devices.each do |device|
|
3069
|
-
|
3081
|
+
valid_device =
|
3082
|
+
device.class == RbVmomi::VIM::VirtualLsiLogicController &&
|
3070
3083
|
device.key == scsi_key
|
3071
|
-
|
3072
|
-
controller = device.deviceInfo.label
|
3084
|
+
controller = device.deviceInfo.label if valid_device
|
3073
3085
|
end
|
3074
3086
|
|
3075
3087
|
controller
|
@@ -3426,6 +3438,7 @@ end
|
|
3426
3438
|
config[:esx_migration_list] = 'Selected_by_DRS'
|
3427
3439
|
end
|
3428
3440
|
|
3441
|
+
vc_vm.reference_all_disks
|
3429
3442
|
vc_vm.migrate(config)
|
3430
3443
|
|
3431
3444
|
vm.replace({ 'VCENTER_CCR_REF' => ccr_ref })
|
data/lib/vm_monitor.rb
CHANGED
@@ -275,6 +275,10 @@ module VirtualMachineMonitor
|
|
275
275
|
info_disks.each do |disk|
|
276
276
|
next if disk[1].no_exists?
|
277
277
|
|
278
|
+
# disk[0] contains the disk ID in OpenNebula or the disk path if
|
279
|
+
# there is no corresponding OpenNebula disk
|
280
|
+
# disk[1] contains the vcenter resource corresponding to the VM disk
|
281
|
+
|
278
282
|
# Delete special characters
|
279
283
|
name = disk[0].gsub(/[^0-9A-Za-z]/, '_')
|
280
284
|
|
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
|
@@ -324,13 +408,25 @@ module VCenterDriver
|
|
324
408
|
break
|
325
409
|
end
|
326
410
|
|
411
|
+
# Read configuration for imported images, taking
|
412
|
+
# into account if we are importing a VM Tempalte
|
413
|
+
# or a Wild VM
|
414
|
+
image_persistency = nil
|
415
|
+
if vm?
|
416
|
+
image_persistency = :wild_vm_persistent_images
|
417
|
+
else
|
418
|
+
image_persistency = :vm_template_persistent_images
|
419
|
+
end
|
420
|
+
|
421
|
+
image_persistency = VCenterDriver::CONFIG[image_persistency]
|
422
|
+
|
327
423
|
params = {
|
328
424
|
:disk => disk,
|
329
425
|
:ipool => ipool,
|
330
426
|
:_type => type,
|
331
427
|
:ds_id => datastore_found['ID'],
|
332
428
|
:opts => {
|
333
|
-
:persistent =>
|
429
|
+
:persistent => image_persistency ? 'YES':'NO'
|
334
430
|
},
|
335
431
|
:images => images
|
336
432
|
}
|
@@ -539,6 +635,23 @@ module VCenterDriver
|
|
539
635
|
|
540
636
|
network.info
|
541
637
|
|
638
|
+
if nic[:ipv4] || nic[:ipv6]
|
639
|
+
ar_array = network.to_hash['VNET']['AR_POOL']['AR']
|
640
|
+
ar_array = [ar_array] if ar_array.is_a?(Hash)
|
641
|
+
|
642
|
+
ipv4, _ipv6, _arid = find_ip_in_ar(
|
643
|
+
IPAddr.new(nic[:ipv4]),
|
644
|
+
ar_array
|
645
|
+
) if ar_array && nic[:ipv4]
|
646
|
+
|
647
|
+
_ipv4, ipv6, _arid = find_ip_in_ar(
|
648
|
+
IPAddr.new(nic[:ipv6]),
|
649
|
+
ar_array
|
650
|
+
) if ar_array && nic[:ipv6]
|
651
|
+
|
652
|
+
return [ipv4, ipv6]
|
653
|
+
end
|
654
|
+
|
542
655
|
# Iterate over Retrieve vCenter VM NICs
|
543
656
|
unless vm_object.item.guest.net.empty?
|
544
657
|
vm_object.item.guest.net.each do |net|
|
@@ -671,9 +784,10 @@ module VCenterDriver
|
|
671
784
|
nic_tmp = "NIC=[\n"
|
672
785
|
nic_tmp << "NETWORK_ID=\"#{one_vn.id}\",\n"
|
673
786
|
nic_tmp << "NAME =\"VC_NIC#{nic_index}\",\n"
|
787
|
+
nic_tmp << "IP = \"#{nic[:ipv4]}\",\n" if nic[:ipv4]
|
674
788
|
|
675
789
|
if vm?
|
676
|
-
if nic[:mac]
|
790
|
+
if nic[:mac] && !nic[:ipv4]
|
677
791
|
nic_tmp << "MAC=\"#{nic[:mac]}\",\n"
|
678
792
|
end
|
679
793
|
if nic[:ipv4_additionals]
|
@@ -729,6 +843,7 @@ module VCenterDriver
|
|
729
843
|
ar_tmp = create_ar(nic)
|
730
844
|
network_found.add_ar(ar_tmp)
|
731
845
|
end
|
846
|
+
|
732
847
|
ipv4, ipv6 = find_ips_in_network(network_found, vm_object,
|
733
848
|
nic, true)
|
734
849
|
network_found.info
|
@@ -740,8 +855,10 @@ module VCenterDriver
|
|
740
855
|
if nic[:mac] && ipv4.empty? && ipv6.empty?
|
741
856
|
nic_tmp << "MAC=\"#{nic[:mac]}\",\n"
|
742
857
|
end
|
858
|
+
|
743
859
|
nic_tmp << "IP=\"#{ipv4}\"," unless ipv4.empty?
|
744
860
|
nic_tmp << "IP6=\"#{ipv6}\"," unless ipv6.empty?
|
861
|
+
|
745
862
|
if nic[:ipv4_additionals]
|
746
863
|
nic_tmp <<
|
747
864
|
'VCENTER_ADDITIONALS_IP4'\
|
@@ -969,7 +1086,13 @@ module VCenterDriver
|
|
969
1086
|
ar_tmp << "]\n"
|
970
1087
|
|
971
1088
|
if vm?
|
972
|
-
ar_tmp << create_ar(nic,
|
1089
|
+
ar_tmp << create_ar(nic, false, nic[:ipv4]) if nic[:ipv4]
|
1090
|
+
|
1091
|
+
if nic[:ipv6]
|
1092
|
+
ar_tmp << create_ar(nic, false, nil, nic[:ipv6])
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
ar_tmp << create_ar(nic, true) if !nic[:ipv4] && !nic[:ipv6]
|
973
1096
|
end
|
974
1097
|
|
975
1098
|
one_vnet[:one] << ar_tmp
|
@@ -1024,6 +1147,23 @@ module VCenterDriver
|
|
1024
1147
|
nic_index = 0
|
1025
1148
|
|
1026
1149
|
vc_nics.each do |nic|
|
1150
|
+
[:ipv4, :ipv6].each do |type|
|
1151
|
+
if nic[type]
|
1152
|
+
opts[type].shift if opts[type]
|
1153
|
+
next
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
begin
|
1157
|
+
ip = opts[type].shift if opts[type]
|
1158
|
+
|
1159
|
+
# Check if it is a valid IP
|
1160
|
+
IPAddr.new(ip)
|
1161
|
+
|
1162
|
+
nic[type] = ip
|
1163
|
+
rescue StandardError
|
1164
|
+
end
|
1165
|
+
end
|
1166
|
+
|
1027
1167
|
# Check if the network already exists
|
1028
1168
|
network_found =
|
1029
1169
|
VCenterDriver::VIHelper
|
@@ -1835,12 +1975,10 @@ module VCenterDriver
|
|
1835
1975
|
# the template if something go wrong
|
1836
1976
|
if copy
|
1837
1977
|
error, template_copy_ref =
|
1838
|
-
selected[:template]
|
1839
|
-
|
1840
|
-
opts[:name]
|
1841
|
-
)
|
1978
|
+
selected[:template].save_as_linked_clones(opts[:name])
|
1979
|
+
|
1842
1980
|
unless template_copy_ref
|
1843
|
-
raise 'There is a problem creating
|
1981
|
+
raise 'There is a problem creating ' \
|
1844
1982
|
"your copy: #{error}"
|
1845
1983
|
end
|
1846
1984
|
|
@@ -1893,68 +2031,70 @@ module VCenterDriver
|
|
1893
2031
|
working_template[:one] <<
|
1894
2032
|
"VCENTER_TEMPLATE_NAME=\"#{selected[:name]}\"\n"
|
1895
2033
|
|
1896
|
-
|
1897
|
-
|
2034
|
+
unless copy
|
2035
|
+
create(working_template[:one]) do |one_object, id|
|
2036
|
+
res[:id] << id
|
1898
2037
|
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
2038
|
+
type = { :object => 'template', :id => id }
|
2039
|
+
error, template_disks, allocated_images =
|
2040
|
+
template
|
2041
|
+
.import_vcenter_disks(
|
2042
|
+
vc_uuid,
|
2043
|
+
dpool,
|
2044
|
+
ipool,
|
2045
|
+
type
|
2046
|
+
)
|
1908
2047
|
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
2048
|
+
if allocated_images
|
2049
|
+
# rollback stack
|
2050
|
+
allocated_images.reverse.each do |i|
|
2051
|
+
@rollback.unshift(Raction.new(i, :delete))
|
2052
|
+
end
|
1913
2053
|
end
|
1914
|
-
|
1915
|
-
raise error unless error.empty?
|
2054
|
+
raise error unless error.empty?
|
1916
2055
|
|
1917
|
-
|
2056
|
+
working_template[:one] << template_disks
|
1918
2057
|
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
2058
|
+
if template_copy_ref
|
2059
|
+
template_moref = template_copy_ref
|
2060
|
+
else
|
2061
|
+
template_moref = selected[:vcenter_ref]
|
2062
|
+
end
|
1924
2063
|
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
2064
|
+
opts_nics = {
|
2065
|
+
:vi_client => @vi_client,
|
2066
|
+
:vc_uuid => vc_uuid,
|
2067
|
+
:npool => npool,
|
2068
|
+
:hpool => hpool,
|
2069
|
+
:vcenter => vcenter,
|
2070
|
+
:template_moref => template_moref,
|
2071
|
+
:vm_object => nil
|
2072
|
+
}
|
1934
2073
|
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
2074
|
+
error, template_nics, _ar_ids, allocated_nets =
|
2075
|
+
template
|
2076
|
+
.import_vcenter_nics(
|
2077
|
+
opts_nics,
|
2078
|
+
id,
|
2079
|
+
dc
|
2080
|
+
)
|
1942
2081
|
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
2082
|
+
if allocated_nets
|
2083
|
+
# rollback stack
|
2084
|
+
allocated_nets.reverse.each do |n|
|
2085
|
+
@rollback.unshift(Raction.new(n, :delete))
|
2086
|
+
end
|
1947
2087
|
end
|
1948
|
-
|
1949
|
-
raise error unless error.empty?
|
2088
|
+
raise error unless error.empty?
|
1950
2089
|
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
2090
|
+
working_template[:one] << template_nics
|
2091
|
+
working_template[:one] << rp_opts(
|
2092
|
+
opts[:type],
|
2093
|
+
opts[:resourcepool]
|
2094
|
+
)
|
1956
2095
|
|
1957
|
-
|
2096
|
+
one_object.update(working_template[:one])
|
2097
|
+
end
|
1958
2098
|
end
|
1959
2099
|
|
1960
2100
|
res
|
data/lib/vmm_importer.rb
CHANGED
@@ -46,7 +46,8 @@ module VCenterDriver
|
|
46
46
|
vm_ref = selected['DEPLOY_ID'] || selected[:wild]['DEPLOY_ID']
|
47
47
|
vm = selected[:one_item] || build
|
48
48
|
template = selected[:template] || import_tmplt
|
49
|
-
|
49
|
+
template = "DEPLOY_ID = #{vm_ref}\n" + template
|
50
|
+
host_id = selected[:host] || @list.keys[0]
|
50
51
|
|
51
52
|
vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid
|
52
53
|
vc_name = @vi_client.vim.host
|
@@ -72,13 +73,15 @@ module VCenterDriver
|
|
72
73
|
template << template_disks
|
73
74
|
|
74
75
|
opts = {
|
75
|
-
:vi_client
|
76
|
-
:vc_uuid
|
77
|
-
:npool
|
78
|
-
:hpool
|
79
|
-
:vcenter
|
76
|
+
:vi_client => @vi_client,
|
77
|
+
:vc_uuid => vc_uuid,
|
78
|
+
:npool => npool,
|
79
|
+
:hpool => hpool,
|
80
|
+
:vcenter => vc_name,
|
80
81
|
:template_moref => vm_ref,
|
81
|
-
:vm_object
|
82
|
+
:vm_object => vc_vm,
|
83
|
+
:ipv4 => selected[:ipv4],
|
84
|
+
:ipv6 => selected[:ipv6]
|
82
85
|
}
|
83
86
|
|
84
87
|
# Create images or get nics information for template
|