opennebula 6.0.3 → 6.2.1
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 +17 -6
- data/lib/models/role.rb +13 -37
- data/lib/models/service.rb +24 -15
- data/lib/opennebula/flow/service_template.rb +11 -3
- data/lib/opennebula/ldap_auth.rb +6 -2
- data/lib/opennebula/marketplaceapp_ext.rb +1 -1
- data/lib/opennebula/pool.rb +7 -5
- data/lib/opennebula/server_cipher_auth.rb +6 -3
- data/lib/opennebula/user.rb +2 -2
- data/lib/opennebula/virtual_machine.rb +42 -8
- data/lib/opennebula/virtual_machine_ext.rb +31 -2
- data/lib/opennebula/virtual_machine_pool.rb +4 -0
- data/lib/opennebula/zone.rb +40 -1
- data/lib/opennebula.rb +1 -1
- data/lib/vcenter_importer.rb +19 -7
- data/lib/virtual_machine.rb +21 -10
- data/lib/vm_template.rb +146 -59
- metadata +66 -67
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
|
@@ -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
|
-
<<
|
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(
|
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(
|
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#{
|
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
|
@@ -369,9 +379,11 @@ module VCenterDriver
|
|
369
379
|
error_msg = "\nError: #{e.message}\n"
|
370
380
|
error_msg << "#{e.backtrace}\n" \
|
371
381
|
if VCenterDriver::CONFIG[:debug_information]
|
372
|
-
|
382
|
+
STDERR.puts error_msg
|
383
|
+
raise_error = true
|
373
384
|
ensure
|
374
385
|
vi_client.close_connection if vi_client
|
386
|
+
raise if raise_error
|
375
387
|
end
|
376
388
|
end
|
377
389
|
|
data/lib/virtual_machine.rb
CHANGED
@@ -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?
|
@@ -1090,14 +1088,22 @@ end
|
|
1090
1088
|
#
|
1091
1089
|
# @return [Hash ("String" => self.Nic)] Model representation of nics
|
1092
1090
|
def info_nics
|
1091
|
+
keep_mac_on_imported = false
|
1092
|
+
keep_mac_on_imported = CONFIG[:keep_mac_on_imported] \
|
1093
|
+
unless CONFIG[:keep_mac_on_imported].nil?
|
1094
|
+
|
1093
1095
|
@nics = { :macs => {} }
|
1094
1096
|
|
1095
1097
|
vc_nics = vcenter_nics_list
|
1096
1098
|
one_nics = one_nics_get
|
1097
1099
|
|
1098
1100
|
one_nics.each do |one_nic|
|
1099
|
-
index
|
1100
|
-
|
1101
|
+
index = one_nic['NIC_ID']
|
1102
|
+
if keep_mac_on_imported && one_nic['MAC_IMPORTED']
|
1103
|
+
mac = one_nic['MAC_IMPORTED']
|
1104
|
+
else
|
1105
|
+
mac = one_nic['MAC']
|
1106
|
+
end
|
1101
1107
|
vc_dev = query_nic(mac, vc_nics)
|
1102
1108
|
|
1103
1109
|
if vc_dev
|
@@ -1975,7 +1981,7 @@ end
|
|
1975
1981
|
end
|
1976
1982
|
|
1977
1983
|
card_spec = {
|
1978
|
-
:key =>
|
1984
|
+
:key => 0,
|
1979
1985
|
:deviceInfo => {
|
1980
1986
|
:label => 'net' + card_num.to_s,
|
1981
1987
|
:summary => pg_name
|
@@ -1985,6 +1991,9 @@ end
|
|
1985
1991
|
:macAddress => mac,
|
1986
1992
|
:unitNumber => unumber
|
1987
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
|
1988
1997
|
|
1989
1998
|
if (limit || rsrv) && (limit > 0)
|
1990
1999
|
ra_spec = {}
|
@@ -2121,7 +2130,7 @@ end
|
|
2121
2130
|
end
|
2122
2131
|
|
2123
2132
|
card_spec = {
|
2124
|
-
:key =>
|
2133
|
+
:key => 0,
|
2125
2134
|
:deviceInfo => {
|
2126
2135
|
:label => 'net' + card_num.to_s,
|
2127
2136
|
:summary => pg_name
|
@@ -2129,6 +2138,9 @@ end
|
|
2129
2138
|
:backing => backing,
|
2130
2139
|
:addressType => 'generated'
|
2131
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
|
2132
2144
|
|
2133
2145
|
if (limit || rsrv) && (limit > 0)
|
2134
2146
|
ra_spec = {}
|
@@ -2419,7 +2431,7 @@ end
|
|
2419
2431
|
# automatically cleans all system snapshots
|
2420
2432
|
# https://github.com/OpenNebula/one/issues/5409
|
2421
2433
|
if snapshots? || one_snapshots?
|
2422
|
-
error_msg = 'Existing
|
2434
|
+
error_msg = 'Existing sytem snapshots, cannot change disks. '
|
2423
2435
|
error_msg << 'Please remove all snapshots and try again.'
|
2424
2436
|
raise error_message
|
2425
2437
|
end
|
@@ -2606,9 +2618,8 @@ end
|
|
2606
2618
|
return unless disk.exists?
|
2607
2619
|
|
2608
2620
|
if snapshots? || one_snapshots?
|
2609
|
-
error_message = 'Existing
|
2610
|
-
error_message << '
|
2611
|
-
error_message << 'try again.'
|
2621
|
+
error_message = 'Existing sytem snapshots, cannot change disks'
|
2622
|
+
error_message << '. Please remove all snapshots and try again.'
|
2612
2623
|
raise error_message
|
2613
2624
|
end
|
2614
2625
|
|
data/lib/vm_template.rb
CHANGED
@@ -40,7 +40,7 @@ module VCenterDriver
|
|
40
40
|
def lock
|
41
41
|
return unless @locking
|
42
42
|
|
43
|
-
@locking_file = File.open('/tmp/vcenter-importer-lock', 'w')
|
43
|
+
@locking_file = File.open('/var/tmp/vcenter-importer-lock', 'w')
|
44
44
|
@locking_file.flock(File::LOCK_EX)
|
45
45
|
end
|
46
46
|
|
@@ -50,9 +50,9 @@ module VCenterDriver
|
|
50
50
|
|
51
51
|
@locking_file.close
|
52
52
|
|
53
|
-
return unless File.exist?('/tmp/vcenter-importer-lock')
|
53
|
+
return unless File.exist?('/var/tmp/vcenter-importer-lock')
|
54
54
|
|
55
|
-
File.delete('/tmp/vcenter-importer-lock')
|
55
|
+
File.delete('/var/tmp/vcenter-importer-lock')
|
56
56
|
end
|
57
57
|
|
58
58
|
def vm?
|
@@ -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
|
@@ -733,6 +817,9 @@ module VCenterDriver
|
|
733
817
|
nic, true)
|
734
818
|
network_found.info
|
735
819
|
|
820
|
+
if nic[:mac]
|
821
|
+
nic_tmp << "MAC_IMPORTED=\"#{nic[:mac]}\",\n"
|
822
|
+
end
|
736
823
|
# This is the existing nic info
|
737
824
|
if nic[:mac] && ipv4.empty? && ipv6.empty?
|
738
825
|
nic_tmp << "MAC=\"#{nic[:mac]}\",\n"
|
@@ -1832,12 +1919,10 @@ module VCenterDriver
|
|
1832
1919
|
# the template if something go wrong
|
1833
1920
|
if copy
|
1834
1921
|
error, template_copy_ref =
|
1835
|
-
selected[:template]
|
1836
|
-
|
1837
|
-
opts[:name]
|
1838
|
-
)
|
1922
|
+
selected[:template].save_as_linked_clones(opts[:name])
|
1923
|
+
|
1839
1924
|
unless template_copy_ref
|
1840
|
-
raise 'There is a problem creating
|
1925
|
+
raise 'There is a problem creating ' \
|
1841
1926
|
"your copy: #{error}"
|
1842
1927
|
end
|
1843
1928
|
|
@@ -1890,68 +1975,70 @@ module VCenterDriver
|
|
1890
1975
|
working_template[:one] <<
|
1891
1976
|
"VCENTER_TEMPLATE_NAME=\"#{selected[:name]}\"\n"
|
1892
1977
|
|
1893
|
-
|
1894
|
-
|
1978
|
+
unless copy
|
1979
|
+
create(working_template[:one]) do |one_object, id|
|
1980
|
+
res[:id] << id
|
1895
1981
|
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
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
|
+
)
|
1905
1991
|
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1992
|
+
if allocated_images
|
1993
|
+
# rollback stack
|
1994
|
+
allocated_images.reverse.each do |i|
|
1995
|
+
@rollback.unshift(Raction.new(i, :delete))
|
1996
|
+
end
|
1910
1997
|
end
|
1911
|
-
|
1912
|
-
raise error unless error.empty?
|
1998
|
+
raise error unless error.empty?
|
1913
1999
|
|
1914
|
-
|
2000
|
+
working_template[:one] << template_disks
|
1915
2001
|
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
2002
|
+
if template_copy_ref
|
2003
|
+
template_moref = template_copy_ref
|
2004
|
+
else
|
2005
|
+
template_moref = selected[:vcenter_ref]
|
2006
|
+
end
|
1921
2007
|
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
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
|
+
}
|
1931
2017
|
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
2018
|
+
error, template_nics, _ar_ids, allocated_nets =
|
2019
|
+
template
|
2020
|
+
.import_vcenter_nics(
|
2021
|
+
opts_nics,
|
2022
|
+
id,
|
2023
|
+
dc
|
2024
|
+
)
|
1939
2025
|
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
2026
|
+
if allocated_nets
|
2027
|
+
# rollback stack
|
2028
|
+
allocated_nets.reverse.each do |n|
|
2029
|
+
@rollback.unshift(Raction.new(n, :delete))
|
2030
|
+
end
|
1944
2031
|
end
|
1945
|
-
|
1946
|
-
raise error unless error.empty?
|
2032
|
+
raise error unless error.empty?
|
1947
2033
|
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
2034
|
+
working_template[:one] << template_nics
|
2035
|
+
working_template[:one] << rp_opts(
|
2036
|
+
opts[:type],
|
2037
|
+
opts[:resourcepool]
|
2038
|
+
)
|
1953
2039
|
|
1954
|
-
|
2040
|
+
one_object.update(working_template[:one])
|
2041
|
+
end
|
1955
2042
|
end
|
1956
2043
|
|
1957
2044
|
res
|