opennebula 6.1.90.pre → 6.2.2
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 +5 -5
- data/lib/cloud/CloudClient.rb +1 -1
- data/lib/datacenter.rb +33 -3
- data/lib/datastore.rb +11 -4
- 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 +141 -33
- data/lib/opennebula/oneflow_client.rb +12 -1
- data/lib/opennebula/user.rb +2 -2
- 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 +11 -1
- data/lib/virtual_machine.rb +23 -12
- data/lib/vm_template.rb +186 -58
- data/lib/vmm_importer.rb +10 -7
- metadata +65 -66
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9492453d246b5d413a5902766bda7526160e953c1e6072d242509ebff8df73bc
|
|
4
|
+
data.tar.gz: eb349b7f7f2a87b29cbbae06ec35db4131db8baf96e5cbf4cf9875f3815e2db3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 546bd3075e73b2e73be4abe53dad5af5d27956dbb896182fd828a2794b510b5df71ea615915b82abbba506ff824f31091fb54afee8d8e67b3b50092714a15ffb
|
|
7
|
+
data.tar.gz: 6476073b7b334c8e746350760a0de9082770f45df57ee3c9db318b72ee9f1c72c86f8626d892e313c4d92387920e367a063878ac24237b017b66fecb7dc3d7fb
|
data/lib/cloud/CloudClient.rb
CHANGED
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 =
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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)
|
data/lib/host.rb
CHANGED
|
@@ -712,7 +712,7 @@ module VCenterDriver
|
|
|
712
712
|
|
|
713
713
|
# Only take care of VMs, not templates
|
|
714
714
|
if !hashed_properties['config.template']
|
|
715
|
-
vms[r.obj._ref] = hashed_properties
|
|
715
|
+
vms[r.obj._ref + '_' + vc_uuid] = hashed_properties
|
|
716
716
|
vm_objects << r.obj
|
|
717
717
|
end
|
|
718
718
|
end
|
|
@@ -802,7 +802,8 @@ module VCenterDriver
|
|
|
802
802
|
found_vm =
|
|
803
803
|
host_vms
|
|
804
804
|
.select do |vm|
|
|
805
|
-
vm['DEPLOY_ID']
|
|
805
|
+
vm['DEPLOY_ID'] == vm_ref ||
|
|
806
|
+
vm['DEPLOY_ID'] == VIHelper.get_deploy_id(vm_ref)
|
|
806
807
|
end.first
|
|
807
808
|
id = found_vm['ID'] if found_vm
|
|
808
809
|
|
|
@@ -55,8 +55,12 @@ module OpenNebula
|
|
|
55
55
|
@one_pool = nil
|
|
56
56
|
|
|
57
57
|
if @client
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
rc = @client.call('user.info', -1)
|
|
59
|
+
|
|
60
|
+
unless OpenNebula.is_error?(rc)
|
|
61
|
+
info = Nokogiri::XML(rc)
|
|
62
|
+
@user_id = Integer(info.xpath('/USER/ID').text)
|
|
63
|
+
end
|
|
60
64
|
end
|
|
61
65
|
|
|
62
66
|
super('DOCUMENT_POOL', 'DOCUMENT', @client)
|
|
@@ -315,6 +315,12 @@ module OpenNebula
|
|
|
315
315
|
end
|
|
316
316
|
else
|
|
317
317
|
IMMUTABLE_ATTRS.each do |attr|
|
|
318
|
+
# Allows updating the template without
|
|
319
|
+
# specifying the immutable attributes
|
|
320
|
+
if template[attr].nil?
|
|
321
|
+
template[attr] = @body[attr]
|
|
322
|
+
end
|
|
323
|
+
|
|
318
324
|
next if template[attr] == @body[attr]
|
|
319
325
|
|
|
320
326
|
return [false, "service_template/#{attr}"]
|
data/lib/opennebula/host.rb
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
# limitations under the License. #
|
|
15
15
|
#--------------------------------------------------------------------------- #
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
require 'opennebula/pool_element'
|
|
19
18
|
require 'base64'
|
|
20
19
|
require 'yaml'
|
|
@@ -217,10 +216,12 @@ module OpenNebula
|
|
|
217
216
|
# Imports a wild VM from the host and puts it in running state
|
|
218
217
|
#
|
|
219
218
|
# @param name [String] Name of the VM to import
|
|
219
|
+
# @param ipv4 [Array] Array with IP4s to set
|
|
220
|
+
# @param ipv6 [Array] Array with IP6s to set
|
|
220
221
|
#
|
|
221
222
|
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
|
222
223
|
# otherwise
|
|
223
|
-
def import_wild(name)
|
|
224
|
+
def import_wild(name, ipv4 = nil, ipv6 = nil)
|
|
224
225
|
vms = importable_wilds.select {|vm| vm['VM_NAME'] == name }
|
|
225
226
|
|
|
226
227
|
if vms.length == 0
|
|
@@ -247,8 +248,15 @@ module OpenNebula
|
|
|
247
248
|
vi_client = VCenterDriver::VIClient.new_from_host(self["ID"])
|
|
248
249
|
importer = VCenterDriver::VmmImporter.new(@client, vi_client)
|
|
249
250
|
|
|
250
|
-
return importer.import(
|
|
251
|
-
|
|
251
|
+
return importer.import(
|
|
252
|
+
{ :wild => wild,
|
|
253
|
+
:template => template,
|
|
254
|
+
:one_item => vm,
|
|
255
|
+
:host => self['ID'],
|
|
256
|
+
:ipv4 => ipv4,
|
|
257
|
+
:ipv6 => ipv6
|
|
258
|
+
}
|
|
259
|
+
)
|
|
252
260
|
else
|
|
253
261
|
rc = vm.allocate(template)
|
|
254
262
|
|
data/lib/opennebula/ldap_auth.rb
CHANGED
|
@@ -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
|
|
|
@@ -185,9 +185,22 @@ module OpenNebula::MarketPlaceAppExt
|
|
|
185
185
|
#---------------------------------------------------------------
|
|
186
186
|
# Created an associated VMTemplate if needed
|
|
187
187
|
#---------------------------------------------------------------
|
|
188
|
-
if
|
|
189
|
-
options[:
|
|
190
|
-
options
|
|
188
|
+
if is_vcenter &&
|
|
189
|
+
(!options[:template] || options[:template] == -1)
|
|
190
|
+
tmpl = create_vcenter_template(ds, options, image)
|
|
191
|
+
|
|
192
|
+
if OpenNebula.is_error?(tmpl)
|
|
193
|
+
rc_info[:vmtemplate] = [tmpl]
|
|
194
|
+
else
|
|
195
|
+
rc_info[:vmtemplate] = [tmpl.id]
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
return rc_info
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
if self['TEMPLATE/VMTEMPLATE64'].nil? ||
|
|
202
|
+
options[:notemplate] ||
|
|
203
|
+
options[:template] == -1
|
|
191
204
|
return rc_info
|
|
192
205
|
end
|
|
193
206
|
|
|
@@ -286,33 +299,128 @@ module OpenNebula::MarketPlaceAppExt
|
|
|
286
299
|
rc
|
|
287
300
|
end
|
|
288
301
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
302
|
+
# Create a VM template in vCenter in order to use it when
|
|
303
|
+
# deploying an app from the marketplace
|
|
304
|
+
#
|
|
305
|
+
# @param ds [OpenNebula::Datastore] Datastore information
|
|
306
|
+
# @param options [Hash] Export options
|
|
307
|
+
# @param image [OpenNebula::Image] Image information
|
|
308
|
+
def create_vcenter_template(ds, options, image = nil)
|
|
309
|
+
ret = {}
|
|
310
|
+
keys = %w[VCENTER_TEMPLATE_REF
|
|
311
|
+
VCENTER_CCR_REF
|
|
312
|
+
VCENTER_INSTANCE_ID]
|
|
313
|
+
|
|
314
|
+
if ds['//VCENTER_TEMPLATE_REF']
|
|
315
|
+
keys.each do |key|
|
|
316
|
+
ret[key] = ds["//#{key}"]
|
|
317
|
+
end
|
|
318
|
+
else
|
|
319
|
+
require 'vcenter_driver'
|
|
292
320
|
|
|
293
|
-
|
|
294
|
-
|
|
321
|
+
# Get vi client for current datastore
|
|
322
|
+
vi_client = VCenterDriver::VIClient.new_from_datastore(
|
|
323
|
+
ds.id
|
|
324
|
+
)
|
|
295
325
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
326
|
+
# Get datastore object
|
|
327
|
+
ds_ref = ds['//VCENTER_DS_REF']
|
|
328
|
+
datastore = VCenterDriver::Datastore.new_from_ref(
|
|
329
|
+
ds_ref,
|
|
330
|
+
vi_client
|
|
331
|
+
)
|
|
299
332
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
333
|
+
# Get resource pool
|
|
334
|
+
host_ref = datastore['host'].first.key.parent._ref
|
|
335
|
+
vi_client.ccr_ref = host_ref
|
|
336
|
+
|
|
337
|
+
host = VCenterDriver::ClusterComputeResource.new_from_ref(
|
|
338
|
+
host_ref,
|
|
339
|
+
vi_client
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
rp = host.resource_pools.first
|
|
343
|
+
|
|
344
|
+
# Get vCentrer instance ID
|
|
345
|
+
uuid = vi_client.vim.serviceContent.about.instanceUuid
|
|
346
|
+
|
|
347
|
+
# Create VM folder it not exists
|
|
348
|
+
dc = datastore.obtain_dc.item
|
|
349
|
+
vm_folder = dc.find_folder('one_default_template')
|
|
350
|
+
|
|
351
|
+
if vm_folder.nil?
|
|
352
|
+
dc.vmFolder.CreateFolder(
|
|
353
|
+
:name => 'one_default_template'
|
|
354
|
+
)
|
|
355
|
+
vm_folder = dc.find_folder('one_default_template')
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# Define default VM config
|
|
359
|
+
vm_cfg = { :name => "one_app_template-#{ds.id}",
|
|
360
|
+
:guestId => 'otherGuest',
|
|
361
|
+
:numCPUs => 1,
|
|
362
|
+
:memoryMB => 128,
|
|
363
|
+
:files => {
|
|
364
|
+
:vmPathName => "[#{datastore.item.name}]"
|
|
365
|
+
} }
|
|
366
|
+
|
|
367
|
+
# Create the VM
|
|
368
|
+
vm = vm_folder.CreateVM_Task(
|
|
369
|
+
:config => vm_cfg,
|
|
370
|
+
:pool => rp
|
|
371
|
+
).wait_for_completion
|
|
372
|
+
|
|
373
|
+
# Create the VM template
|
|
374
|
+
vm.MarkAsTemplate
|
|
375
|
+
|
|
376
|
+
ret['VCENTER_TEMPLATE_REF'] = vm._ref
|
|
377
|
+
ret['VCENTER_CCR_REF'] = host_ref
|
|
378
|
+
ret['VCENTER_INSTANCE_ID'] = uuid
|
|
379
|
+
|
|
380
|
+
ret.each do |key, value|
|
|
381
|
+
ds.update("#{key}=\"#{value}\"", true)
|
|
308
382
|
end
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
tmpl = <<-EOT
|
|
386
|
+
NAME = "#{options[:vmtemplate_name] || options[:name]}"
|
|
387
|
+
CPU = "1"
|
|
388
|
+
VCPU = "1"
|
|
389
|
+
MEMORY = "128"
|
|
390
|
+
HYPERVISOR = "vcenter"
|
|
391
|
+
EOT
|
|
392
|
+
|
|
393
|
+
tmpl << "DISK = [ IMAGE_ID = \"#{image.id}\" ]" if image
|
|
394
|
+
|
|
395
|
+
ret.each do |key, value|
|
|
396
|
+
tmpl << "#{key}=\"#{value}\"\n"
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
vmtpl = Template.new(Template.build_xml, @client)
|
|
400
|
+
|
|
401
|
+
rc = vmtpl.allocate(tmpl)
|
|
402
|
+
|
|
403
|
+
if OpenNebula.is_error?(rc)
|
|
404
|
+
rc
|
|
309
405
|
else
|
|
310
|
-
|
|
311
|
-
' Please use the --template file to define' \
|
|
312
|
-
' a VM Template ID if needed.'
|
|
406
|
+
Template.new_with_id(vmtpl.id, @client)
|
|
313
407
|
end
|
|
314
408
|
end
|
|
315
409
|
|
|
410
|
+
def update_options_with_template(options)
|
|
411
|
+
path = "#{VAR_LOCATION}/remotes/etc/vmm/vcenter/vcenterrc"
|
|
412
|
+
|
|
413
|
+
return options unless File.file?(path)
|
|
414
|
+
|
|
415
|
+
config = YAML.load_file(path)
|
|
416
|
+
|
|
417
|
+
return options unless config.key?(:default_template)
|
|
418
|
+
|
|
419
|
+
options[:template] = config[:default_template]
|
|
420
|
+
|
|
421
|
+
options
|
|
422
|
+
end
|
|
423
|
+
|
|
316
424
|
# Creates a VM template based on the APPTEMPLATE64 attribute
|
|
317
425
|
# @param [Hash] options
|
|
318
426
|
# :export_name [String] name of the vm template
|
|
@@ -334,19 +442,19 @@ module OpenNebula::MarketPlaceAppExt
|
|
|
334
442
|
options = update_options_with_template(options)
|
|
335
443
|
end
|
|
336
444
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
445
|
+
if !options[:template] || options[:template] == -1
|
|
446
|
+
vmtpl = create_vcenter_template(ds, options)
|
|
447
|
+
else
|
|
448
|
+
template_id = options[:template]
|
|
449
|
+
template = Template.new_with_id(template_id, @client)
|
|
342
450
|
|
|
343
|
-
|
|
451
|
+
vmtpl_id = template.clone(
|
|
452
|
+
options[:vmtemplate_name] || options[:name]
|
|
453
|
+
)
|
|
344
454
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
)
|
|
455
|
+
vmtpl = Template.new_with_id(vmtpl_id, @client)
|
|
456
|
+
end
|
|
348
457
|
|
|
349
|
-
vmtpl = Template.new_with_id(vmtpl_id, @client)
|
|
350
458
|
rc = vmtpl.info
|
|
351
459
|
else
|
|
352
460
|
# ----------------------------------------------------------
|
|
@@ -461,7 +569,7 @@ module OpenNebula::MarketPlaceAppExt
|
|
|
461
569
|
def export_recursive(xpath, options)
|
|
462
570
|
# Get marketplace apps pool to find roles apps
|
|
463
571
|
pool = OpenNebula::MarketPlaceAppPool.new(@client)
|
|
464
|
-
rc = pool.
|
|
572
|
+
rc = pool.info_all
|
|
465
573
|
|
|
466
574
|
return rc if OpenNebula.is_error?(rc)
|
|
467
575
|
|
|
@@ -319,10 +319,21 @@ module Service
|
|
|
319
319
|
|
|
320
320
|
class Client
|
|
321
321
|
def initialize(opts={})
|
|
322
|
+
endpoint = '/.one/oneflow_endpoint'
|
|
322
323
|
@username = opts[:username] || ENV['ONEFLOW_USER']
|
|
323
324
|
@password = opts[:password] || ENV['ONEFLOW_PASSWORD']
|
|
324
325
|
|
|
325
|
-
|
|
326
|
+
if opts[:url]
|
|
327
|
+
url = opts[:url]
|
|
328
|
+
elsif ENV['ONEFLOW_URL']
|
|
329
|
+
url = ENV['ONEFLOW_URL']
|
|
330
|
+
elsif ENV['HOME'] && File.exists?(ENV['HOME'] + endpoint)
|
|
331
|
+
url = File.read(ENV['HOME'] + endpoint).strip
|
|
332
|
+
elsif File.exists?('/var/lib/one/.one/oneflow_endpoint')
|
|
333
|
+
url = File.read('/var/lib/one/.one/oneflow_endpoint').strip
|
|
334
|
+
else
|
|
335
|
+
url = 'http://localhost:2474'
|
|
336
|
+
end
|
|
326
337
|
|
|
327
338
|
if @username.nil? && @password.nil?
|
|
328
339
|
if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"])
|
data/lib/opennebula/user.rb
CHANGED
|
@@ -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 |
|
|
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
|
|
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
data/lib/scripts_common.rb
CHANGED
|
@@ -28,6 +28,11 @@ module OpenNebula
|
|
|
28
28
|
log_function("INFO", message)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
# Logs an info message
|
|
32
|
+
def self.log_warning(message)
|
|
33
|
+
log_function('WARNING', message)
|
|
34
|
+
end
|
|
35
|
+
|
|
31
36
|
# Logs an error message
|
|
32
37
|
def self.log_error(message)
|
|
33
38
|
log_function("ERROR", message)
|
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
|