opennebula 6.6.1 → 6.6.3

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
  SHA256:
3
- metadata.gz: af7eaa43ec35cbc81be2215013a235e6be0ed5b73f4ff4f4b55a21f4d85df635
4
- data.tar.gz: 19a6fd052192ac9d266caea0718a8abb29c1bc1a86624b7162ad6a1dbea5fe0d
3
+ metadata.gz: 885bbb7b22fbe7f2652e00b846dbf5881960a9cd041282d789a669d671a5835f
4
+ data.tar.gz: e7575d6535512ae13e139249ecfb05cac655cd34013176184bf98ce6fc5215dd
5
5
  SHA512:
6
- metadata.gz: af9f1f08ed1e6e43b3d69c1092d45909f8d5b423d801db6efad379d12137d3a36b119db9c7a0da7f7b6d96e9e6e5598043b3d22c5827a3d1b62fdaf082aba010
7
- data.tar.gz: f73c345fd3f1ed0fe33f70cb58d409618c8e875260416457eb8a01d93d2d869b3fd9d8171026be1600fa7b01c440f1c5f0d6aeda7de6b0bc1cda65babfac3917
6
+ metadata.gz: 138d7785b0d1c4dc84df1a862f6a14de05a4156ee44b1bff15752dcb99daab62e9590a776d4bc3d5dcd8c45924c574b0b1a8da1aa16e37626609780811b2e47a
7
+ data.tar.gz: b3ff5aa1bf6ef4ed40f37e77beb6a8e4e11aaa7bbeed6c5643c316cb95f795d0c4792b026478c92298d8e00b584955a9c2970f14eb03257c8316ef9bb886d198
@@ -189,7 +189,7 @@ module DriverExecHelper
189
189
  cfg=file.read
190
190
  end
191
191
 
192
- cfg.split(/\n/).each do |line|
192
+ cfg.split("\n").each do |line|
193
193
  m=line.match(/^([^=]+)=(.*)$/)
194
194
 
195
195
  next unless m
@@ -0,0 +1,111 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2023, OpenNebula Project, OpenNebula Systems #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ # -------------------------------------------------------------------------- #
16
+
17
+ # rubocop:disable Lint/MissingCopEnableDirective
18
+ # rubocop:disable Layout/FirstArgumentIndentation
19
+ # rubocop:disable Layout/FirstHashElementIndentation
20
+ # rubocop:disable Layout/HashAlignment
21
+ # rubocop:disable Layout/HeredocIndentation
22
+ # rubocop:disable Layout/IndentationWidth
23
+ # rubocop:disable Style/HashSyntax
24
+ # rubocop:disable Style/ParallelAssignment
25
+
26
+ require 'CommandManager'
27
+
28
+ # This helper module introduces a common routine that synchronizes
29
+ # the "remotes".
30
+ class HostSyncManager
31
+
32
+ def initialize(one_config = nil)
33
+ one_location = ENV['ONE_LOCATION']&.delete("'")
34
+ if one_location.nil?
35
+ @one_config_path = '/var/lib/one/config'
36
+ @local_scripts_base_path = '/var/lib/one/remotes'
37
+ else
38
+ @one_config_path = one_location + '/var/config'
39
+ @local_scripts_base_path = one_location + '/var/remotes'
40
+ end
41
+
42
+ # Do a simple parsing of the config file unless the values
43
+ # are already provided. NOTE: We don't care about "arrays" here..
44
+ one_config ||= File.read(@one_config_path).lines.each_with_object({}) \
45
+ do |line, object|
46
+ key, value = line.split('=').map(&:strip)
47
+ object[key.upcase] = value
48
+ end
49
+
50
+ @remote_scripts_base_path = one_config['SCRIPTS_REMOTE_DIR']
51
+ @remote_scripts_base_path&.delete!("'")
52
+ end
53
+
54
+ def update_remotes(hostname, logger = nil, copy_method = :rsync, subset = nil)
55
+ sources = '.'
56
+
57
+ if subset && copy_method == :rsync
58
+ # Make sure all files in the subset exist (and are relative).
59
+ subset.each do |path|
60
+ File.realpath path, @local_scripts_base_path
61
+ end
62
+
63
+ sources = subset.join(' ')
64
+ end
65
+
66
+ assemble_cmd = lambda do |steps|
67
+ "exec 2>/dev/null; #{steps.join(' && ')}"
68
+ end
69
+
70
+ case copy_method
71
+ when :ssh
72
+ mkdir_cmd = assemble_cmd.call [
73
+ "rm -rf '#{@remote_scripts_base_path}'/",
74
+ "mkdir -p '#{@remote_scripts_base_path}'/"
75
+ ]
76
+
77
+ sync_cmd = assemble_cmd.call [
78
+ "cd '#{@local_scripts_base_path}'/",
79
+ "scp -rp #{sources} " \
80
+ "'#{hostname}':'#{@remote_scripts_base_path}'/"
81
+ ]
82
+ when :rsync
83
+ mkdir_cmd = assemble_cmd.call [
84
+ "mkdir -p '#{@remote_scripts_base_path}'/"
85
+ ]
86
+
87
+ sync_cmd = assemble_cmd.call [
88
+ "cd '#{@local_scripts_base_path}'/",
89
+ "rsync -LRaz --delete #{sources} " \
90
+ "'#{hostname}':'#{@remote_scripts_base_path}'/"
91
+ ]
92
+ end
93
+
94
+ cmd = SSHCommand.run(mkdir_cmd, hostname, logger)
95
+ return cmd.code if error?(cmd)
96
+
97
+ cmd = LocalCommand.run(sync_cmd, logger)
98
+ return cmd.code if error?(cmd)
99
+
100
+ 0
101
+ end
102
+
103
+ def error?(cmd)
104
+ return false if cmd.code == 0
105
+
106
+ STDERR.puts cmd.stderr
107
+ STDOUT.puts cmd.stdout
108
+ true
109
+ end
110
+
111
+ end
@@ -55,7 +55,8 @@ class VirtualMachineDriver < OpenNebulaDriver
55
55
  :update_conf => "UPDATECONF",
