opennebula 6.10.3 → 6.99.85.pre
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 +3 -3
- data/lib/models/role.rb +349 -823
- data/lib/models/service.rb +156 -80
- data/lib/models/vmrole.rb +703 -0
- data/lib/models/vrrole.rb +284 -0
- data/lib/models.rb +3 -1
- data/lib/opennebula/acl.rb +1 -1
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/backupjob.rb +1 -1
- data/lib/opennebula/backupjob_pool.rb +1 -1
- data/lib/opennebula/client.rb +1 -1
- data/lib/opennebula/cluster.rb +45 -2
- data/lib/opennebula/cluster_pool.rb +1 -1
- data/lib/opennebula/datastore.rb +1 -1
- data/lib/opennebula/datastore_pool.rb +1 -1
- data/lib/opennebula/document.rb +1 -1
- data/lib/opennebula/document_json.rb +1 -1
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +1 -1
- data/lib/opennebula/flow/grammar.rb +1 -1
- data/lib/opennebula/flow/service_pool.rb +1 -1
- data/lib/opennebula/flow/service_template.rb +353 -97
- data/lib/opennebula/flow/service_template_ext.rb +3 -3
- data/lib/opennebula/flow/service_template_pool.rb +1 -1
- data/lib/opennebula/flow/validator.rb +458 -410
- data/lib/opennebula/flow.rb +1 -1
- data/lib/opennebula/group.rb +1 -1
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/hook.rb +1 -1
- data/lib/opennebula/hook_log.rb +1 -1
- data/lib/opennebula/hook_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -60
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +1 -1
- data/lib/opennebula/image_pool.rb +1 -1
- data/lib/opennebula/ldap_auth.rb +1 -1
- data/lib/opennebula/ldap_auth_spec.rb +1 -1
- data/lib/opennebula/lockable_ext.rb +1 -1
- data/lib/opennebula/marketplace.rb +1 -1
- data/lib/opennebula/marketplace_pool.rb +1 -1
- data/lib/opennebula/marketplaceapp.rb +1 -1
- data/lib/opennebula/marketplaceapp_ext.rb +14 -211
- data/lib/opennebula/marketplaceapp_pool.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +11 -9
- data/lib/opennebula/pool.rb +1 -1
- data/lib/opennebula/pool_element.rb +1 -1
- data/lib/opennebula/security_group.rb +1 -1
- data/lib/opennebula/security_group_pool.rb +1 -1
- data/lib/opennebula/server_cipher_auth.rb +1 -1
- data/lib/opennebula/server_x509_auth.rb +1 -1
- data/lib/opennebula/ssh_auth.rb +1 -1
- data/lib/opennebula/system.rb +1 -1
- data/lib/opennebula/template.rb +1 -1
- data/lib/opennebula/template_ext.rb +1 -1
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +1 -1
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/utils.rb +2 -2
- data/lib/opennebula/vdc.rb +1 -1
- data/lib/opennebula/vdc_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +3 -12
- data/lib/opennebula/virtual_machine_ext.rb +2 -31
- data/lib/opennebula/virtual_machine_pool.rb +1 -1
- data/lib/opennebula/virtual_network.rb +1 -1
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/virtual_router.rb +1 -1
- data/lib/opennebula/virtual_router_pool.rb +1 -1
- data/lib/opennebula/vm_group.rb +1 -1
- data/lib/opennebula/vm_group_pool.rb +1 -1
- data/lib/opennebula/vntemplate.rb +1 -1
- data/lib/opennebula/vntemplate_pool.rb +1 -1
- data/lib/opennebula/wait_ext.rb +1 -1
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +2 -2
- data/lib/opennebula/xml_pool.rb +1 -1
- data/lib/opennebula/xml_utils.rb +1 -1
- data/lib/opennebula/zone.rb +1 -1
- data/lib/opennebula/zone_pool.rb +1 -1
- data/lib/opennebula.rb +2 -2
- metadata +6 -67
- data/lib/ActionManager.rb +0 -280
- data/lib/CommandManager.rb +0 -328
- data/lib/DriverExecHelper.rb +0 -213
- data/lib/HostSyncManager.rb +0 -111
- data/lib/OpenNebulaDriver.rb +0 -223
- data/lib/VirtualMachineDriver.rb +0 -404
- data/lib/datacenter.rb +0 -1319
- data/lib/datastore.rb +0 -1049
- data/lib/distributed_firewall.rb +0 -293
- data/lib/file_helper.rb +0 -374
- data/lib/host.rb +0 -1518
- data/lib/logical_port.rb +0 -50
- data/lib/logical_switch.rb +0 -77
- data/lib/memoize.rb +0 -74
- data/lib/network.rb +0 -705
- data/lib/nsx_client.rb +0 -157
- data/lib/nsx_component.rb +0 -28
- data/lib/nsx_constants.rb +0 -162
- data/lib/nsx_driver.rb +0 -91
- data/lib/nsx_error.rb +0 -77
- data/lib/nsx_rule.rb +0 -206
- data/lib/nsxt_client.rb +0 -189
- data/lib/nsxt_dfw.rb +0 -196
- data/lib/nsxt_logical_port.rb +0 -94
- data/lib/nsxt_rule.rb +0 -188
- data/lib/nsxt_tz.rb +0 -38
- data/lib/nsxv_client.rb +0 -189
- data/lib/nsxv_dfw.rb +0 -202
- data/lib/nsxv_logical_port.rb +0 -107
- data/lib/nsxv_rule.rb +0 -172
- data/lib/nsxv_tz.rb +0 -41
- data/lib/opaque_network.rb +0 -134
- data/lib/rest_client.rb +0 -191
- data/lib/scripts_common.rb +0 -176
- data/lib/transport_zone.rb +0 -43
- data/lib/vcenter_driver.rb +0 -152
- data/lib/vcenter_importer.rb +0 -626
- data/lib/vi_client.rb +0 -273
- data/lib/vi_helper.rb +0 -328
- data/lib/virtual_machine.rb +0 -3574
- data/lib/virtual_wire.rb +0 -158
- data/lib/vm_device.rb +0 -80
- data/lib/vm_disk.rb +0 -202
- data/lib/vm_folder.rb +0 -69
- data/lib/vm_helper.rb +0 -30
- data/lib/vm_monitor.rb +0 -305
- data/lib/vm_nic.rb +0 -70
- data/lib/vm_template.rb +0 -2112
- data/lib/vmm_importer.rb +0 -165
data/lib/vi_client.rb
DELETED
@@ -1,273 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2024, 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
|
-
require 'openssl'
|
17
|
-
require 'yaml'
|
18
|
-
|
19
|
-
##############################################################################
|
20
|
-
# Module VCenterDriver
|
21
|
-
##############################################################################
|
22
|
-
module VCenterDriver
|
23
|
-
|
24
|
-
##########################################################################
|
25
|
-
# Class VIClient
|
26
|
-
##########################################################################
|
27
|
-
class VIClient
|
28
|
-
|
29
|
-
attr_accessor :vim
|
30
|
-
attr_accessor :rp
|
31
|
-
attr_accessor :vc_name
|
32
|
-
attr_accessor :ccr_ref
|
33
|
-
|
34
|
-
def initialize(opts, host_id = -1)
|
35
|
-
opts = { :insecure => true }.merge(opts)
|
36
|
-
@host_id = host_id
|
37
|
-
@vim = RbVmomi::VIM.connect(opts)
|
38
|
-
@vc_name = opts[:host] if opts[:host]
|
39
|
-
|
40
|
-
# Get ccr and get rp
|
41
|
-
@ccr_ref = opts.delete(:ccr)
|
42
|
-
|
43
|
-
return unless @ccr_ref
|
44
|
-
|
45
|
-
ccr = RbVmomi::VIM::ClusterComputeResource.new(@vim, @ccr_ref)
|
46
|
-
|
47
|
-
# Get ref for rp
|
48
|
-
|
49
|
-
return unless ccr
|
50
|
-
|
51
|
-
rp = opts.delete(:rp)
|
52
|
-
|
53
|
-
return unless rp
|
54
|
-
|
55
|
-
rp_list = get_resource_pools(ccr)
|
56
|
-
rp_ref =
|
57
|
-
rp_list
|
58
|
-
.select {|r| r[:name] == rp }.first[:ref] rescue nil
|
59
|
-
@rp = RbVmomi::VIM::ResourcePool(@vim, rp_ref) if rp_ref
|
60
|
-
end
|
61
|
-
|
62
|
-
def rp_confined?
|
63
|
-
!!@rp
|
64
|
-
end
|
65
|
-
|
66
|
-
def host_credentials(one_client)
|
67
|
-
raise 'no host id defined!' if @host_id == -1
|
68
|
-
|
69
|
-
host =
|
70
|
-
OpenNebula::Host
|
71
|
-
.new_with_id(
|
72
|
-
@host_id,
|
73
|
-
one_client
|
74
|
-
)
|
75
|
-
rc = host.info
|
76
|
-
if OpenNebula.is_error?(rc)
|
77
|
-
raise "Could not get host info \
|
78
|
-
for ID: #{@host_id} - #{rc.message}"
|
79
|
-
end
|
80
|
-
|
81
|
-
{ :pass => host['TEMPLATE/VCENTER_PASSWORD'],
|
82
|
-
:user => host['TEMPLATE/VCENTER_USER'],
|
83
|
-
:host => @vc_name }
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_resource_pools(ccr, rp = nil, parent_prefix = '', rp_array = [])
|
87
|
-
current_rp = ''
|
88
|
-
|
89
|
-
if !rp
|
90
|
-
rp = ccr.resourcePool
|
91
|
-
else
|
92
|
-
if !parent_prefix.empty?
|
93
|
-
current_rp << parent_prefix
|
94
|
-
current_rp << '/'
|
95
|
-
end
|
96
|
-
current_rp << rp.name
|
97
|
-
end
|
98
|
-
|
99
|
-
if rp.resourcePool.empty?
|
100
|
-
rp_info = {}
|
101
|
-
rp_info[:name] = current_rp
|
102
|
-
rp_info[:ref] = rp._ref
|
103
|
-
rp_array << rp_info
|
104
|
-
else
|
105
|
-
rp.resourcePool.each do |child_rp|
|
106
|
-
get_resource_pools(ccr, child_rp, current_rp, rp_array)
|
107
|
-
end
|
108
|
-
rp_info = {}
|
109
|
-
rp_info[:name] = current_rp
|
110
|
-
rp_info[:ref] = rp._ref
|
111
|
-
rp_array << rp_info unless current_rp.empty?
|
112
|
-
end
|
113
|
-
|
114
|
-
rp_array
|
115
|
-
end
|
116
|
-
|
117
|
-
def close_connection
|
118
|
-
@vim.close
|
119
|
-
end
|
120
|
-
|
121
|
-
# @return RbVmomi::VIM::<type> objects
|
122
|
-
def self.get_entities(folder, type, entities = [])
|
123
|
-
if folder == []
|
124
|
-
# rubocop:disable Style/ReturnNil
|
125
|
-
return nil
|
126
|
-
# rubocop:enable Style/ReturnNil
|
127
|
-
end
|
128
|
-
|
129
|
-
folder.childEntity.each do |child|
|
130
|
-
the_name, _junk = child.to_s.split('(')
|
131
|
-
case the_name
|
132
|
-
when 'Folder'
|
133
|
-
get_entities(child, type, entities)
|
134
|
-
when type
|
135
|
-
entities.push(child)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
entities
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.new_from_host(host_id, client = nil)
|
143
|
-
client = OpenNebula::Client.new if client.nil?
|
144
|
-
host = OpenNebula::Host.new_with_id(host_id, client)
|
145
|
-
rc = host.info(true)
|
146
|
-
if OpenNebula.is_error?(rc)
|
147
|
-
raise "Could not get host info for \
|
148
|
-
ID: #{host_id} - #{rc.message}"
|
149
|
-
end
|
150
|
-
|
151
|
-
connection = {
|
152
|
-
:host => host['TEMPLATE/VCENTER_HOST'],
|
153
|
-
:user => host['TEMPLATE/VCENTER_USER'],
|
154
|
-
:rp => host['TEMPLATE/VCENTER_RESOURCE_POOL'],
|
155
|
-
:ccr => host['TEMPLATE/VCENTER_CCR_REF'],
|
156
|
-
:password => host['TEMPLATE/VCENTER_PASSWORD']
|
157
|
-
}
|
158
|
-
|
159
|
-
vc_port = host['TEMPLATE/VCENTER_PORT']
|
160
|
-
connection[:port] = vc_port unless vc_port.nil?
|
161
|
-
|
162
|
-
new(connection, host_id)
|
163
|
-
end
|
164
|
-
|
165
|
-
def self.new_from_datastore(datastore_id)
|
166
|
-
client = OpenNebula::Client.new
|
167
|
-
datastore =
|
168
|
-
OpenNebula::Datastore
|
169
|
-
.new_with_id(
|
170
|
-
datastore_id,
|
171
|
-
client
|
172
|
-
)
|
173
|
-
rc = datastore.info
|
174
|
-
if OpenNebula.is_error?(rc)
|
175
|
-
raise "Could not get datastore info \
|
176
|
-
for ID: #{datastore_id} - #{rc.message}"
|
177
|
-
end
|
178
|
-
|
179
|
-
vcenter_id = datastore['TEMPLATE/VCENTER_INSTANCE_ID']
|
180
|
-
|
181
|
-
host_pool = OpenNebula::HostPool.new(client)
|
182
|
-
rc = host_pool.info
|
183
|
-
if OpenNebula.is_error?(rc)
|
184
|
-
raise "Could not get hosts information - #{rc.message}"
|
185
|
-
end
|
186
|
-
|
187
|
-
user = ''
|
188
|
-
password = ''
|
189
|
-
port = 0
|
190
|
-
host_pool.each do |host|
|
191
|
-
vc_instance_id = host['TEMPLATE/VCENTER_INSTANCE_ID']
|
192
|
-
next unless vc_instance_id == vcenter_id
|
193
|
-
|
194
|
-
host_decrypted =
|
195
|
-
OpenNebula::Host
|
196
|
-
.new_with_id(
|
197
|
-
host['ID'],
|
198
|
-
client
|
199
|
-
)
|
200
|
-
host_decrypted.info(true)
|
201
|
-
user = host_decrypted['TEMPLATE/VCENTER_USER']
|
202
|
-
password = host_decrypted['TEMPLATE/VCENTER_PASSWORD']
|
203
|
-
port = host_decrypted['TEMPLATE/VCENTER_PORT']
|
204
|
-
end
|
205
|
-
if password.empty? || user.empty?
|
206
|
-
raise "Error getting \
|
207
|
-
credentials for datastore #{datastore_id}"
|
208
|
-
end
|
209
|
-
|
210
|
-
connection = {
|
211
|
-
:host => datastore['TEMPLATE/VCENTER_HOST'],
|
212
|
-
:user => user,
|
213
|
-
:password => password
|
214
|
-
}
|
215
|
-
|
216
|
-
connection[:port] = port unless port.nil?
|
217
|
-
|
218
|
-
new(connection)
|
219
|
-
end
|
220
|
-
|
221
|
-
def self.decrypt(msg, token)
|
222
|
-
begin
|
223
|
-
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
224
|
-
|
225
|
-
cipher.decrypt
|
226
|
-
|
227
|
-
# Truncate for Ruby 2.4 (in previous versions this was being
|
228
|
-
# automatically truncated)
|
229
|
-
cipher.key = token[0..31]
|
230
|
-
|
231
|
-
msg = cipher.update(Base64.decode64(msg))
|
232
|
-
msg << cipher.final
|
233
|
-
rescue StandardError
|
234
|
-
raise 'Error decrypting secret.'
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def self.in_silence
|
239
|
-
begin
|
240
|
-
orig_stderr = $stderr.clone
|
241
|
-
orig_stdout = $stdout.clone
|
242
|
-
$stderr.reopen File.new(File::NULL, 'w')
|
243
|
-
$stdout.reopen File.new(File::NULL, 'w')
|
244
|
-
retval = yield
|
245
|
-
rescue StandardError => e
|
246
|
-
$stdout.reopen orig_stdout
|
247
|
-
$stderr.reopen orig_stderr
|
248
|
-
raise e
|
249
|
-
ensure
|
250
|
-
$stdout.reopen orig_stdout
|
251
|
-
$stderr.reopen orig_stderr
|
252
|
-
end
|
253
|
-
retval
|
254
|
-
end
|
255
|
-
|
256
|
-
def self.in_stderr_silence
|
257
|
-
begin
|
258
|
-
orig_stderr = $stderr.clone
|
259
|
-
$stderr.reopen File.new(File::NULL, 'w')
|
260
|
-
retval = yield
|
261
|
-
rescue StandardError => e
|
262
|
-
$stderr.reopen orig_stderr
|
263
|
-
raise e
|
264
|
-
ensure
|
265
|
-
$stderr.reopen orig_stderr
|
266
|
-
end
|
267
|
-
retval
|
268
|
-
end
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
end
|
273
|
-
# module VCenterDriver
|
data/lib/vi_helper.rb
DELETED
@@ -1,328 +0,0 @@
|
|
1
|
-
# -------------------------------------------------------------------------- #
|
2
|
-
# Copyright 2002-2024, 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
|
-
########################################################################
|
18
|
-
# Module VCenterDriver
|
19
|
-
########################################################################
|
20
|
-
module VCenterDriver
|
21
|
-
|
22
|
-
########################################################################
|
23
|
-
# Class VIHelper
|
24
|
-
########################################################################
|
25
|
-
class VIHelper
|
26
|
-
|
27
|
-
ETC_LOCATION = '/etc/one/' unless defined?(ETC_LOCATION)
|
28
|
-
VCENTER_DRIVER_DEFAULT = "#{ETC_LOCATION}/vcenter_driver.default"
|
29
|
-
VM_PREFIX_DEFAULT = 'one-$i-'
|
30
|
-
|
31
|
-
# rubocop:disable Style/GlobalVars
|
32
|
-
# rubocop:disable Style/ClassVars
|
33
|
-
def self.client
|
34
|
-
if $conf.nil?
|
35
|
-
@@client ||= OpenNebula::Client.new # rubocop:disable Style/ClassVars
|
36
|
-
else
|
37
|
-
@@client ||= OpenNebula::Client.new(
|
38
|
-
nil,
|
39
|
-
$conf[:one_xmlrpc]
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
# rubocop:enable Style/GlobalVars
|
44
|
-
|
45
|
-
def self.set_client(options, client = nil)
|
46
|
-
if client.nil?
|
47
|
-
@@client=OpenNebulaHelper::OneHelper.get_client(options, true)
|
48
|
-
else
|
49
|
-
@@client = client
|
50
|
-
end
|
51
|
-
end
|
52
|
-
# rubocop:enable Style/ClassVars
|
53
|
-
|
54
|
-
def self.return_if_error(rc, item, exit_if_fail)
|
55
|
-
if OpenNebula.is_error?(rc)
|
56
|
-
raise rc.message unless exit_if_fail
|
57
|
-
|
58
|
-
STDERR.puts rc.message
|
59
|
-
exit 1
|
60
|
-
else
|
61
|
-
item
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
require 'scripts_common'
|
66
|
-
def self.check_error(rc, message, exit_condition = false)
|
67
|
-
return unless OpenNebula.is_error?(rc)
|
68
|
-
|
69
|
-
OpenNebula.error_message("\n Error #{message}: #{rc.message}\n")
|
70
|
-
exit 1 if exit_condition
|
71
|
-
|
72
|
-
raise rc.message
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.get_cluster_id(clusters)
|
76
|
-
clusters.each do |id|
|
77
|
-
return id unless id == -1
|
78
|
-
end
|
79
|
-
-1
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.one_managed?(object)
|
83
|
-
if object.class.ancestors.include?(OpenNebula::XMLElement)
|
84
|
-
managed =
|
85
|
-
object['TEMPLATE/OPENNEBULA_MANAGED'] ||
|
86
|
-
object['USER_TEMPLATE/OPENNEBULA_MANAGED']
|
87
|
-
return managed != 'NO'
|
88
|
-
end
|
89
|
-
false
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.check_opts(opts, att_list)
|
93
|
-
att_list.each do |att|
|
94
|
-
raise "#{att} option is mandatory" if opts[att].nil?
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.one_item(the_class, id, exit_if_fail = true)
|
99
|
-
item = the_class.new_with_id(id, client)
|
100
|
-
rc=nil
|
101
|
-
if the_class == OpenNebula::VirtualMachine
|
102
|
-
rc = item.info(true)
|
103
|
-
else
|
104
|
-
rc = item.info
|
105
|
-
end
|
106
|
-
return_if_error(rc, item, exit_if_fail)
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.new_one_item(the_class)
|
110
|
-
the_class.new(the_class.build_xml, client)
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.one_pool(the_class, exit_if_fail = true)
|
114
|
-
item = the_class.new(client)
|
115
|
-
|
116
|
-
rc = nil
|
117
|
-
begin
|
118
|
-
rc = item.info_all
|
119
|
-
rescue StandardError
|
120
|
-
rc = item.info
|
121
|
-
end
|
122
|
-
|
123
|
-
return_if_error(rc, item, exit_if_fail)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Since https://github.com/OpenNebula/one/issues/5689
|
127
|
-
# there two deploy_ids allowed:
|
128
|
-
# * moref, eg: vm-567
|
129
|
-
# * moref +"_" + vcenter uuid, eg:
|
130
|
-
# 2499952a-6c85-480e-b7df-4cbd2137eb69_vm-456
|
131
|
-
# This function will always return the moref
|
132
|
-
def self.get_deploy_id(deploy_id)
|
133
|
-
deploy_id.split('_')[0]
|
134
|
-
end
|
135
|
-
|
136
|
-
def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
|
137
|
-
pool = one_pool(the_class, raise_if_fail) if pool.nil?
|
138
|
-
element = pool.find {|e| e['NAME'] == name.to_s }
|
139
|
-
if element.nil? && raise_if_fail
|
140
|
-
raise "Could not find element '#{name}' in pool '#{the_class}'"
|
141
|
-
end
|
142
|
-
|
143
|
-
element
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.generate_name(opts, nbytes)
|
147
|
-
return opts[:name] if nbytes <= 0
|
148
|
-
|
149
|
-
@sha256 ||= Digest::SHA256.new
|
150
|
-
chain = opts[:key]
|
151
|
-
hash = @sha256.hexdigest(chain)[0..nbytes-1]
|
152
|
-
|
153
|
-
"#{opts[:name]}-#{hash}"
|
154
|
-
end
|
155
|
-
|
156
|
-
def self.one_name(the_class, name, key, pool = nil, bytes = 0)
|
157
|
-
# Remove \u007F character that comes from vcenter
|
158
|
-
name = name.tr("\u007F", '')
|
159
|
-
pool = one_pool(the_class) if pool.nil?
|
160
|
-
|
161
|
-
import_name = generate_name({ :name => name, :key => key }, bytes)
|
162
|
-
|
163
|
-
begin
|
164
|
-
find_by_name(the_class, import_name, pool)
|
165
|
-
rescue StandardError
|
166
|
-
return import_name
|
167
|
-
end
|
168
|
-
|
169
|
-
one_name(the_class, name, key, pool, bytes+2)
|
170
|
-
end
|
171
|
-
|
172
|
-
def self.get_ref_key(element, attribute, vcenter_uuid = nil)
|
173
|
-
key = element[attribute]
|
174
|
-
|
175
|
-
return if key.nil?
|
176
|
-
|
177
|
-
tvid = element['TEMPLATE/VCENTER_INSTANCE_ID']
|
178
|
-
uvid = element['USER_TEMPLATE/VCENTER_INSTANCE_ID']
|
179
|
-
|
180
|
-
if tvid
|
181
|
-
key += tvid
|
182
|
-
elsif uvid
|
183
|
-
key += uvid
|
184
|
-
elsif vcenter_uuid
|
185
|
-
key += vcenter_uuid
|
186
|
-
end
|
187
|
-
|
188
|
-
key
|
189
|
-
end
|
190
|
-
|
191
|
-
def self.create_ref_hash(attribute, pool, vcenter_uuid = nil)
|
192
|
-
hash = {}
|
193
|
-
|
194
|
-
pool.each_element(proc do |e|
|
195
|
-
refkey = get_ref_key(e, attribute, vcenter_uuid)
|
196
|
-
hash[refkey] = e
|
197
|
-
end)
|
198
|
-
|
199
|
-
hash
|
200
|
-
end
|
201
|
-
|
202
|
-
def self.clean_ref_hash
|
203
|
-
@ref_hash = {}
|
204
|
-
end
|
205
|
-
|
206
|
-
def self.add_ref_hash(attr, one_object)
|
207
|
-
raise 'cache is empty!' unless @ref_hash
|
208
|
-
|
209
|
-
refkey = get_ref_key(one_object, attr)
|
210
|
-
|
211
|
-
return unless @ref_hash[attr]
|
212
|
-
|
213
|
-
@ref_hash[attr][refkey] = one_object
|
214
|
-
end
|
215
|
-
|
216
|
-
def self.remove_ref_hash(attr, one_object)
|
217
|
-
raise 'cache is empty!' unless @ref_hash
|
218
|
-
|
219
|
-
refkey = get_ref_key(one_object, attr)
|
220
|
-
|
221
|
-
return unless @ref_hash[attr]
|
222
|
-
|
223
|
-
@ref_hash[attr].delete(refkey)
|
224
|
-
end
|
225
|
-
|
226
|
-
def self.find_by_ref(
|
227
|
-
the_class,
|
228
|
-
attribute,
|
229
|
-
ref,
|
230
|
-
vcenter_uuid,
|
231
|
-
pool = nil
|
232
|
-
)
|
233
|
-
pool = one_pool(the_class, false) if pool.nil?
|
234
|
-
@ref_hash ||= {}
|
235
|
-
|
236
|
-
if @ref_hash[attribute].nil? || @ref_hash[attribute] == {}
|
237
|
-
@ref_hash[attribute] = create_ref_hash(attribute,
|
238
|
-
pool,
|
239
|
-
vcenter_uuid)
|
240
|
-
end
|
241
|
-
|
242
|
-
refkey = ''
|
243
|
-
refkey = ref if ref
|
244
|
-
refkey += vcenter_uuid if vcenter_uuid
|
245
|
-
|
246
|
-
@ref_hash[attribute][refkey]
|
247
|
-
end
|
248
|
-
|
249
|
-
require 'addressable'
|
250
|
-
def self.find_image_by(att, the_class, path, ds_id, pool = nil)
|
251
|
-
pool = one_pool(the_class, false) if pool.nil?
|
252
|
-
pool.find do |e|
|
253
|
-
e[att] == Addressable::URI.escape(path) &&
|
254
|
-
e['DATASTORE_ID'] == ds_id
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
def self.find_persistent_image_by_source(source, pool)
|
259
|
-
pool.find do |e|
|
260
|
-
e['SOURCE'] == source &&
|
261
|
-
e['PERSISTENT'] == '1'
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
def self.find_vcenter_vm_by_name(one_vm, host, vi_client)
|
266
|
-
# Let's try to find the VM object only by its name
|
267
|
-
# Let's build the VM name
|
268
|
-
vm_prefix = host['TEMPLATE/VM_PREFIX']
|
269
|
-
vm_prefix = VM_PREFIX_DEFAULT if vm_prefix.nil?
|
270
|
-
vm_prefix.gsub!('$i', one_vm['ID'])
|
271
|
-
vm_name = vm_prefix + one_vm['NAME']
|
272
|
-
|
273
|
-
# We have no DEPLOY_ID, the VM has never been deployed
|
274
|
-
# let's use a view to try to find the VM from the root folder
|
275
|
-
view = vi_client
|
276
|
-
.vim
|
277
|
-
.serviceContent
|
278
|
-
.viewManager
|
279
|
-
.CreateContainerView(
|
280
|
-
{
|
281
|
-
:container => vi_client.vim.rootFolder,
|
282
|
-
:type => ['VirtualMachine'],
|
283
|
-
:recursive => true
|
284
|
-
}
|
285
|
-
)
|
286
|
-
|
287
|
-
if !view.view.nil? && !view.view.empty?
|
288
|
-
vcenter_vm = view
|
289
|
-
.view
|
290
|
-
.find {|v| v.name == vm_name }
|
291
|
-
end
|
292
|
-
|
293
|
-
view.DestroyView # Destroy the view
|
294
|
-
|
295
|
-
vcenter_vm
|
296
|
-
end
|
297
|
-
|
298
|
-
def self.get_default(xpath)
|
299
|
-
begin
|
300
|
-
xml = OpenNebula::XMLElement.new
|
301
|
-
xml.initialize_xml(File.read(VCENTER_DRIVER_DEFAULT), 'VCENTER')
|
302
|
-
xml[xpath]
|
303
|
-
rescue StandardError
|
304
|
-
nil
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
def self.get_location(item)
|
309
|
-
folders = []
|
310
|
-
until item.instance_of? RbVmomi::VIM::Datacenter
|
311
|
-
item = item.parent
|
312
|
-
if !item.instance_of?(RbVmomi::VIM::Datacenter) &&
|
313
|
-
item.name != 'host'
|
314
|
-
folders << item.name
|
315
|
-
end
|
316
|
-
raise 'Could not find the location' if item.nil?
|
317
|
-
end
|
318
|
-
location = folders.reverse.join('/')
|
319
|
-
location = '/' if location.empty?
|
320
|
-
|
321
|
-
location
|
322
|
-
end
|
323
|
-
|
324
|
-
end
|
325
|
-
# class VIHelper
|
326
|
-
|
327
|
-
end
|
328
|
-
# module VCenterDriver
|