opennebula 6.0.2 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c860bdde4c2e7184d75f0433181a5aa485d39296
4
- data.tar.gz: 7b773535ac63930fb85252435814b4f4e81adcf0
3
+ metadata.gz: 62addc3c6ca7a2d64f362b69e78d5249a8c580ca
4
+ data.tar.gz: 753aea24a283602fad7c6e7171164a8c6af9ee00
5
5
  SHA512:
6
- metadata.gz: 0b23945ca645beba28c3e898a13ef254b4a78ecdc63dec03922c808914233d550a3503efef499a521d2aa6fbfaeff795789976105ccb93eb80614ef3686662e1
7
- data.tar.gz: 3337709c1791f07680d40dcb8c4a012139e93af38546fc200dacb07fea81b3890405a80f48a596f72465c4bb08e28f02b6c729801e8c414ba55559d1b2f7a097
6
+ metadata.gz: afd9480704e6bfce7e708729ef75ad7457ce713b0e85b235b23373e94867b40713aef2a032b191d52f3567b2ca8de4a361e5baaf757228aa131eb32ceda2b12e
7
+ data.tar.gz: 0b319949a9cfad08f13f6ecd1040b28d5edaf1a11c46f5fadbd0ea3ee90af97f239a48fa85809789eec9805cb269ad44f9f72c63b5809e6fea8e273acda7f1c5
@@ -34,17 +34,9 @@ require 'base64'
34
34
  # * Log messages will be sent to STDOUT
35
35
  # * The script will return 0 if it succeded or any other value
36
36
  # if there was a failure
37
- # * In case of failure the cause of the error will be written to STDERR
38
- # wrapped by start and end marks as follows:
39
- #
40
- # ERROR MESSAGE --8<------
41
- # error message for the failure
42
- # ERROR MESSAGE ------>8--
43
-
37
+ # * In case of failure the cause of the error will be written to STDERR.
44
38
 
45
39
  class GenericCommand
46
- ERROR_OPEN = "ERROR MESSAGE --8<------"
47
- ERROR_CLOSE = "ERROR MESSAGE ------>8--"
48
40
 
49
41
  attr_reader :code, :stdout, :stderr, :command
50
42
 
@@ -93,8 +85,9 @@ class GenericCommand
93
85
  end
94
86
 
95
87
  log(error_message)
96
- @stderr = ERROR_OPEN + "\n" + error_message + "\n" + ERROR_CLOSE
97
- @code = 255
88
+
89
+ @stderr = error_message
90
+ @code = 255
98
91
  end
99
92
 
100
93
  return @code
@@ -102,9 +95,9 @@ class GenericCommand
102
95
 
103
96
  # Parses error message from +stderr+ output
104
97
  def get_error_message
105
- tmp=@stderr.scan(/^#{ERROR_OPEN}\n(.*?)#{ERROR_CLOSE}$/m)
106
- return "-" if !tmp[0]
107
- tmp[0].join(' ').strip
98
+ return '-' if @stderr.empty?
99
+
100
+ @stderr.tr("\n",' ').strip
108
101
  end
109
102
 
110
103
  def to_xml
@@ -176,8 +169,12 @@ private
176
169
  end
177
170
  }
178
171
 
179
- i.write stdin_data
180
- i.close
172
+ begin
173
+ i.write stdin_data
174
+ i.close
175
+ rescue Errno::EPIPE
176
+ # the cmd doesn't read the input, ignore error
177
+ end
181
178
 
182
179
  # blocking wait for process termination
183
180
  t.value
@@ -124,31 +124,21 @@ module DriverExecHelper
124
124
  # Sends a log message to ONE. The +message+ can be multiline, it will
125
125
  # be automatically splitted by lines.
126
126
  def log(number, message, all = true)
127
- in_error_message=false
128
- msg=message.strip
127
+ msg = message.strip
128
+
129
129
  msg.each_line do |line|
130
130
  all ? severity='I' : severity=nil
131
- l=line.strip
132
-
133
- if l=='ERROR MESSAGE --8<------'
134
- in_error_message=true
135
- next
136
- elsif l=='ERROR MESSAGE ------>8--'
137
- in_error_message=false
138
- next
139
- else
140
- if in_error_message
131
+
132
+ if line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
133
+ line=Regexp.last_match(2)
134
+
135
+ case Regexp.last_match(1)
136
+ when 'ERROR'
141
137
  severity='E'
142
- elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
143
- line=Regexp.last_match(2)
144
- case Regexp.last_match(1)
145
- when 'ERROR'
146
- severity='E'
147
- when 'DEBUG'
148
- severity='D'
149
- when 'INFO'
150
- severity='I'
151
- end
138
+ when 'DEBUG'
139
+ severity='D'
140
+ when 'INFO'
141
+ severity='I'
152
142
  end
153
143
  end
154
144
 
@@ -51,7 +51,7 @@ end
51
51
  module CloudClient
52
52
 
53
53
  # OpenNebula version
54
- VERSION = '6.0.2'
54
+ VERSION = '6.2.0'
55
55
 
56
56
  # #########################################################################
57
57
  # Default location for the authentication file