56
56
  :resize => "RESIZE",
57
57
  :backup => "BACKUP",
58
- :update_nic => "UPDATENIC"
58
+ :update_nic => "UPDATENIC",
59
+ :backup_cancel=> "BACKUPCANCEL"
59
60
  }
60
61
 
61
62
  POLL_ATTRIBUTE = OpenNebula::VirtualMachine::Driver::POLL_ATTRIBUTE
@@ -104,6 +105,7 @@ class VirtualMachineDriver < OpenNebulaDriver
104
105
  register_action(ACTION[:resize].to_sym, method("resize"))
105
106
  register_action(ACTION[:backup].to_sym, method("backup"))
106
107
  register_action(ACTION[:update_nic].to_sym, method("update_nic"))
108
+ register_action(ACTION[:backup_cancel].to_sym, method("backup_cancel"))
107
109
  end
108
110
 
109
111
  # Decodes the encoded XML driver message received from the core
@@ -248,6 +250,11 @@ class VirtualMachineDriver < OpenNebulaDriver
248
250
  send_message(ACTION[:update_nic],RESULT[:failure],id,error)
249
251
  end
250
252
 
253
+ def backup_cancel(id, drv_message)
254
+ error = "Action not implemented by driver #{self.class}"
255
+ send_message(ACTION[:backup_cancel],RESULT[:failure],id,error)
256
+ end
257
+
251
258
  private
252
259
 
253
260
  # Interface to handle the pending events from the ActionManager Interface
@@ -51,7 +51,7 @@ end
51
51
  module CloudClient
52
52
 
53
53
  # OpenNebula version
54
- VERSION = '6.6.1'
54
+ VERSION = '6.6.3'
55
55
 
56
56
  # #########################################################################
57
57
  # Default location for the authentication file
data/lib/host.rb CHANGED
@@ -352,7 +352,7 @@ module VCenterDriver
352
352
  str_info << 'USEDMEMORY=' << (total_mem - free_mem).to_s << "\n"
353
353
 
354
354
  # DRS enabled
355
- str_info << 'VCENTER_DRS=' << drs_enabled.to_s << "\n"
355
+ str_info << 'VCENTER_DRS=' << drs_enabled.to_s << "\n"
356
356
 
357
357
  # HA enabled
358
358
  str_info << 'VCENTER_HA=' << ha_enabled.to_s << "\n"
@@ -323,6 +323,9 @@ module OpenNebula
323
323
 
324
324
  template['start_time'] = Integer(Time.now)
325
325
 
326
+ # Replace $attibute by the corresponding value
327
+ resolve_attributes(template)
328
+
326
329
  super(template.to_json, template['name'])
