opennebula 5.13.80.pre → 6.0.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 +4 -4
- data/lib/cloud/CloudClient.rb +1 -1
- data/lib/datacenter.rb +8 -9
- data/lib/datastore.rb +2 -2
- data/lib/network.rb +68 -4
- data/lib/opennebula.rb +1 -1
- data/lib/opennebula/client.rb +9 -1
- data/lib/opennebula/flow/service_template.rb +37 -1
- data/lib/opennebula/image.rb +2 -0
- data/lib/opennebula/marketplaceapp_ext.rb +77 -13
- data/lib/opennebula/pool.rb +2 -0
- data/lib/opennebula/template_ext.rb +19 -2
- data/lib/opennebula/virtual_machine.rb +2 -0
- data/lib/opennebula/virtual_machine_ext.rb +1 -1
- data/lib/opennebula/wait_ext.rb +120 -85
- data/lib/scripts_common.rb +3 -0
- data/lib/vi_helper.rb +2 -1
- data/lib/virtual_machine.rb +3 -3
- data/lib/vm_template.rb +15 -13
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f663dcec1594a07beb54bc3a4065b53818669846
|
4
|
+
data.tar.gz: 63d9ffe94c43fb81d6cc7e2a0563ed6d711ebc48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 905fbdea52975558d07f8720c64c5f37365672d487a1bb334c94e0e4ea5026be94468c3320b667c2d7acc6f31f312e0e58b951cbf136bf45ebfc1d4efaa7e857
|
7
|
+
data.tar.gz: ddb7dadb1c1d2df3454b11a4c7f91385049ee2b134de1d75c0c27b7e59b554b2f9db5ca6135e85a9d0e8ff3b0e0565f3f4e34dd121830c151a1f468347187ad6
|
data/lib/cloud/CloudClient.rb
CHANGED
data/lib/datacenter.rb
CHANGED
@@ -576,15 +576,14 @@ module VCenterDriver
|
|
576
576
|
# Initialize opts hash used to inject data into one template
|
577
577
|
opts = {}
|
578
578
|
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
end
|
579
|
+
# Add network type to network hash
|
580
|
+
network_type = \
|
581
|
+
VCenterDriver::Network.get_network_type(
|
582
|
+
vc_network,
|
583
|
+
vc_network_name
|
584
|
+
)
|
585
|
+
network[vc_network_ref][:network_type] = network_type
|
586
|
+
network[vc_network_ref][:type] = network_type
|
588
587
|
|
589
588
|
# Determine if the network must be excluded
|
590
589
|
network[vc_network_ref][:excluded] = exclude_network?(
|
data/lib/datastore.rb
CHANGED
@@ -653,8 +653,8 @@ module VCenterDriver
|
|
653
653
|
|
654
654
|
wout.close
|
655
655
|
size = rout.readlines.select do |l|
|
656
|
-
l.start_with?('
|
657
|
-
end[0].sub('
|
656
|
+
l.downcase.start_with?('content-length')
|
657
|
+
end[0].downcase.sub('content-length: ', '')
|
658
658
|
rout.close
|
659
659
|
size.chomp.to_i < 4096 # If <4k, then is a descriptor
|
660
660
|
end
|
data/lib/network.rb
CHANGED
@@ -486,6 +486,70 @@ module VCenterDriver
|
|
486
486
|
@defaults = { :size => '255', :type => 'ether' }
|
487
487
|
end
|
488
488
|
|
489
|
+
def process_import(indexes, opts = {}, &_block)
|
490
|
+
indexes = indexes.gsub(/\s*\,\s*/, ',').strip.split(',')
|
491
|
+
|
492
|
+
dc_folder = VCenterDriver::DatacenterFolder.new(@vi_client)
|
493
|
+
vcenter_instance_name = @vi_client.vc_name
|
494
|
+
vcenter_uuid = @vi_client.vim.serviceContent.about.instanceUuid
|
495
|
+
hpool = VCenterDriver::VIHelper.one_pool(
|
496
|
+
OpenNebula::HostPool,
|
497
|
+
false
|
498
|
+
)
|
499
|
+
|
500
|
+
one_client = OpenNebula::Client.new
|
501
|
+
one_host = OpenNebula::Host.new_with_id(opts[:host], one_client)
|
502
|
+
|
503
|
+
rc = one_host.info
|
504
|
+
raise rc.message if OpenNebula.is_error? rc
|
505
|
+
|
506
|
+
# Get all networks in vcenter cluster (one_host)
|
507
|
+
vc_cluster_networks = dc_folder.cluster_networks(one_host)
|
508
|
+
|
509
|
+
vc_cluster_networks_map_ref = {}
|
510
|
+
|
511
|
+
# Iterate over vcenter networks
|
512
|
+
vc_cluster_networks.each do |vc_cluster_network|
|
513
|
+
vc_cluster_networks_map_ref[vc_cluster_network._ref] =
|
514
|
+
vc_cluster_network
|
515
|
+
end
|
516
|
+
|
517
|
+
indexes.each do |index|
|
518
|
+
begin
|
519
|
+
@rollback = []
|
520
|
+
@info[index] = {}
|
521
|
+
|
522
|
+
vc_cluster_network = vc_cluster_networks_map_ref[index]
|
523
|
+
|
524
|
+
if hpool.respond_to?(:message)
|
525
|
+
raise 'Could not get OpenNebula HostPool: ' \
|
526
|
+
"#{hpool.message}"
|
527
|
+
end
|
528
|
+
|
529
|
+
params = {}
|
530
|
+
params[:vc_network] = vc_cluster_network
|
531
|
+
params[:vcenter_instance_name] = vcenter_instance_name
|
532
|
+
params[:vcenter_uuid] = vcenter_uuid
|
533
|
+
params[:_hpool] = hpool
|
534
|
+
params[:one_host] = one_host
|
535
|
+
params[:args] = {}
|
536
|
+
|
537
|
+
selected = dc_folder.process_network(params)
|
538
|
+
|
539
|
+
selected = selected[index]
|
540
|
+
|
541
|
+
# import the object
|
542
|
+
opts[index] ||= @defaults
|
543
|
+
@info[:success] << import(selected, opts[index])
|
544
|
+
rescue StandardError => e
|
545
|
+
@info[:error] << { index => e.message }
|
546
|
+
@info[index][:e] = e
|
547
|
+
|
548
|
+
apply_rollback
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
489
553
|
def get_list(args = {})
|
490
554
|
dc_folder = VCenterDriver::DatacenterFolder.new(@vi_client)
|
491
555
|
|
@@ -496,8 +560,8 @@ module VCenterDriver
|
|
496
560
|
false
|
497
561
|
)
|
498
562
|
if npool.respond_to?(:message)
|
499
|
-
raise
|
500
|
-
OpenNebula VirtualNetworkPool: #{npool.message}"
|
563
|
+
raise 'Could not get ' \
|
564
|
+
"OpenNebula VirtualNetworkPool: #{npool.message}"
|
501
565
|
end
|
502
566
|
|
503
567
|
# Get OpenNebula's host pool
|
@@ -572,8 +636,8 @@ module VCenterDriver
|
|
572
636
|
str
|
573
637
|
end
|
574
638
|
|
575
|
-
def import(selected)
|
576
|
-
opts = @info[selected[:ref]][:opts]
|
639
|
+
def import(selected, opts = nil)
|
640
|
+
opts = @info[selected[:ref]][:opts] if opts.nil?
|
577
641
|
|
578
642
|
net = VCenterDriver::Network
|
579
643
|
.new_from_ref(selected[:ref], @vi_client)
|
data/lib/opennebula.rb
CHANGED
data/lib/opennebula/client.rb
CHANGED
@@ -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
|
-
|
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 > 128
|
365
|
+
new_name = "#{template.name[0..(126 - 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
|
data/lib/opennebula/image.rb
CHANGED
@@ -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? ||
|
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
|
192
|
-
template_id
|
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
|
-
|
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
|
-
|
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
|
-
|
363
|
+
tmpl << "\nNAME=\"#{options[:name]}\"\n"
|
301
364
|
|
302
|
-
|
303
|
-
|
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
|
|
data/lib/opennebula/pool.rb
CHANGED
@@ -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
|
-
|
213
|
-
|
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]}"
|
@@ -324,7 +324,7 @@ module OpenNebula::VirtualMachineExt
|
|
324
324
|
tmp.delete(true)
|
325
325
|
|
326
326
|
binfo[:apps].each do |id|
|
327
|
-
|
327
|
+
logger.info "Deleting applicance #{id}" if logger
|
328
328
|
|
329
329
|
papp = OpenNebula::MarketPlaceApp.new_with_id(id, @client)
|
330
330
|
|
data/lib/opennebula/wait_ext.rb
CHANGED
@@ -14,19 +14,117 @@
|
|
14
14
|
# limitations under the License. #
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
|
-
require 'ffi-rzmq'
|
18
17
|
|
19
18
|
require 'opennebula/host'
|
20
19
|
require 'opennebula/image'
|
21
20
|
require 'opennebula/virtual_machine'
|
22
21
|
|
22
|
+
module OpenNebula::WaitExtEvent
|
23
|
+
def wait_event(ctx, event, timeout)
|
24
|
+
subscriber = ctx.socket(ZMQ::SUB)
|
25
|
+
|
26
|
+
# Create subscriber
|
27
|
+
key = ''
|
28
|
+
content = ''
|
29
|
+
|
30
|
+
subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
|
31
|
+
subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
|
32
|
+
subscriber.connect(@client.one_zmq)
|
33
|
+
|
34
|
+
rc = subscriber.recv_string(key)
|
35
|
+
rc = subscriber.recv_string(content) if rc != -1
|
36
|
+
|
37
|
+
return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
|
38
|
+
|
39
|
+
content
|
40
|
+
ensure
|
41
|
+
subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
|
42
|
+
subscriber.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
46
|
+
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
47
|
+
|
48
|
+
# Start with a timeout of 2 seconds, to wait until the first
|
49
|
+
# info.
|
50
|
+
#
|
51
|
+
# The timeout is increased later, to avoid multiple info calls.
|
52
|
+
c_timeout = 2
|
53
|
+
recvs = 0
|
54
|
+
in_state = false
|
55
|
+
|
56
|
+
# Subscribe with timeout seconds
|
57
|
+
#
|
58
|
+
# Subscribe string:
|
59
|
+
#
|
60
|
+
# EVENT STATE element_name/state_str//self.ID
|
61
|
+
#
|
62
|
+
# - element_name: is the element name to find in the message
|
63
|
+
# - self.ID: returns element ID to find in the message
|
64
|
+
ctx = ZMQ::Context.new(1)
|
65
|
+
|
66
|
+
until in_state || (cycles != -1 && recvs >= cycles)
|
67
|
+
content = wait_event(ctx,
|
68
|
+
wfun[:event].call(self, sstr1, sstr2),
|
69
|
+
c_timeout)
|
70
|
+
|
71
|
+
if content && !content.empty?
|
72
|
+
in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
|
73
|
+
|
74
|
+
break if in_state
|
75
|
+
end
|
76
|
+
|
77
|
+
c_timeout *= 10
|
78
|
+
c_timeout = timeout if c_timeout > timeout
|
79
|
+
|
80
|
+
rco = info
|
81
|
+
|
82
|
+
return false if OpenNebula.is_error?(rco)
|
83
|
+
|
84
|
+
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
85
|
+
|
86
|
+
recvs += 1
|
87
|
+
end
|
88
|
+
|
89
|
+
in_state
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
module OpenNebula::WaitExtPolling
|
95
|
+
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
96
|
+
wfun = OpenNebula::WaitExt::WAIT[self.class]
|
97
|
+
|
98
|
+
stime = 5
|
99
|
+
recvs = 0
|
100
|
+
cycles = timeout / stime
|
101
|
+
in_state = false
|
102
|
+
|
103
|
+
loop do
|
104
|
+
rco = info
|
105
|
+
|
106
|
+
return false if OpenNebula.is_error?(rco)
|
107
|
+
|
108
|
+
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
109
|
+
|
110
|
+
recvs += 1
|
111
|
+
|
112
|
+
break if in_state || recvs >= cycles
|
113
|
+
|
114
|
+
sleep stime
|
115
|
+
end
|
116
|
+
|
117
|
+
in_state
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
23
122
|
# Module to decorate Wait classes with the following methods:
|
24
123
|
# - Wait
|
25
124
|
#
|
26
125
|
# rubocop:disable Style/ClassAndModuleChildren
|
27
126
|
module OpenNebula::WaitExt
|
28
|
-
|
29
|
-
# Wait classes and the name published in ZMQ
|
127
|
+
# Wait classes and the name published in ZMQ/STATE
|
30
128
|
WAIT = {
|
31
129
|
OpenNebula::Host => {
|
32
130
|
:event => lambda {|o, s1, _s2|
|
@@ -78,7 +176,7 @@ module OpenNebula::WaitExt
|
|
78
176
|
},
|
79
177
|
|
80
178
|
:in_state => lambda {|o, s1, s2|
|
81
|
-
|
179
|
+
obj_s1 = Integer(o['STATE'])
|
82
180
|
inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1)
|
83
181
|
|
84
182
|
obj_s2 = Integer(o['LCM_STATE'])
|
@@ -105,93 +203,30 @@ module OpenNebula::WaitExt
|
|
105
203
|
wait?(obj)
|
106
204
|
|
107
205
|
class << obj
|
206
|
+
begin
|
207
|
+
require 'ffi-rzmq'
|
108
208
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
# @param timeout [Integer] Number of seconds to timeout event recv
|
114
|
-
# @param cycles [Integer] Number of recv cycles. After each one
|
115
|
-
# object status is checked in OpenNebula.
|
116
|
-
# Use -1 (default) to wait forever.
|
117
|
-
def wait(state_str, timeout = 60, cycles = -1)
|
118
|
-
wait2(state_str, '', timeout, cycles)
|
119
|
-
end
|
120
|
-
|
121
|
-
def wait_event(ctx, event, timeout)
|
122
|
-
subscriber = ctx.socket(ZMQ::SUB)
|
123
|
-
|
124
|
-
# Create subscriber
|
125
|
-
key = ''
|
126
|
-
content = ''
|
127
|
-
|
128
|
-
subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
|
129
|
-
subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
|
130
|
-
subscriber.connect('tcp://localhost:2101')
|
131
|
-
|
132
|
-
rc = subscriber.recv_string(key)
|
133
|
-
rc = subscriber.recv_string(content) if rc != -1
|
134
|
-
|
135
|
-
return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
|
136
|
-
|
137
|
-
content
|
138
|
-
ensure
|
139
|
-
subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
|
140
|
-
subscriber.close
|
141
|
-
end
|
142
|
-
|
143
|
-
def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
|
144
|
-
wfun = WAIT[self.class]
|
145
|
-
|
146
|
-
# Start with a timeout of 2 seconds, to wait until the first
|
147
|
-
# info.
|
148
|
-
#
|
149
|
-
# The timeout is increased later, to avoid multiple info calls.
|
150
|
-
c_timeout = 2
|
151
|
-
recvs = 0
|
152
|
-
in_state = false
|
153
|
-
|
154
|
-
# Subscribe with timeout seconds
|
155
|
-
#
|
156
|
-
# Subscribe string:
|
157
|
-
#
|
158
|
-
# EVENT STATE element_name/state_str//self.ID
|
159
|
-
#
|
160
|
-
# - element_name: is the element name to find in the message
|
161
|
-
# - self.ID: returns element ID to find in the message
|
162
|
-
ctx = ZMQ::Context.new(1)
|
163
|
-
|
164
|
-
until in_state || (cycles != -1 && recvs >= cycles)
|
165
|
-
content = wait_event(ctx,
|
166
|
-
wfun[:event].call(self, sstr1, sstr2),
|
167
|
-
c_timeout)
|
168
|
-
|
169
|
-
if content && !content.empty?
|
170
|
-
in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
|
171
|
-
|
172
|
-
break if in_state
|
173
|
-
end
|
174
|
-
|
175
|
-
c_timeout *= 10
|
176
|
-
c_timeout = timeout if c_timeout > timeout
|
177
|
-
|
178
|
-
rco = info
|
179
|
-
|
180
|
-
return false if OpenNebula.is_error?(rco)
|
181
|
-
|
182
|
-
in_state = wfun[:in_state].call(self, sstr1, sstr2)
|
183
|
-
|
184
|
-
recvs += 1
|
185
|
-
end
|
186
|
-
|
187
|
-
in_state
|
188
|
-
end
|
189
|
-
|
209
|
+
include OpenNebula::WaitExtEvent
|
210
|
+
rescue LoadError
|
211
|
+
include OpenNebula::WaitExtPolling
|
212
|
+
end
|
190
213
|
end
|
191
214
|
|
192
215
|
super
|
193
216
|
end
|
194
217
|
|
218
|
+
# Wait until the element reaches some specific state
|
219
|
+
# It waits until the state can be found in ZMQ event message
|
220
|
+
#
|
221
|
+
# @param state_str [String] State name to wait
|
222
|
+
# @param timeout [Integer] Number of seconds to timeout event recv
|
223
|
+
# @param cycles [Integer] Number of recv cycles. After each one
|
224
|
+
# object status is checked in OpenNebula.
|
225
|
+
# Use -1 (default) to wait forever.
|
226
|
+
def wait(state_str, timeout = 60, cycles = -1)
|
227
|
+
wait2(state_str, '', timeout, cycles)
|
228
|
+
end
|
229
|
+
|
195
230
|
# Check if object has the method wait or not
|
196
231
|
#
|
197
232
|
# @param obj [Object or Class] Object to check class
|
data/lib/scripts_common.rb
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
# limitations under the License. #
|
15
15
|
#--------------------------------------------------------------------------- #
|
16
16
|
|
17
|
+
require 'shellwords'
|
18
|
+
|
17
19
|
module OpenNebula
|
18
20
|
|
19
21
|
# Generic log function
|
@@ -76,6 +78,7 @@ module OpenNebula
|
|
76
78
|
# If a second parameter is present it is used as the error message when
|
77
79
|
# the command fails
|
78
80
|
def self.exec_and_log(command, message=nil, allowed_return_code=0)
|
81
|
+
command = command.shellsplit.shelljoin # escape
|
79
82
|
output=`#{command} 2>&1 1>/dev/null`
|
80
83
|
code=$?.exitstatus
|
81
84
|
|
data/lib/vi_helper.rb
CHANGED
@@ -231,10 +231,11 @@ module VCenterDriver
|
|
231
231
|
@ref_hash[attribute][refkey]
|
232
232
|
end
|
233
233
|
|
234
|
+
require 'addressable'
|
234
235
|
def self.find_image_by(att, the_class, path, ds_id, pool = nil)
|
235
236
|
pool = one_pool(the_class, false) if pool.nil?
|
236
237
|
pool.find do |e|
|
237
|
-
e[att] == path &&
|
238
|
+
e[att] == Addressable::URI.escape(path) &&
|
238
239
|
e['DATASTORE_ID'] == ds_id
|
239
240
|
end
|
240
241
|
end
|
data/lib/virtual_machine.rb
CHANGED
@@ -1961,7 +1961,7 @@ module VCenterDriver
|
|
1961
1961
|
end
|
1962
1962
|
|
1963
1963
|
card_spec = {
|
1964
|
-
:key =>
|
1964
|
+
:key => Time.now.utc.strftime('%Y%m%d%M%S%L').to_i,
|
1965
1965
|
:deviceInfo => {
|
1966
1966
|
:label => 'net' + card_num.to_s,
|
1967
1967
|
:summary => pg_name
|
@@ -2107,7 +2107,7 @@ module VCenterDriver
|
|
2107
2107
|
end
|
2108
2108
|
|
2109
2109
|
card_spec = {
|
2110
|
-
:key =>
|
2110
|
+
:key => Time.now.utc.strftime('%Y%m%d%M%S%L').to_i,
|
2111
2111
|
:deviceInfo => {
|
2112
2112
|
:label => 'net' + card_num.to_s,
|
2113
2113
|
:summary => pg_name
|
@@ -3032,7 +3032,7 @@ module VCenterDriver
|
|
3032
3032
|
# Create a snapshot for the VM
|
3033
3033
|
def create_snapshot(snap_id, snap_name)
|
3034
3034
|
memory_dumps = true
|
3035
|
-
memory_dumps = CONFIG[:memory_dumps]
|
3035
|
+
memory_dumps = CONFIG[:memory_dumps] unless CONFIG[:memory_dumps].nil?
|
3036
3036
|
|
3037
3037
|
snapshot_hash = {
|
3038
3038
|
:name => snap_id,
|
data/lib/vm_template.rb
CHANGED
@@ -602,7 +602,7 @@ module VCenterDriver
|
|
602
602
|
def nic_alias_from_nic(id, nic, nic_index, network_found, vm_object)
|
603
603
|
nic_tmp = ''
|
604
604
|
|
605
|
-
nic_alias_index =
|
605
|
+
nic_alias_index = 0
|
606
606
|
if nic[:ipv4_additionals]
|
607
607
|
nic[:ipv4_additionals].split(',').each do |ipv4_additional|
|
608
608
|
ipv4, ipv6 =
|
@@ -625,8 +625,8 @@ module VCenterDriver
|
|
625
625
|
nic_tmp << "NETWORK_ID=\"#{id}\",\n"
|
626
626
|
nic_tmp << "IP=\"#{ipv4_additional}\",\n"
|
627
627
|
nic_tmp <<
|
628
|
-
"NAME=\"
|
629
|
-
nic_tmp << "PARENT=\"
|
628
|
+
"NAME=\"VC_NIC#{nic_index}_ALIAS#{nic_alias_index}\",\n"
|
629
|
+
nic_tmp << "PARENT=\"VC_NIC#{nic_index}\"\n"
|
630
630
|
nic_tmp << "]\n"
|
631
631
|
nic_alias_index += 1
|
632
632
|
end
|
@@ -653,8 +653,8 @@ module VCenterDriver
|
|
653
653
|
nic_tmp << "NETWORK_ID=\"#{id}\",\n"
|
654
654
|
nic_tmp << "IP6=\"#{ipv6_additional}\",\n"
|
655
655
|
nic_tmp <<
|
656
|
-
"NAME=\"
|
657
|
-
nic_tmp << "PARENT=\"
|
656
|
+
"NAME=\"VC_NIC#{nic_index}_ALIAS#{nic_alias_index}\",\n"
|
657
|
+
nic_tmp << "PARENT=\"VC_NIC#{nic_index}\"\n"
|
658
658
|
nic_tmp << "]\n"
|
659
659
|
nic_alias_index += 1
|
660
660
|
end
|
@@ -666,7 +666,7 @@ module VCenterDriver
|
|
666
666
|
def nic_from_network_created(one_vn, nic, nic_index, vm_object, _ar_ids)
|
667
667
|
nic_tmp = "NIC=[\n"
|
668
668
|
nic_tmp << "NETWORK_ID=\"#{one_vn.id}\",\n"
|
669
|
-
nic_tmp << "NAME =\"
|
669
|
+
nic_tmp << "NAME =\"VC_NIC#{nic_index}\",\n"
|
670
670
|
|
671
671
|
if vm?
|
672
672
|
if nic[:mac]
|
@@ -716,7 +716,7 @@ module VCenterDriver
|
|
716
716
|
)
|
717
717
|
nic_tmp = "NIC=[\n"
|
718
718
|
nic_tmp << "NETWORK_ID=\"#{network_found['ID']}\",\n"
|
719
|
-
nic_tmp << "NAME =\"
|
719
|
+
nic_tmp << "NAME =\"VC_NIC#{nic_index}\",\n"
|
720
720
|
|
721
721
|
if vm?
|
722
722
|
ipv4, ipv6 = find_ips_in_network(network_found, vm_object,
|
@@ -1014,7 +1014,7 @@ module VCenterDriver
|
|
1014
1014
|
# Track allocated networks for rollback
|
1015
1015
|
allocated_networks = []
|
1016
1016
|
|
1017
|
-
nic_index =
|
1017
|
+
nic_index = 0
|
1018
1018
|
|
1019
1019
|
vc_nics.each do |nic|
|
1020
1020
|
# Check if the network already exists
|
@@ -1659,10 +1659,12 @@ module VCenterDriver
|
|
1659
1659
|
folders = []
|
1660
1660
|
until item.instance_of? RbVmomi::VIM::Datacenter
|
1661
1661
|
item = item.parent
|
1662
|
-
first_condition =
|
1663
|
-
|
1662
|
+
first_condition =
|
1663
|
+
!(item.instance_of? RbVmomi::VIM::Datacenter)
|
1664
|
+
second_condition =
|
1665
|
+
item.name != 'vm'
|
1664
1666
|
|
1665
|
-
|
1667
|
+
if first_condition && second_condition
|
1666
1668
|
folders << item.name
|
1667
1669
|
end
|
1668
1670
|
if item.nil?
|
@@ -1693,8 +1695,8 @@ module VCenterDriver
|
|
1693
1695
|
one_tmp[:dc_name] = dc_name
|
1694
1696
|
one_tmp[:template_name] = template_name
|
1695
1697
|
one_tmp[:sunstone_template_name]=
|
1696
|
-
"#{template_name} [ Cluster: #{template_ccr_name} \
|
1697
|
-
- Template location: #{location} ]"
|
1698
|
+
"#{template_name} [ Cluster: #{template_ccr_name}" \
|
1699
|
+
" - Template location: #{location} ]"
|
1698
1700
|
one_tmp[:template_location] = location
|
1699
1701
|
one_tmp[:vcenter_ccr_ref] = template_ccr_ref
|
1700
1702
|
one_tmp[:vcenter_ref] = template_ref
|
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:
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenNebula
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -223,8 +223,8 @@ files:
|
|
223
223
|
- lib/opennebula/xml_element.rb
|
224
224
|
- lib/opennebula/xml_pool.rb
|
225
225
|
- lib/opennebula/xml_utils.rb
|
226
|
-
- lib/opennebula/zone.rb
|
227
226
|
- lib/opennebula/zone_pool.rb
|
227
|
+
- lib/opennebula/zone.rb
|
228
228
|
- lib/opennebula/flow/grammar.rb
|
229
229
|
- lib/opennebula/flow/service_pool.rb
|
230
230
|
- lib/opennebula/flow/service_template.rb
|
@@ -255,9 +255,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
255
255
|
version: '0'
|
256
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
257
|
requirements:
|
258
|
-
- - '
|
258
|
+
- - '>='
|
259
259
|
- !ruby/object:Gem::Version
|
260
|
-
version:
|
260
|
+
version: '0'
|
261
261
|
requirements: []
|
262
262
|
rubyforge_project:
|
263
263
|
rubygems_version: 2.0.14.1
|