data/lib/datastore.rb CHANGED
@@ -558,8 +558,12 @@ module VCenterDriver
558
558
  raise 'Could not get file size or capacity' if size.nil?
559
559
 
560
560
  size
561
- rescue StandardError
562
- raise 'Could not find file.'
561
+ rescue StandardError => e
562
+ message = "Could not find file. Reason: \"#{e.message}\"."
563
+ if VCenterDriver::CONFIG[:debug_information]
564
+ message += ' ' + e.backtrace
565
+ end
566
+ raise message
563
567
  end
564
568
  end
565
569
 
data/lib/file_helper.rb CHANGED
@@ -81,6 +81,10 @@ module VCenterDriver
81
81
  file.match(%r{^https?://}) || file.match(%r{^s3?://})
82
82
  end
83
83
 
84
+ def self.from_s3?(file)
85
+ file.match(%r{^s3?://})
86
+ end
87
+
84
88
  def self.vmdk?(file)
85
89
  type = `file #{file}`
86
90
 
data/lib/host.rb CHANGED
@@ -1145,14 +1145,14 @@ module VCenterDriver
1145
1145
  vswitchspec =
1146
1146
  RbVmomi::VIM::HostVirtualSwitchSpec(
1147
1147
  :bridge => hostbridge,
1148
- :mtu => mtu,
1149
- :numPorts => num_ports
1148
+ :mtu => mtu,
1149
+ :numPorts => num_ports
1150
1150
  )
1151
1151
  begin
1152
1152
  nws
1153
1153
  .UpdateVirtualSwitch(
1154
1154
  :vswitchName => name,
1155
- :spec => vswitchspec
1155
+ :spec => vswitchspec
1156
1156
  )
1157
1157
  rescue StandardError => e
1158
1158
  raise "The standard switch with name #{name} \
@@ -1463,7 +1463,7 @@ module VCenterDriver
1463
1463
  nws
1464
1464
  .UpdatePortGroup(
1465
1465
  :pgName => nr[:name],
1466
- :portgrp => nr[:spec]
1466
+ :portgrp => nr[:spec]
1467
1467
  )
1468
1468
  rescue StandardError => e
1469
1469
  raise "A rollback operation for standard \
data/lib/models/role.rb CHANGED
@@ -571,11 +571,20 @@ module OpenNebula
571
571
  vm = OpenNebula::VirtualMachine.new_with_id(vm_id,
572
572
  @service.client)
573
573
 
574
- rc = vm.info
574
+ if do_offset
575
+ offset = (index / vms_per_period.to_i).floor
576
+ time_offset = offset * period.to_i
577
+ end
578
+
579
+ tmp_str = 'SCHED_ACTION = ['
580
+ tmp_str << "ACTION = #{action},"
581
+ tmp_str << "ARGS = \"#{args}\"," if args
582
+ tmp_str << "TIME = #{now + time_offset}]"
575
583
 
584
+ rc = vm.sched_action_add(tmp_str)
576
585
  if OpenNebula.is_error?(rc)
577
- msg = "Role #{name} : VM #{vm_id} monitorization failed;"\
578
- " #{rc.message}"
586
+ msg = "Role #{name} : VM #{vm_id} error scheduling "\
587
+ "action; #{rc.message}"
579
588
 
580
589
  error_msgs << msg
581
590
 
@@ -583,40 +592,7 @@ module OpenNebula
583
592
 
584
593
  @service.log_error(msg)
585
594
  else
586
- ids = vm.retrieve_elements('USER_TEMPLATE/SCHED_ACTION/ID')
587
-
588
- id = 0
589
- if !ids.nil? && !ids.empty?
590
- ids.map! {|e| e.to_i }
591
- id = ids.max + 1
592
- end
593
-
594
- tmp_str = vm.user_template_str
595
-
596
- if do_offset
597
- offset = (index / vms_per_period.to_i).floor
598
- time_offset = offset * period.to_i
599
- end
600
-
601
- tmp_str << "\nSCHED_ACTION = ["
602
- tmp_str << "ID = #{id},"
603
- tmp_str << "ACTION = #{action},"
604
- tmp_str << "ARGS = \"#{args}\"," if args
605
- tmp_str << "TIME = #{now + time_offset}]"
606
-
607
- rc = vm.update(tmp_str)
608
- if OpenNebula.is_error?(rc)
609
- msg = "Role #{name} : VM #{vm_id} error scheduling "\
610
- "action; #{rc.message}"
611
-
612
- error_msgs << msg
613
-
614
- Log.error LOG_COMP, msg, @service.id
615
-
616
- @service.log_error(msg)
617
- else
618
- vms_id << vm.id
619
- end
595
+ vms_id << vm.id
620
596
  end
621
597
  end
622
598
 
@@ -140,12 +140,14 @@ module OpenNebula
140
140
  # Return true if the service can be undeployed
141
141
  # @return true if the service can be undeployed, false otherwise
142
142
  def can_undeploy?
143
+ # rubocop:disable Style/IfWithBooleanLiteralBranches
143
144
  if (transient_state? && state != Service::STATE['UNDEPLOYING']) ||
144
- state == Service::STATE['DONE'] || failed_state?
145
+ state == Service::STATE['DONE'] || failed_state?
145
146
  false
146
147
  else
147
148
  true
148
149
  end
150
+ # rubocop:enable Style/IfWithBooleanLiteralBranches
149
151
  end
150
152
 
151
153
  # Return true if the service can be updated
@@ -166,6 +168,12 @@ module OpenNebula
166
168
  RECOVER_SCALE_STATES.include? STATE_STR[state]
167
169
  end
168
170
 
171
+ # Return true if the service is running
172
+ # @return true if the service is runnning, false otherwise
173
+ def running?
174
+ state_str == 'RUNNING'
175
+ end
176
+
169
177
  # Returns the running_status_vm option
170
178
  # @return [true, false] true if the running_status_vm option is enabled
171
179
  def report_ready?
@@ -323,6 +331,36 @@ module OpenNebula
323
331
  nil
324
332
  end
325
333
 
334
+ # Adds a role to the service
335
+ #
336
+ # @param template [Hash] Role information
337
+ #
338
+ # @return [OpenNebula::Role] New role
339
+ def add_role(template)
340
+ template['state'] ||= Role::STATE['PENDING']
341
+ role = Role.new(template, self)
342
+
343
+ if @roles[role.name]
344
+ return OpenNebula::Error.new("Role #{role.name} already exists")
345
+ end
346
+
347
+ @roles[role.name] = role
348
+ @body['roles'] << template if @body && @body['roles']
349
+
350
+ role
351
+ end
352
+
353
+ # Removes a role from the service
354
+ #
355
+ # @param name [String] Role name to delete
356
+ def remove_role(name)
357
+ @roles.delete(name)
358
+
359
+ @body['roles'].delete_if do |role|
360
+ role['name'] == name
361
+ end
362
+ end
363
+
326
364
  # Retrieves the information of the Service and all its Nodes.
327
365
  #
328
366
  # @return [nil, OpenNebula::Error] nil in case of success, Error
@@ -484,38 +522,51 @@ module OpenNebula
484
522
 
485
523
  # Check that changes values are correct
486
524
  #
487
- # @param template_json [String] New template
525
+ # @param template_json [String] New template
526
+ # @param append [Boolean] True to append template to the current
488
527
  #
489
528
  # @return [Boolean, String] True, nil if everything is correct
490
529
  # False, attr if attr was changed
491
- def check_new_template(template_json)
530
+ def check_new_template(template_json, append)
492
531
  template = JSON.parse(template_json)
493
532
 
494
- if template['roles'].size != @roles.size
495
- return [false, 'service/roles size']
496
- end
533
+ if append
534
+ IMMUTABLE_ATTRS.each do |attr|
535
+ next if template[attr].nil?
497
536
 
498
- IMMUTABLE_ATTRS.each do |attr|
499
- next if template[attr] == @body[attr]
537
+ return [false, "service/#{attr}"]
538
+ end
539
+ else
540
+ if template['roles'].size != @roles.size
541
+ return [false, 'service/roles size']
542
+ end
500
543
 
501
- return [false, "service/#{attr}"]
502
- end
544
+ IMMUTABLE_ATTRS.each do |attr|
545
+ next if template[attr] == @body[attr]
503
546
 
504
- template['roles'].each do |role|
505
- # Role name can't be changed, if it is changed some problems
506
- # may appear, as name is used to reference roles
507
- return [false, 'name'] unless @roles[role['name']]
547
+ return [false, "service/#{attr}"]
548
+ end
549
+
550
+ template['roles'].each do |role|
551
+ # Role name can't be changed, if it is changed some problems
552
+ # may appear, as name is used to reference roles
553
+ return [false, 'name'] unless @roles[role['name']]
508
554
 
509
- rc = @roles[role['name']].check_new_template(role)
555
+ rc = @roles[role['name']].check_new_template(role)
510
556
 
511
- return rc unless rc[0]
557
+ return rc unless rc[0]
558
+ end
512
559
  end
513
560
 
514
561
  [true, nil]
515
562
  end
516
563
 
517
- def deploy_networks
518
- body = JSON.parse(self['TEMPLATE/BODY'])
564
+ def deploy_networks(deploy = true)
565
+ if deploy
566
+ body = JSON.parse(self['TEMPLATE/BODY'])
567
+ else
568
+ body = @body
569
+ end
519
570
 
520
571
  return if body['networks_values'].nil?
521
572
 
@@ -531,7 +582,7 @@ module OpenNebula
531
582
  if OpenNebula.is_error?(rc)
532
583
  return rc
533
584
  end
534
- end
585
+ end if deploy
535
586
 
536
587
  # Replace $attibute by the corresponding value
537
588
  resolve_attributes(body)
@@ -307,10 +307,18 @@ module OpenNebula
307
307
 
308
308
  template = JSON.parse(template_json)
309
309
 
310
- IMMUTABLE_ATTRS.each do |attr|
311
- next if template[attr] == @body[attr]
310
+ if append
311
+ IMMUTABLE_ATTRS.each do |attr|
312
+ unless template[attr].nil?
313
+ return [false, "service_template/#{attr}"]
314
+ end
315
+ end
316
+ else
317
+ IMMUTABLE_ATTRS.each do |attr|
318
+ next if template[attr] == @body[attr]
312
319
 
313
- return [false, "service_template/#{attr}"]
320
+ return [false, "service_template/#{attr}"]
321
+ end
314
322
  end
315
323
 
316
324
  template = @body.merge(template) if append
@@ -451,6 +459,16 @@ module OpenNebula
451
459
  validate_values(template)
452
460
  end
453
461
 
462
+ def self.validate_role(template)
463
+ validator = Validator::Validator.new(
464
+ :default_values => true,
465
+ :delete_extra_properties => false,
466
+ :allow_extra_properties => true
467
+ )
468
+
469
+ validator.validate!(template, ROLE_SCHEMA)
470
+ end
471
+
454
472
  def instantiate(merge_template)
455
473
  rc = nil
456
474
 
@@ -161,7 +161,8 @@ class OpenNebula::LdapAuth
161
161
  end
162
162
 
163
163
  def is_in_group?(user, group)
164
- username = user.first.force_encoding(Encoding::UTF_8)
164
+ username = Net::LDAP::Filter.escape(
165
+ user.first.force_encoding(Encoding::UTF_8))
165
166
  result=@ldap.search(
166
167
  :base => group,
167
168
  :attributes => [@options[:group_field]],
@@ -273,6 +274,7 @@ def get_server_order(opts, user)
273
274
  user = m[1] if m[1]
274
275
 
275
276
  order << to_array(server)
277
+ break
276
278
  end
277
279
  end
278
280
 
@@ -29,7 +29,15 @@ module OpenNebula
29
29
  :update => "market.update",
30
30
  :chown => "market.chown",
31
31
  :chmod => "market.chmod",
32
- :rename => "market.rename"
32
+ :rename => "market.rename",
33
+ :enable => "market.enable"
34
+ }
35
+
36
+ MARKETPLACE_STATES=%w{ENABLED DISABLED}
37
+
38
+ SHORT_MARKETPLACE_STATES={
39
+ "ENABLED" => "on",
40
+ "DISABLED" => "off"
33
41
  }
34
42
 
35
43
  # Creates a MarketPlace description with just its identifier
@@ -130,13 +138,33 @@ module OpenNebula
130
138
  # @return [nil, OpenNebula::Error] nil in case of success, Error
131
139
  # otherwise
132
140
  def rename(name)
133
- return call(MARKETPLACE_METHODS[:rename], @pe_id, name)
141
+ call(MARKETPLACE_METHODS[:rename], @pe_id, name)
142
+ end
143
+
144
+ # Enables this marketplace
145
+ def enable
146
+ call(MARKETPLACE_METHODS[:enable], @pe_id, true)
147
+ end
148
+
149
+ # Enables this marketplace
150
+ def disable
151
+ call(MARKETPLACE_METHODS[:enable], @pe_id, false)
134
152
  end
135
153
 
136
154
  # ---------------------------------------------------------------------
137
155
  # Helpers to get information
138
156
  # ---------------------------------------------------------------------
139
157
 
158
+ # Returns the state of the Zone (numeric value)
159
+ def state
160
+ self['STATE'].to_i
161
+ end
162
+
163
+ # Returns the state of the Zone (string value)
164
+ def state_str
165
+ MARKETPLACE_STATES[state]
166
+ end
167
+
140
168
  # Returns whether or not the marketplace app with id 'id' is part of
141
169
  # this marketplace
142
170
  def contains(id)
@@ -261,6 +261,8 @@ module OpenNebula
261
261
  size = OpenNebula.pool_page_size if (!size || size == 0)
262
262
  rc = @client.call(method, @user_id, current, -size, state)
263
263
 
264
+ return rc if OpenNebula.is_error?(rc)
265
+
264
266
  initialize_xml(rc, @pool_name)
265
267
  else
266
268
  rc = info
@@ -276,11 +278,11 @@ module OpenNebula
276
278
  page = OpenNebula::XMLElement.new
277
279
 
278
280
  loop do
279
- page.initialize_xml(get_page(size,
280
- current,
281
- extended,
282
- state),
283
- @pool_name)
281
+ rc = get_page(size, current, extended, state)
282
+
283
+ break rc if OpenNebula.is_error?(rc)
284
+
285
+ page.initialize_xml(rc, @pool_name)
284
286
 
285
287
  break if page["//#{element}"].nil?
286
288
 
@@ -41,8 +41,10 @@ class OpenNebula::ServerCipherAuth
41
41
  if !srv_passwd.empty?
42
42
  # truncate token to 32-bytes for Ruby >= 2.4
43
43
  @key = Digest::SHA256.hexdigest(@srv_passwd)[0..31]
44
- else
44
+ @iv = @key[0..15]
45
+ else
45
46
  @key = ""
47
+ @iv = ""
46
48
  end
47
49
 
48
50
  @cipher = OpenSSL::Cipher.new(CIPHER)
@@ -112,6 +114,7 @@ class OpenNebula::ServerCipherAuth
112
114
  begin
113
115
  # truncate token to 32-bytes for Ruby >= 2.4
114
116
  @key = srv_pass[0..31]
117
+ @iv = srv_pass[0..15]
115
118
 
116
119
  token_array = decrypt(signed_text).split(':')
117
120
 
@@ -133,7 +136,7 @@ class OpenNebula::ServerCipherAuth
133
136
  def encrypt(data)
134
137
  @cipher.encrypt
135
138
  @cipher.key = @key
136
-
139
+ @cipher.iv = @iv
137
140
  rc = @cipher.update(data)
138
141
  rc << @cipher.final
139
142
 
@@ -143,7 +146,7 @@ class OpenNebula::ServerCipherAuth
143
146
  def decrypt(data)
144
147
  @cipher.decrypt
145
148
  @cipher.key = @key
146
-
149
+ @cipher.iv = @iv
147
150
  rc = @cipher.update(Base64::decode64(data))
148
151
  rc << @cipher.final
149
152
 
@@ -50,8 +50,11 @@ module OpenNebula
50
50
  :disksnapshotrename => "vm.disksnapshotrename",
51
51
  :diskresize => "vm.diskresize",
52
52
  :updateconf => "vm.updateconf",
53
- :lock => "vm.lock",
54
- :unlock => "vm.unlock"
53
+ :lock => "vm.lock",
54
+ :unlock => "vm.unlock",
55
+ :schedadd => "vm.schedadd",
56
+ :scheddelete => "vm.scheddelete",
57
+ :schedupdate => "vm.schedupdate"
55
58
  }
56
59
 
57
60
  VM_STATE=%w{INIT PENDING HOLD ACTIVE STOPPED SUSPENDED DONE FAILED
@@ -260,7 +263,7 @@ module OpenNebula
260
263
  # +id+ the id of the vm
261
264
  #
262
265
  # Example:
263
- # vnet = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
266
+ # vm = VirtualMachine.new(VirtualMachine.build_xml(3),rpc_client)
264
267
  #
265
268
  def VirtualMachine.build_xml(pe_id=nil)
266
269
  if pe_id
@@ -710,18 +713,49 @@ module OpenNebula
710
713
  end
711
714
  end
712
715
 
713
- # Changes the attributes of a VM in power off, failure and undeploy
714
- # states
715
- # @param new_conf, string describing the new attributes. Each attribute
716
+ # Changes the attributes of a VM in power off, failure and undeploy
717
+ # states
718
+ #
719
+ # @param new_conf, string describing the new attributes. Each attribute
716
720
  # will replace the existing ones or delete it if empty. Attributes that
717
721
  # can be updated are: INPUT/{TYPE, BUS}; RAW/{TYPE, DATA, DATA_VMX},
718
722
  # OS/{BOOT, BOOTLOADER, ARCH, MACHINE, KERNEL, INITRD},
719
723
  # FEATURES/{ACPI, APIC, PAE, LOCALTIME, HYPERV, GUEST_AGENT},
720
724
  # and GRAPHICS/{TYPE, LISTEN, PASSWD, KEYMAP}
725
+ # @param append, append template, do not delete empty attributes
726
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
727
+ # otherwise
728
+ def updateconf(new_conf, append = false)
729
+ return call(VM_METHODS[:updateconf], @pe_id, new_conf, append ? 1 : 0)
730
+ end
731
+
732
+ # Add sched actions
733
+ #
734
+ # @param sched_template [String] Template with SCHED_ACTIONs
735
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
736
+ # otherwise
737
+ def sched_action_add(sched_template)
738
+ return call(VM_METHODS[:schedadd], @pe_id, sched_template)
739
+ end
740
+
741
+ # Delete sched action
742
+ #
743
+ # @param sched_id [Int] id of the SCHED_ACTION
744
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
745
+ # otherwise
746
+ def sched_action_delete(sched_id)
747
+ return call(VM_METHODS[:scheddelete], @pe_id, sched_id.to_i)
748
+ end
749
+
750
+ # Update sched_action
751
+ #
752
+ # @param sched_id [Int] id of the SCHED_ACTION
753
+ # @param sched_template [String] Template containing a SCHED_ACTION
721
754
  # @return [nil, OpenNebula::Error] nil in case of success, Error
722
755
  # otherwise
723
- def updateconf(new_conf)
724
- return call(VM_METHODS[:updateconf], @pe_id, new_conf)
756
+ def sched_action_update(sched_id, sched_template)
757
+ return call(VM_METHODS[:schedupdate], @pe_id, sched_id.to_i,
758
+ sched_template)
725
759
  end
726
760
 
727
761
  ########################################################################
@@ -14,107 +14,118 @@
14
14
  # limitations under the License. #
15
15
  #--------------------------------------------------------------------------- #
16
16
 
17
-
18
17
  require 'opennebula/host'
19
18
  require 'opennebula/image'
20
19
  require 'opennebula/virtual_machine'
21
20
 
22
- module OpenNebula::WaitExtEvent
23
- def wait_event(ctx, event, timeout)
24
- subscriber = ctx.socket(ZMQ::SUB)
21
+ module OpenNebula
25
22
 
26
- # Create subscriber
27
- key = ''
28
- content = ''
23
+ # Module to wait OpenNebula objects events using ZMQ
24
+ module WaitExtEvent
29
25
 
30
- subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
31
- subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
32
- subscriber.connect(@client.one_zmq)
26
+ def wait_event(ctx, event, timeout)
27
+ subscriber = ctx.socket(ZMQ::SUB)
33
28
 
34
- rc = subscriber.recv_string(key)
35
- rc = subscriber.recv_string(content) if rc != -1
29
+ # Create subscriber
30
+ key = ''
31
+ content = ''
36
32
 
37
- return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
33
+ subscriber.setsockopt(ZMQ::RCVTIMEO, timeout * 1000)
34
+ subscriber.setsockopt(ZMQ::SUBSCRIBE, event)
35
+ subscriber.connect(@client.one_zmq)
38
36
 
39
- content
40
- ensure
41
- subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
42
- subscriber.close
43
- end
37
+ rc = subscriber.recv_string(key)
38
+ rc = subscriber.recv_string(content) if rc != -1
44
39
 
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
40
+ return if ZMQ::Util.errno == ZMQ::EAGAIN || rc == -1
41
+
42
+ content
43
+ ensure
44
+ subscriber.setsockopt(ZMQ::UNSUBSCRIBE, event)
45
+ subscriber.close
46
+ end
47
+
48
+ def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
49
+ wfun = OpenNebula::WaitExt::WAIT[self.class]
50
+
51
+ # Start with a timeout of 2 seconds, to wait until the first
52
+ # info.
53
+ #
54
+ # The timeout is increased later, to avoid multiple info calls.
55
+ c_timeout = 2
56
+ recvs = 0
57
+ in_state = false
58
+
59
+ # Subscribe with timeout seconds
60
+ #
61
+ # Subscribe string:
62
+ #
63
+ # EVENT STATE element_name/state_str//self.ID
64
+ #
65
+ # - element_name: is the element name to find in the message
66
+ # - self.ID: returns element ID to find in the message
67
+ ctx = ZMQ::Context.new(1)
68
+
69
+ until in_state || (cycles != -1 && recvs >= cycles)
70
+ content = wait_event(ctx,
71
+ wfun[:event].call(self, sstr1, sstr2),
72
+ c_timeout)
73
+
74
+ if content && !content.empty?
75
+ in_state = wfun[:in_state_e].call(sstr1, sstr2, content)
76
+
77
+ break if in_state
78
+ end
76
79
 
77
- c_timeout *= 10
78
- c_timeout = timeout if c_timeout > timeout
80
+ c_timeout *= 10
81
+ c_timeout = timeout if c_timeout > timeout
79
82
 
80
- rco = info
83
+ rco = info
81
84
 
82
- return false if OpenNebula.is_error?(rco)
85
+ return false if OpenNebula.is_error?(rco)
83
86
 
84
- in_state = wfun[:in_state].call(self, sstr1, sstr2)
87
+ in_state = wfun[:in_state].call(self, sstr1, sstr2)
85
88
 
86
- recvs += 1
89
+ recvs += 1
90
+ end
91
+
92
+ in_state
87
93
  end
88
94
 
89
- in_state
90
95
  end
91
96
 
92
97
  end
93
98
 
94
- module OpenNebula::WaitExtPolling
95
- def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
96
- wfun = OpenNebula::WaitExt::WAIT[self.class]
99
+ module OpenNebula
100
+
101
+ # Module to wait OpenNebula objects events using polling
102
+ module WaitExtPolling
103
+
104
+ def wait2(sstr1, sstr2, timeout = 60, cycles = -1)
105
+ wfun = OpenNebula::WaitExt::WAIT[self.class]
106
+
107
+ stime = 5
108
+ recvs = 0
109
+ cycles = timeout / stime if cycles == -1
110
+ in_state = false
97
111
 
98
- stime = 5
99
- recvs = 0
100
- cycles = timeout / stime
101
- in_state = false
112
+ loop do
113
+ rco = info
102
114
 
103
- loop do
104
- rco = info
115
+ return false if OpenNebula.is_error?(rco)
105
116
 
106
- return false if OpenNebula.is_error?(rco)
117
+ in_state = wfun[:in_state].call(self, sstr1, sstr2)
107
118
 
108
- in_state = wfun[:in_state].call(self, sstr1, sstr2)
119
+ recvs += 1
109
120
 
110
- recvs += 1
121
+ break if in_state || recvs >= cycles
111
122
 
112
- break if in_state || recvs >= cycles
123
+ sleep stime
124
+ end
113
125
 
114
- sleep stime
126
+ in_state
115
127
  end
116
128
 
117
- in_state
118
129
  end
119
130
 
120
131
  end
@@ -124,6 +135,7 @@ end
124
135
  #
125
136
  # rubocop:disable Style/ClassAndModuleChildren
126
137
  module OpenNebula::WaitExt
138
+
127
139
  # Wait classes and the name published in ZMQ/STATE
128
140
  WAIT = {
129
141
  OpenNebula::Host => {
@@ -176,7 +188,7 @@ module OpenNebula::WaitExt
176
188
  },
177
189
 
178
190
  :in_state => lambda {|o, s1, s2|
179
- obj_s1 = Integer(o['STATE'])
191
+ obj_s1 = Integer(o['STATE'])
180
192
  inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1)
181
193
 
182
194
  obj_s2 = Integer(o['LCM_STATE'])
@@ -203,13 +215,15 @@ module OpenNebula::WaitExt
203
215
  wait?(obj)
204
216
 
205
217
  class << obj
206
- begin
207
- require 'ffi-rzmq'
208
218
 
209
- include OpenNebula::WaitExtEvent
210
- rescue LoadError
211
- include OpenNebula::WaitExtPolling
212
- end
219
+ begin
220
+ require 'ffi-rzmq'
221
+
222
+ include OpenNebula::WaitExtEvent
223
+ rescue LoadError
224
+ include OpenNebula::WaitExtPolling
225
+ end
226
+
213
227
  end
214
228
 
215
229
  super
@@ -31,7 +31,15 @@ module OpenNebula
31
31
  :delete => "zone.delete",
32
32
  :addserver => "zone.addserver",
33
33
  :delserver => "zone.delserver",
34
- :resetserver => "zone.resetserver"
34
+ :resetserver => "zone.resetserver",
35
+ :enable => "zone.enable"
36
+ }
37
+
38
+ ZONE_STATES=%w{ENABLED DISABLED}
39
+
40
+ SHORT_ZONE_STATES={
41
+ "ENABLED" => "on",
42
+ "DISABLED" => "off"
35
43
  }
36
44
 
37
45
  # Creates a Zone description with just its identifier
@@ -179,6 +187,37 @@ module OpenNebula
179
187
  return call(ZONE_METHODS[:resetserver], @pe_id, server_id)
180
188
  end
181
189
 
190
+ # Enable zone
191
+ #
192
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
193
+ # otherwise
194
+ def enable()
195
+ return call(ZONE_METHODS[:enable], @pe_id, true)
196
+ end
197
+
198
+ # Disable zone, only readonly commands can be executed in disabled
199
+ # state
200
+ #
201
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
202
+ # otherwise
203
+ def disable()
204
+ return call(ZONE_METHODS[:enable], @pe_id, false)
205
+ end
206
+
207
+ #######################################################################
208
+ # Helpers to get Zone information
209
+ #######################################################################
210
+
211
+ # Returns the state of the Zone (numeric value)
212
+ def state
213
+ self['STATE'].to_i
214
+ end
215
+
216
+ # Returns the state of the Zone (string value)
217
+ def state_str
218
+ ZONE_STATES[state]
219
+ end
220
+
182
221
  private
183
222
 
184
223
  # These methods adds elements to the given node of the zone
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.0.2'
80
+ VERSION = '6.2.0'
81
81
  end
@@ -45,16 +45,7 @@ module OpenNebula
45
45
 
46
46
  # This function is used to pass error message to the mad
47
47
  def self.error_message(message)
48
- STDERR.puts format_error_message(message)
49
- end
50
-
51
- #This function formats an error message for OpenNebula
52
- def self.format_error_message(message)
53
- error_str = "ERROR MESSAGE --8<------\n"
54
- error_str << message
55
- error_str << "\nERROR MESSAGE ------>8--"
56
-
57
- return error_str
48
+ STDERR.puts message
58
49
  end
59
50
 
60
51
  def self.is_disk?(arg)
@@ -133,19 +133,10 @@ end
133
133
  # Helper functions #
134
134
  # ---------------------------------------------------------------------------- #
135
135
 
136
- def error_message(message)
137
- error_str = "ERROR MESSAGE --8<------\n"
138
- error_str << message
139
- error_str << "\nERROR MESSAGE ------>8--"
140
-
141
- error_str
142
- end
143
-
144
136
  def check_valid(parameter, label)
145
137
  return unless parameter.nil? || parameter.empty?
146
138
 
147
- STDERR.puts error_message("The parameter '#{label}'\
148
- is required for this action.")
139
+ STDERR.puts "The parameter '#{label}' is required for this action."
149
140
  exit(-1)
150
141
  end
151
142
 
@@ -369,9 +369,11 @@ module VCenterDriver
369
369
  error_msg = "\nError: #{e.message}\n"
370
370
  error_msg << "#{e.backtrace}\n" \
371
371
  if VCenterDriver::CONFIG[:debug_information]
372
- STDOUT.puts error_msg
372
+ STDERR.puts error_msg
373
+ raise_error = true
373
374
  ensure
374
375
  vi_client.close_connection if vi_client
376
+ raise if raise_error
375
377
  end
376
378
  end
377
379
 
@@ -1090,14 +1090,22 @@ end
1090
1090
  #
1091
1091
  # @return [Hash ("String" => self.Nic)] Model representation of nics
1092
1092
  def info_nics
1093
+ keep_mac_on_imported = false
1094
+ keep_mac_on_imported = CONFIG[:keep_mac_on_imported] \
1095
+ unless CONFIG[:keep_mac_on_imported].nil?
1096
+
1093
1097
  @nics = { :macs => {} }
1094
1098
 
1095
1099
  vc_nics = vcenter_nics_list
1096
1100
  one_nics = one_nics_get
1097
1101
 
1098
1102
  one_nics.each do |one_nic|
1099
- index = one_nic['NIC_ID']
1100
- mac = one_nic['MAC']
1103
+ index = one_nic['NIC_ID']
1104
+ if keep_mac_on_imported && one_nic['MAC_IMPORTED']
1105
+ mac = one_nic['MAC_IMPORTED']
1106
+ else
1107
+ mac = one_nic['MAC']
1108
+ end
1101
1109
  vc_dev = query_nic(mac, vc_nics)
1102
1110
 
1103
1111
  if vc_dev
@@ -2418,10 +2426,10 @@ end
2418
2426
  # Adding a new disk in newer vSphere versions
2419
2427
  # automatically cleans all system snapshots
2420
2428
  # https://github.com/OpenNebula/one/issues/5409
2421
- if snapshots? or one_snapshots?
2422
- error_message = 'Existing sytem snapshots, cannot change disks. '
2423
- error_message << 'Please remove all snapshots and try again.'
2424
- raise error_message
2429
+ if snapshots? || one_snapshots?
2430
+ error_msg = 'Existing sytem snapshots, cannot change disks. '
2431
+ error_msg << 'Please remove all snapshots and try again.'
2432
+ raise error_message
2425
2433
  end
2426
2434
 
2427
2435
  spec_hash = {}
@@ -2605,10 +2613,10 @@ end
2605
2613
  def detach_disk(disk)
2606
2614
  return unless disk.exists?
2607
2615
 
2608
- if snapshots? or one_snapshots?
2609
- error_message = 'Existing sytem snapshots, cannot change disks. '
2610
- error_message << 'Please remove all snapshots and try again.'
2611
- raise error_message
2616
+ if snapshots? || one_snapshots?
2617
+ error_message = 'Existing sytem snapshots, cannot change disks'
2618
+ error_message << '. Please remove all snapshots and try again.'
2619
+ raise error_message
2612
2620
  end
2613
2621
 
2614
2622
  spec_hash = {}
@@ -3070,7 +3078,8 @@ end
3070
3078
  # Create a snapshot for the VM
3071
3079
  def create_snapshot(snap_id, snap_name)
3072
3080
  memory_dumps = true
3073
- memory_dumps = CONFIG[:memory_dumps] unless CONFIG[:memory_dumps].nil?
3081
+ memory_dumps = CONFIG[:memory_dumps] \
3082
+ unless CONFIG[:memory_dumps].nil?
3074
3083
 
3075
3084
  snapshot_hash = {
3076
3085
  :name => snap_id,
data/lib/vm_monitor.rb CHANGED
@@ -175,8 +175,6 @@ module VirtualMachineMonitor
175
175
  @monitor[:diskwrbytes] = previous_diskwrbytes +
176
176
  (write_kbpersec * 1024 * refresh_rate).to_i
177
177
  end
178
- # rubocop:enable Naming/VariableName
179
- # rubocop:enable Style/FormatStringToken
180
178
 
181
179
  # Generates a OpenNebula IM Driver valid string with the monitor info
182
180
  def info
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?
@@ -550,6 +550,10 @@ module VCenterDriver
550
550
  net.ipConfig.ipAddress.each do |ip_config|
551
551
  ip = IPAddr.new(ip_config.ipAddress)
552
552
 
553
+ if ip.ipv6? && get_ipv6_prefix(ip.to_s, 10) == 'fe80'
554
+ next
555
+ end
556
+
553
557
  if force
554
558
  ipv4 = ip.to_s if ip.ipv4?
555
559
  ipv6 = ip.to_s if ip.ipv6?
@@ -729,6 +733,9 @@ module VCenterDriver
729
733
  nic, true)
730
734
  network_found.info
731
735
 
736
+ if nic[:mac]
737
+ nic_tmp << "MAC_IMPORTED=\"#{nic[:mac]}\",\n"
738
+ end
732
739
  # This is the existing nic info
733
740
  if nic[:mac] && ipv4.empty? && ipv6.empty?
734
741
  nic_tmp << "MAC=\"#{nic[:mac]}\",\n"
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.0.2
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenNebula
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -223,14 +223,14 @@ 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_pool.rb
227
226
  - lib/opennebula/zone.rb
227
+ - lib/opennebula/zone_pool.rb
228
228
  - lib/opennebula/flow/grammar.rb
229
229
  - lib/opennebula/flow/service_pool.rb
230
+ - lib/opennebula/flow/service_template.rb
230
231
  - lib/opennebula/flow/service_template_ext.rb
231
232
  - lib/opennebula/flow/service_template_pool.rb
232
233
  - lib/opennebula/flow/validator.rb
233
- - lib/opennebula/flow/service_template.rb
234
234
  - lib/opennebula/ldap_auth.rb
235
235
  - lib/opennebula/ldap_auth_spec.rb
236
236
  - lib/opennebula/server_cipher_auth.rb