327
330
  end
328
331
 
@@ -660,7 +663,7 @@ module OpenNebula
660
663
  end if deploy
661
664
 
662
665
  # Replace $attibute by the corresponding value
663
- resolve_attributes(body)
666
+ resolve_networks(body)
664
667
 
665
668
  # @body = template.to_hash
666
669
 
@@ -784,31 +787,49 @@ module OpenNebula
784
787
  end
785
788
 
786
789
  # rubocop:disable Layout/LineLength
790
+ def resolve_networks(template)
791
+ template['roles'].each do |role|
792
+ next unless role['vm_template_contents']
793
+
794
+ # $CUSTOM1_VAR Any word character
795
+ # (letter, number, underscore)
796
+ role['vm_template_contents'].scan(/\$(\w+)/).each do |key|
797
+ net = template['networks_values'].find {|att| att.key? key[0] }
798
+
799
+ next if net.nil?
800
+
801
+ role['vm_template_contents'].gsub!(
802
+ '$'+key[0],
803
+ net[net.keys[0]]['id'].to_s
804
+ )
805
+ end
806
+ end
807
+ end
808
+
787
809
  def resolve_attributes(template)
788
810
  template['roles'].each do |role|
789
811
  if role['vm_template_contents']
790
812
  # $CUSTOM1_VAR Any word character
791
813
  # (letter, number, underscore)
792
814
  role['vm_template_contents'].scan(/\$(\w+)/).each do |key|
793
- # Check if $ var value is in custom_attrs_values
794
- if !template['custom_attrs_values'].nil? &&
795
- template['custom_attrs_values'].key?(key[0])
815
+ # Check if $ var value is in custom_attrs_values within the role
816
+ if !role['custom_attrs_values'].nil? && \
817
+ role['custom_attrs_values'].key?(key[0])
796
818
  role['vm_template_contents'].gsub!(
797
819
  '$'+key[0],
798
- template['custom_attrs_values'][key[0]]
820
+ role['custom_attrs_values'][key[0]]
799
821
  )
800
822
  next
801
823
  end
802
824
 
803
- # Check if $ var value is in networks
804
- net = template['networks_values']
805
- .find {|att| att.key? key[0] }
825
+ # Check if $ var value is in custom_attrs_values
806
826
 
807
- next if net.nil?
827
+ next unless !template['custom_attrs_values'].nil? && \
828
+ template['custom_attrs_values'].key?(key[0])
808
829
 
809
830
  role['vm_template_contents'].gsub!(
810
831
  '$'+key[0],
811
- net[net.keys[0]]['id'].to_s
832
+ template['custom_attrs_values'][key[0]]
812
833
  )
813
834
  end
814
835
  end
@@ -42,6 +42,16 @@ module OpenNebula
42
42
  :type => :string,
43
43
  :required => false
44
44
  },
