opennebula 6.6.2 → 6.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/DriverExecHelper.rb +1 -1
- data/lib/HostSyncManager.rb +111 -0
- data/lib/cloud/CloudClient.rb +1 -1
- data/lib/host.rb +1 -1
- data/lib/opennebula/pool_element.rb +48 -47
- data/lib/opennebula/virtual_machine.rb +295 -298
- data/lib/opennebula.rb +1 -1
- data/lib/virtual_wire.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 885bbb7b22fbe7f2652e00b846dbf5881960a9cd041282d789a669d671a5835f
|
4
|
+
data.tar.gz: e7575d6535512ae13e139249ecfb05cac655cd34013176184bf98ce6fc5215dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 138d7785b0d1c4dc84df1a862f6a14de05a4156ee44b1bff15752dcb99daab62e9590a776d4bc3d5dcd8c45924c574b0b1a8da1aa16e37626609780811b2e47a
|
7
|
+
data.tar.gz: b3ff5aa1bf6ef4ed40f37e77beb6a8e4e11aaa7bbeed6c5643c316cb95f795d0c4792b026478c92298d8e00b584955a9c2970f14eb03257c8316ef9bb886d198
|
data/lib/DriverExecHelper.rb
CHANGED
@@ -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
|
data/lib/cloud/CloudClient.rb
CHANGED
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='
|
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"
|
@@ -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
|
-
|
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')
|
54
|
+
return Error.new('ID not defined') unless @pe_id
|
53
55
|
|
54
56
|
rc = @client.call(xml_method, *args)
|
55
|
-
rc = nil
|
57
|
+
rc = nil unless OpenNebula.is_error?(rc)
|
56
58
|
|
57
|
-
|
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')
|
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
|
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
|
-
|
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
|
-
|
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(
|
116
|
+
return Error.new('Wrong argument', Error::EXML_RPC_CALL)
|
115
117
|
end
|
116
118
|
|
117
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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')
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
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
|
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
|
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
|
-
|
283
|
+
hash
|
283
284
|
end
|
284
285
|
|
285
286
|
end
|