45
+ 'custom_attrs' => {
46
+ :type => :object,
47
+ :properties => {},
48
+ :required => false
49
+ },
50
+ 'custom_attrs_values' => {
51
+ :type => :object,
52
+ :properties => {},
53
+ :required => false
54
+ },
45
55
  'parents' => {
46
56
  :type => :array,
47
57
  :items => {
@@ -487,7 +497,7 @@ module OpenNebula
487
497
  instantiate_template = JSON.parse(@body.to_json)
488
498
  else
489
499
  instantiate_template = JSON.parse(@body.to_json)
490
- .merge(merge_template)
500
+ .deep_merge(merge_template)
491
501
  end
492
502
 
493
503
  begin
@@ -17,11 +17,13 @@
17
17
  require 'opennebula/pool'
18
18
 
19
19
  module OpenNebula
20
+
20
21
  # The PoolElement Class represents a generic element of a Pool in
21
22
  # XML format
22
23
  class PoolElement < XMLElement
23
24
 
24
- protected
25
+ protected
26
+
25
27
  # node:: _XML_is a XML element that represents the Pool element
26
28
  # client:: _Client_ represents a XML-RPC connection
27
29
  def initialize(node, client)
@@ -49,12 +51,12 @@ module OpenNebula
49
51
  # @return [nil, OpenNebula::Error] nil in case of success, Error
50
52
  # otherwise
51
53
  def call(xml_method, *args)
52
- return Error.new('ID not defined') if !@pe_id
54
+ return Error.new('ID not defined') unless @pe_id
53
55
 
54
56
  rc = @client.call(xml_method, *args)
55
- rc = nil if !OpenNebula.is_error?(rc)
57
+ rc = nil unless OpenNebula.is_error?(rc)
56
58
 
57
- return rc
59
+ rc
58
60
  end
59
61
 
60
62
  # Calls to the corresponding info method to retreive the element
@@ -66,19 +68,19 @@ module OpenNebula
66
68
  # @return [nil, OpenNebula::Error] nil in case of success, Error
67
69
  # otherwise
68
70
  def info(xml_method, root_element, decrypt = false)
69
- return Error.new('ID not defined') if !@pe_id
71
+ return Error.new('ID not defined') unless @pe_id
70
72
 
71
73
  rc = @client.call(xml_method, @pe_id, decrypt)
72
74
 
73
75
  if !OpenNebula.is_error?(rc)
74
76
  initialize_xml(rc, root_element)
75
- rc = nil
77
+ rc = nil
76
78
 
77
79
  @pe_id = self['ID'].to_i if self['ID']
78
80
  @name = self['NAME'] if self['NAME']
79
81
  end
80
82
 
81
- return rc
83
+ rc
82
84
  end
83
85
 
84
86
  # Calls to the corresponding allocate method to create a new element
@@ -97,7 +99,7 @@ module OpenNebula
97
99
  rc = nil
98
100
  end
99
101
 
100
- return rc
102
+ rc
101
103
  end
102
104
 
103
105
  # Calls to the corresponding update method to modify
@@ -111,10 +113,10 @@ module OpenNebula
111
113
  # otherwise
112
114
  def update(xml_method, new_template, *args)
113
115
  if new_template.nil?
114
- return Error.new("Wrong argument", Error::EXML_RPC_CALL)
116
+ return Error.new('Wrong argument', Error::EXML_RPC_CALL)
115
117
  end
116
118
 
117
- return call(xml_method, @pe_id, new_template, *args)
119
+ call(xml_method, @pe_id, new_template, *args)
118
120
  end
119
121
 
120
122
  # Calls to the corresponding delete method to remove this element
@@ -125,7 +127,7 @@ module OpenNebula
125
127
  # @return [nil, OpenNebula::Error] nil in case of success, Error
126
128
  # otherwise
127
129
  def delete(xml_method)
128
- return call(xml_method,@pe_id)
130
+ call(xml_method, @pe_id)
129
131
  end
130
132
 
131
133
  # Calls to the corresponding chown method to modify
@@ -138,7 +140,7 @@ module OpenNebula
138
140
  # @return [nil, OpenNebula::Error] nil in case of success, Error
139
141
  # otherwise
140
142
  def chown(xml_method, uid, gid)
141
- return call(xml_method, @pe_id, uid, gid)
143
+ call(xml_method, @pe_id, uid, gid)
142
144
  end
143
145
 
144
146
  # Calls to the corresponding chmod method to modify
@@ -149,7 +151,7 @@ module OpenNebula
149
151
  #
150
152
  # @return [nil, OpenNebula::Error] nil in case of success, Error
151
153
  # otherwise
152
- def chmod_octet(xml_method, octet)
154
+ def chmod_octet(_xml_method, octet)
153
155
  owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
154
156
  owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
155
157
  owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
@@ -161,7 +163,7 @@ module OpenNebula
161
163
  other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0
162
164
 
163
165
  chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
164
- other_m, other_a)
166
+ other_m, other_a)
165
167
  end
166
168
 
167
169
  # Calls to the corresponding chmod method to modify
@@ -173,13 +175,12 @@ module OpenNebula
173
175
  # @return [nil, OpenNebula::Error] nil in case of success, Error
174
176
  # otherwise
175
177
  def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
176
- other_m, other_a)
177
- return call(xml_method, @pe_id, owner_u, owner_m,
178
- owner_a, group_u, group_m, group_a, other_u,
179
- other_m, other_a)
178
+ other_m, other_a)
179
+ call(xml_method, @pe_id, owner_u, owner_m,
180
+ owner_a, group_u, group_m, group_a, other_u,
181
+ other_m, other_a)
180
182
  end
181
183
 
182
-
183
184
  # Retrieves this Element's monitoring data from OpenNebula
184
185
  #
185
186
  # @param [String] xml_method the name of the XML-RPC method
@@ -189,28 +190,27 @@ module OpenNebula
189
190
  # @return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with
190
191
  # the requested xpath expressions, and an Array of [timestamp, value].
191
192
  def monitoring(xml_method, xpaths)
192
- return Error.new('ID not defined') if !@pe_id
193
+ return Error.new('ID not defined') unless @pe_id
193
194
 
194
195
  rc = @client.call(xml_method, @pe_id)
195
196
 
196
- if ( OpenNebula.is_error?(rc) )
197
+ if OpenNebula.is_error?(rc)
197
198
  return rc
198
199
  end
199
200
 
200
201
  xmldoc = XMLElement.new
201
202
  xmldoc.initialize_xml(rc, 'MONITORING_DATA')
202
203
 
203
-
204
- return OpenNebula.process_monitoring(xmldoc, @pe_id, xpaths)
204
+ OpenNebula.process_monitoring(xmldoc, @pe_id, xpaths)
205
205
  end
206
206
 
207
- public
207
+ public
208
208
 
209
209
  # Creates new element specifying its id
210
210
  # id:: identifyier of the element
211
211
  # client:: initialized OpenNebula::Client object
212
- def self.new_with_id(id, client=nil)
213
- self.new(self.build_xml(id), client)
212
+ def self.new_with_id(id, client = nil)
213
+ new(build_xml(id), client)
214
214
  end
215
215
 
216
216
  # Returns element identifier
@@ -221,16 +221,14 @@ module OpenNebula
221
221
 
222
222
  # Gets element name
223
223
  # [return] _String_ the PoolElement name
224
- def name
225
- @name
226
- end
224
+ attr_reader :name
227
225
 
228
226
  # DO NOT USE - ONLY REXML BACKEND
229
227
  def to_str
230
- str = ""
231
- REXML::Formatters::Pretty.new(1).write(@xml,str)
228
+ str = ''
229
+ REXML::Formatters::Pretty.new(1).write(@xml, str)
232
230
 
233
- return str
231
+ str
234
232
  end
235
233
 
236
234
  # Replace the xml pointed by xpath using a Hash object
@@ -240,18 +238,19 @@ module OpenNebula
240
238
  # @param [Hash] options object containing pair key-value
241
239
  #
242
240
  # @returns the new xml representation
243
- def replace(opts, xpath = "TEMPLATE")
244
- if self[xpath]
245
- opts.each do |att, value|
246
- xpath_u = xpath+"/#{att}"
247
- docs = retrieve_xmlelements(xpath_u)
248
- if docs.size == 1
249
- docs[0].set_content(value)
250
- end
241
+ def replace(opts, xpath = 'TEMPLATE')
242
+ return unless self[xpath]
243
+
244
+ opts.each do |att, value|
245
+ xpath_u = xpath+"/#{att}"
246
+ docs = retrieve_xmlelements(xpath_u)
247
+ if docs.size == 1
248
+ docs[0].set_content(value)
251
249
  end
252
- update(template_like_str(xpath))
253
250
  end
251
+ update(template_like_str(xpath))
254
252
  end
253
+
255
254
  end
256
255
 
257
256
  # Processes the monitoring data in XML returned by OpenNebula
@@ -266,20 +265,22 @@ module OpenNebula
266
265
  def self.process_monitoring(xmldoc, oid, xpath_expressions)
267
266
  hash = {}
268
267
  timestamps = xmldoc.retrieve_elements(
269
- "/MONITORING_DATA/MONITORING[ID=#{oid}]/TIMESTAMP")
268
+ "/MONITORING_DATA/MONITORING[ID=#{oid}]/TIMESTAMP"
269
+ )
270
270
 
271
- xpath_expressions.each { |xpath|
271
+ xpath_expressions.each do |xpath|
272
272
  xpath_values = xmldoc.retrieve_elements(
273
- "/MONITORING_DATA/MONITORING[ID=#{oid}]/#{xpath}")
273
+ "/MONITORING_DATA/MONITORING[ID=#{oid}]/#{xpath}"
274
+ )
274
275
 
275
- if ( xpath_values.nil? )
276
+ if xpath_values.nil?
276
277
  hash[xpath] = []
277
278
  else
278
279
  hash[xpath] = timestamps.zip(xpath_values)
279
280
  end
280
- }
281
+ end
281
282
 
282
- return hash
283
+ hash
283
284
  end
284
285
 
285
286
  end