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/vcenter_importer.rb
DELETED
@@ -1,626 +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
|
-
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
23
|
-
|
24
|
-
if !ONE_LOCATION
|
25
|
-
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' \
|
26
|
-
unless defined?(RUBY_LIB_LOCATION)
|
27
|
-
GEMS_LOCATION = '/usr/share/one/gems' \
|
28
|
-
unless defined?(GEMS_LOCATION)
|
29
|
-
HOOK_LOCATION = '/var/lib/one/remotes/hooks' \
|
30
|
-
unless defined?(HOOK_LOCATION)
|
31
|
-
else
|
32
|
-
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' \
|
33
|
-
unless defined?(RUBY_LIB_LOCATION)
|
34
|
-
GEMS_LOCATION = ONE_LOCATION + '/share/gems' \
|
35
|
-
unless defined?(GEMS_LOCATION)
|
36
|
-
HOOK_LOCATION = ONE_LOCATION + '/remotes/hooks' \
|
37
|
-
unless defined?(HOOK_LOCATION)
|
38
|
-
end
|
39
|
-
|
40
|
-
##########################################################################
|
41
|
-
# Class VcImporter
|
42
|
-
##########################################################################
|
43
|
-
class VcImporter
|
44
|
-
|
45
|
-
attr_accessor :list
|
46
|
-
|
47
|
-
######################################################################
|
48
|
-
# Constructors
|
49
|
-
######################################################################
|
50
|
-
#
|
51
|
-
#
|
52
|
-
|
53
|
-
# Builds a vCenter importer
|
54
|
-
#
|
55
|
-
# @param one_client [OpenNebula::Client] OpenNebula ruby Client
|
56
|
-
# @param vi_client [VCenterDriver::VIClient] vCenter driver Client
|
57
|
-
#
|
58
|
-
def initialize(one_client, vi_client)
|
59
|
-
@vi_client = vi_client
|
60
|
-
@one_client = one_client
|
61
|
-
|
62
|
-
@list = {}
|
63
|
-
|
64
|
-
@info = {}
|
65
|
-
@info[:clusters] = {}
|
66
|
-
@info[:success] = []
|
67
|
-
@info[:error] = []
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Allow us to spawn a specific importer child
|
72
|
-
#
|
73
|
-
# @param one_client [OpenNebula::Client] OpenNebula ruby Client
|
74
|
-
# @param vi_client [VCenterDriver::VIClient] vCenter driver Client
|
75
|
-
# @param type [String] to choose the specific child
|
76
|
-
#
|
77
|
-
# @return [VCImporter] the vCenter importer that will handle
|
78
|
-
# any operation
|
79
|
-
#
|
80
|
-
def self.new_child(one_client, vi_client, type)
|
81
|
-
case type.downcase
|
82
|
-
when 'hosts'
|
83
|
-
VCenterDriver::VcImporter.new(one_client, vi_client)
|
84
|
-
when 'datastores'
|
85
|
-
VCenterDriver::DsImporter.new(one_client, vi_client)
|
86
|
-
when 'templates'
|
87
|
-
VCenterDriver::VmImporter.new(one_client, vi_client)
|
88
|
-
when 'networks'
|
89
|
-
VCenterDriver::NetImporter.new(one_client, vi_client)
|
90
|
-
when 'images'
|
91
|
-
VCenterDriver::ImageImporter.new(one_client, vi_client)
|
92
|
-
else
|
93
|
-
raise 'unknown object type'
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# @return [String] the object type of the importer
|
99
|
-
#
|
100
|
-
def one_str
|
101
|
-
return @one_class.to_s.split('::').last if @one_class
|
102
|
-
|
103
|
-
'OpenNebula object'
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# Prints feedback of the realized import operations
|
108
|
-
# throught STDOUT
|
109
|
-
#
|
110
|
-
def stdout
|
111
|
-
@info[:success].each do |o|
|
112
|
-
o[:id].each do |id|
|
113
|
-
puts "ID: #{id}"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
puts
|
118
|
-
|
119
|
-
@info[:error].each do |error|
|
120
|
-
index = error.first[0]
|
121
|
-
e = @info[index][:e]
|
122
|
-
puts "Error: Couldn't import #{index} due to #{e.message}!"
|
123
|
-
puts
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Importer return value
|
128
|
-
#
|
129
|
-
# @ return [Hash{:sucess =>[[]] , :error => {}}
|
130
|
-
#
|
131
|
-
def output
|
132
|
-
{ :success => @info[:success], :error => @info[:error] }
|
133
|
-
end
|
134
|
-
|
135
|
-
#
|
136
|
-
# Parse arguments usually given by command line interface
|
137
|
-
# with the purpose of retrieve a list of selected indexes
|
138
|
-
# by the users.
|
139
|
-
#
|
140
|
-
# @param args [nil | Array | String] range, names or nil
|
141
|
-
#
|
142
|
-
# @ return [Aarray] the list of selected indexes
|
143
|
-
#
|
144
|
-
def get_indexes(args = nil)
|
145
|
-
raise 'the list is empty' if list_empty?
|
146
|
-
|
147
|
-
list = @list.values[0]
|
148
|
-
indexes = ''
|
149
|
-
keys = list.keys
|
150
|
-
|
151
|
-
return keys.join(',') unless args
|
152
|
-
|
153
|
-
if args.include?('..')
|
154
|
-
range = Range.new(*args.split('..').map(&:to_i))
|
155
|
-
|
156
|
-
if range.first != range.last
|
157
|
-
range.each do |i|
|
158
|
-
indexes << "#{keys[i]}, "
|
159
|
-
end
|
160
|
-
|
161
|
-
return indexes
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
if args !~ /\D/
|
166
|
-
ind = args.to_i
|
167
|
-
|
168
|
-
return keys[ind]
|
169
|
-
end
|
170
|
-
|
171
|
-
args
|
172
|
-
end
|
173
|
-
|
174
|
-
#
|
175
|
-
# Wrapper of get_list, needed for clean the cache
|
176
|
-
# get_list populates @ref_hash cache at vCenter driver
|
177
|
-
# level, with this function you still can reuse the importer.
|
178
|
-
#
|
179
|
-
# @param opts [Hash] Hash with the needed arguments
|
180
|
-
#
|
181
|
-
# @ return [Hash] the list of unimported resources
|
182
|
-
#
|
183
|
-
def retrieve_resources(opts = {})
|
184
|
-
VCenterDriver::VIHelper.clean_ref_hash
|
185
|
-
|
186
|
-
list = get_list(opts)
|
187
|
-
|
188
|
-
@defaults = opts[:config] if opts[:config]
|
189
|
-
|
190
|
-
list
|
191
|
-
end
|
192
|
-
|
193
|
-
#
|
194
|
-
# This method handles all the importation.
|
195
|
-
# Will be in charge of call the specific import operation
|
196
|
-
# of the specific importer.
|
197
|
-
#
|
198
|
-
# @param indexes [Array] Array with all the indexes that
|
199
|
-
# points to the selected object of the list.
|
200
|
-
# @param opts [Hash] Hash with the options.
|
201
|
-
# In sunstone context this options will contain every
|
202
|
-
# index associated to his own resource opt
|
203
|
-
#
|
204
|
-
# Example:
|
205
|
-
# {"vm-343" => {:linked_clone: '0', :copy: '0'...}
|
206
|
-
#
|
207
|
-
# @ return [Hash] the list of unimported resources
|
208
|
-
#
|
209
|
-
def process_import(indexes, opts = {}, &block)
|
210
|
-
raise 'the list is empty' if list_empty?
|
211
|
-
|
212
|
-
indexes = indexes.gsub(/\s*\,\s*/, ',').strip.split(',')
|
213
|
-
|
214
|
-
indexes.each do |index|
|
215
|
-
begin
|
216
|
-
@rollback = []
|
217
|
-
@info[index] = {}
|
218
|
-
|
219
|
-
selected = get_element(index)
|
220
|
-
|
221
|
-
if block_given?
|
222
|
-
@info[index][:opts] = block.call(selected)
|
223
|
-
elsif opts[index]
|
224
|
-
@info[index][:opts] = opts[index]
|
225
|
-
else
|
226
|
-
@info[index][:opts] = defaults
|
227
|
-
end
|
228
|
-
|
229
|
-
# import the object
|
230
|
-
@info[:success] << import(selected)
|
231
|
-
rescue StandardError => e
|
232
|
-
@info[:error] << { index => e.message }
|
233
|
-
@info[index][:e] = e
|
234
|
-
|
235
|
-
apply_rollback
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def self.import_clusters(con_ops, options)
|
241
|
-
begin
|
242
|
-
STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."
|
243
|
-
|
244
|
-
use_defaults = options.key?(:defaults)
|
245
|
-
|
246
|
-
vi_client = VCenterDriver::VIClient.new(con_ops)
|
247
|
-
|
248
|
-
STDOUT.print "done!\n\n"
|
249
|
-
|
250
|
-
STDOUT.print 'Exploring vCenter resources...'
|
251
|
-
|
252
|
-
dc_folder = VCenterDriver::DatacenterFolder.new(vi_client)
|
253
|
-
|
254
|
-
vcenter_instance_name = vi_client.vim.host
|
255
|
-
|
256
|
-
# OpenNebula's ClusterPool
|
257
|
-
cpool = VCenterDriver::VIHelper
|
258
|
-
.one_pool(OpenNebula::ClusterPool, false)
|
259
|
-
if cpool.respond_to?(:message)
|
260
|
-
raise "Could not get OpenNebula ClusterPool: \
|
261
|
-
#{cpool.message}"
|
262
|
-
end
|
263
|
-
|
264
|
-
cluster_list = {}
|
265
|
-
cpool.each do |c|
|
266
|
-
name = VCenterDriver::VcImporter.sanitize(
|
267
|
-
c['NAME']
|
268
|
-
)
|
269
|
-
cluster_list[c['ID']] = name if c['ID'].to_i != 0
|
270
|
-
end
|
271
|
-
|
272
|
-
# Get OpenNebula's host pool
|
273
|
-
hpool = VCenterDriver::VIHelper
|
274
|
-
.one_pool(OpenNebula::HostPool, false)
|
275
|
-
if hpool.respond_to?(:message)
|
276
|
-
raise "Could not get OpenNebula HostPool: #{hpool.message}"
|
277
|
-
end
|
278
|
-
|
279
|
-
rs = dc_folder.get_unimported_hosts(hpool,
|
280
|
-
vcenter_instance_name)
|
281
|
-
|
282
|
-
# Select just cluster with this reference
|
283
|
-
if options[:cluster_ref]
|
284
|
-
rs.each do |_, clusters|
|
285
|
-
clusters.select! do |c|
|
286
|
-
c[:cluster_ref] == options[:cluster_ref]
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
STDOUT.print "done!\n\n"
|
292
|
-
|
293
|
-
rs.each do |dc, clusters|
|
294
|
-
if !use_defaults
|
295
|
-
# rubocop:disable Layout/LineLength
|
296
|
-
STDOUT.print "Do you want to process datacenter #{dc} (y/[n])? "
|
297
|
-
# rubocop:enable Layout/LineLength
|
298
|
-
next if STDIN.gets.strip.downcase != 'y'
|
299
|
-
end
|
300
|
-
|
301
|
-
if clusters.empty?
|
302
|
-
STDOUT.puts "\n No new clusters found in #{dc}..."
|
303
|
-
next
|
304
|
-
end
|
305
|
-
|
306
|
-
clusters.each do |cluster|
|
307
|
-
one_cluster_id = nil
|
308
|
-
rpool = nil
|
309
|
-
|
310
|
-
# Handle OpenNebula cluster creation or reuse
|
311
|
-
if !use_defaults
|
312
|
-
# rubocop:disable Layout/LineLength
|
313
|
-
STDOUT.print "\n * vCenter cluster found:\n"\
|
314
|
-
" - Name : \e[92m#{cluster[:simple_name]}\e[39m\n"\
|
315
|
-
" - Location : #{cluster[:cluster_location]}\n"\
|
316
|
-
' Import cluster (y/[n])? '
|
317
|
-
# rubocop:enable Layout/LineLength
|
318
|
-
next if STDIN.gets.strip.downcase != 'y'
|
319
|
-
|
320
|
-
if !cluster_list.empty?
|
321
|
-
# rubocop:disable Layout/LineLength
|
322
|
-
STDOUT.print "\n In which OpenNebula cluster do you want the vCenter cluster to be included?\n "
|
323
|
-
# rubocop:enable Layout/LineLength
|
324
|
-
|
325
|
-
cluster_list_str = "\n"
|
326
|
-
cluster_list.each do |key, value|
|
327
|
-
name = VCenterDriver::VcImporter.sanitize(
|
328
|
-
value
|
329
|
-
)
|
330
|
-
cluster_list_str << " - \e[94mID: " \
|
331
|
-
<< key \
|
332
|
-
<< "\e[39m - NAME: " \
|
333
|
-
<< name << "\n"
|
334
|
-
end
|
335
|
-
|
336
|
-
STDOUT.print "\n #{cluster_list_str}"
|
337
|
-
# rubocop:disable Layout/LineLength
|
338
|
-
STDOUT.print "\n Specify the ID of the cluster or press Enter if you want OpenNebula to create a new cluster for you: "
|
339
|
-
# rubocop:enable Layout/LineLength
|
340
|
-
answer = STDIN.gets.strip
|
341
|
-
|
342
|
-
if !answer.empty?
|
343
|
-
one_cluster_id = answer
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
cluster_name = VCenterDriver::VcImporter.sanitize(
|
349
|
-
cluster[:cluster_name]
|
350
|
-
)
|
351
|
-
|
352
|
-
# Check if the OpenNebula Cluster exists, and reuse it
|
353
|
-
one_cluster_id ||= cluster_list
|
354
|
-
.key(cluster_name)
|
355
|
-
|
356
|
-
if !one_cluster_id
|
357
|
-
one_cluster = VCenterDriver::VIHelper
|
358
|
-
.new_one_item(OpenNebula::Cluster)
|
359
|
-
rc = one_cluster
|
360
|
-
.allocate(cluster_name.to_s)
|
361
|
-
if ::OpenNebula.is_error?(rc)
|
362
|
-
# rubocop:disable Layout/LineLength
|
363
|
-
STDOUT.puts " Error creating OpenNebula cluster: #{rc.message}\n"
|
364
|
-
# rubocop:enable Layout/LineLength
|
365
|
-
next
|
366
|
-
end
|
367
|
-
one_cluster_id = one_cluster.id
|
368
|
-
end
|
369
|
-
|
370
|
-
# Generate host template and allocate new host
|
371
|
-
one_host = VCenterDriver::ClusterComputeResource
|
372
|
-
.to_one(cluster,
|
373
|
-
con_ops,
|
374
|
-
rpool,
|
375
|
-
one_cluster_id)
|
376
|
-
# rubocop:disable Layout/LineLength
|
377
|
-
STDOUT.puts "\n OpenNebula host \e[92m#{cluster_name}\e[39m with"\
|
378
|
-
" ID \e[94m#{one_host.id}\e[39m successfully created."
|
379
|
-
STDOUT.puts
|
380
|
-
# rubocop:enable Layout/LineLength
|
381
|
-
end
|
382
|
-
end
|
383
|
-
rescue Interrupt
|
384
|
-
puts "\n"
|
385
|
-
exit 0 # Ctrl+C
|
386
|
-
rescue StandardError => e
|
387
|
-
error_msg = "\nError: #{e.message}\n"
|
388
|
-
error_msg << "#{e.backtrace}\n" \
|
389
|
-
if VCenterDriver::CONFIG[:debug_information]
|
390
|
-
STDERR.puts error_msg
|
391
|
-
raise_error = true
|
392
|
-
ensure
|
393
|
-
vi_client.close_connection if vi_client
|
394
|
-
raise if raise_error
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
def self.sanitize(text)
|
399
|
-
bad_chars = ['|']
|
400
|
-
bad_chars.each do |bad_char|
|
401
|
-
text.gsub!(bad_char, '_')
|
402
|
-
end
|
403
|
-
text
|
404
|
-
end
|
405
|
-
|
406
|
-
protected
|
407
|
-
|
408
|
-
#
|
409
|
-
# Object used for stack action and perform rollback
|
410
|
-
#
|
411
|
-
# Constructor:
|
412
|
-
# @param object [Ruby Object] Any object related to the action.
|
413
|
-
# @param method [Symbol] Symbol representing the method
|
414
|
-
# (must belong to object)
|
415
|
-
# @param args [Array] Array with list of arguments,
|
416
|
-
# will be passed to method
|
417
|
-
#
|
418
|
-
# apply:
|
419
|
-
# The stored @object call ther @method with @args
|
420
|
-
class Raction
|
421
|
-
|
422
|
-
def initialize(object, method, args = [])
|
423
|
-
@object = object
|
424
|
-
@action = method
|
425
|
-
@args = args
|
426
|
-
end
|
427
|
-
|
428
|
-
def apply
|
429
|
-
@object.method(@action).call(*@args)
|
430
|
-
end
|
431
|
-
|
432
|
-
def self.delete_ars(ar_ids, opts)
|
433
|
-
error = opts[:error]
|
434
|
-
|
435
|
-
raise error if ar_ids.nil?
|
436
|
-
|
437
|
-
# key = opts[:key]
|
438
|
-
vc_uuid = opts[:uuid]
|
439
|
-
npool = opts[:npool]
|
440
|
-
|
441
|
-
ar_ids.each do |key, value|
|
442
|
-
network = VCenterDriver::VIHelper
|
443
|
-
.find_by_ref(OpenNebula::VirtualNetworkPool,
|
444
|
-
'TEMPLATE/VCENTER_NET_REF',
|
445
|
-
key,
|
446
|
-
vc_uuid, npool)
|
447
|
-
value.each {|ar| network.rm_ar(ar) }
|
448
|
-
end
|
449
|
-
|
450
|
-
raise error
|
451
|
-
end
|
452
|
-
|
453
|
-
end
|
454
|
-
|
455
|
-
#######################################################################
|
456
|
-
# ABSTRACT INTERFACE
|
457
|
-
#######################################################################
|
458
|
-
#
|
459
|
-
# This Interface should be implemented by the specific importer.
|
460
|
-
|
461
|
-
MESS = 'missing method from parent'
|
462
|
-
|
463
|
-
#
|
464
|
-
# Retrieves a list with the unimported resources
|
465
|
-
# The importer needs to perform this operation
|
466
|
-
# before any import operation,
|
467
|
-
#
|
468
|
-
# @param args [Hash] Hash with the needed arguments
|
469
|
-
#
|
470
|
-
# @return [Hash{String => Hash}] operation results.
|
471
|
-
#
|
472
|
-
def get_list(_args = {})
|
473
|
-
raise MESS
|
474
|
-
end
|
475
|
-
|
476
|
-
#
|
477
|
-
# Add certain resource to OpenNebula Cluster.
|
478
|
-
#
|
479
|
-
# @param cid [Int] opennebula cluster id
|
480
|
-
# @param eid [Int] the id of the imported opennebula resource
|
481
|
-
#
|
482
|
-
def add_cluster(_cid, _eid)
|
483
|
-
raise MESS
|
484
|
-
end
|
485
|
-
|
486
|
-
#
|
487
|
-
# Remove the imported resource from the default cluster
|
488
|
-
#
|
489
|
-
# @param id [Int] id of the imported resource
|
490
|
-
#
|
491
|
-
def remove_default(_id)
|
492
|
-
raise MESS
|
493
|
-
end
|
494
|
-
|
495
|
-
#
|
496
|
-
# Retrieves information about the run-time state of a virtual machine.
|
497
|
-
#
|
498
|
-
# @param selected [Hash] Hash with the info of the
|
499
|
-
# vCenter object that will
|
500
|
-
# be imported
|
501
|
-
#
|
502
|
-
# @return [Hash{:id => [], :name => String}] operation results.
|
503
|
-
#
|
504
|
-
def import(_selected)
|
505
|
-
raise MESS
|
506
|
-
end
|
507
|
-
|
508
|
-
#
|
509
|
-
# Create and allocate a OpenNebula Object.
|
510
|
-
#
|
511
|
-
# @param info [String] Info passed to OpenNebula Core.
|
512
|
-
#
|
513
|
-
# @return [&block] the allocated object through a block.
|
514
|
-
#
|
515
|
-
def create(info, &block)
|
516
|
-
resource = VCenterDriver::VIHelper.new_one_item(@one_class)
|
517
|
-
message = 'Error creating the OpenNebula resource'
|
518
|
-
|
519
|
-
rc = resource.allocate(info)
|
520
|
-
VCenterDriver::VIHelper.check_error(rc, message)
|
521
|
-
|
522
|
-
resource.info
|
523
|
-
id = resource['ID']
|
524
|
-
@rollback << Raction.new(resource, :delete)
|
525
|
-
block.call(resource, id)
|
526
|
-
end
|
527
|
-
|
528
|
-
#
|
529
|
-
# Asks if @list is empty
|
530
|
-
#
|
531
|
-
def list_empty?
|
532
|
-
@list == {}
|
533
|
-
end
|
534
|
-
|
535
|
-
#
|
536
|
-
# Gets a certain element from the list, ref given.
|
537
|
-
#
|
538
|
-
# @param ref [String] vCenter reference and index of importer list.
|
539
|
-
#
|
540
|
-
# @return [Hash] Hash with all the info related to the reference
|
541
|
-
#
|
542
|
-
def get_element(ref)
|
543
|
-
raise 'the list is empty' if list_empty? || @list.values[0].empty?
|
544
|
-
|
545
|
-
list = @list.values[0]
|
546
|
-
|
547
|
-
return list[ref] if list[ref]
|
548
|
-
|
549
|
-
raise "#{ref} not found!"
|
550
|
-
end
|
551
|
-
|
552
|
-
#
|
553
|
-
# Add the imported resources to n OpenNebula Clusters.
|
554
|
-
# And remove the default one(0).
|
555
|
-
#
|
556
|
-
# @param one_id [Int] The id of the imported OpenNebula object.
|
557
|
-
# @param clusters [Array] Array with all the ids of the desired
|
558
|
-
# OpenNebula clusters.
|
559
|
-
#
|
560
|
-
def add_clusters(one_id, clusters)
|
561
|
-
clusters.each do |cid|
|
562
|
-
next if cid < 0
|
563
|
-
|
564
|
-
@info[:clusters][cid] ||= VCenterDriver::VIHelper
|
565
|
-
.one_item(OpenNebula::Cluster,
|
566
|
-
cid.to_s,
|
567
|
-
false)
|
568
|
-
rc = add_cluster(cid, one_id.to_i)
|
569
|
-
VCenterDriver::VIHelper
|
570
|
-
.check_error(rc, 'add element to cluster')
|
571
|
-
end
|
572
|
-
remove_default(one_id)
|
573
|
-
end
|
574
|
-
|
575
|
-
#
|
576
|
-
# Call this function to use the rollback Stack, and delete every
|
577
|
-
# corrupted object created by the importer.
|
578
|
-
#
|
579
|
-
def apply_rollback
|
580
|
-
return if @rollback.empty?
|
581
|
-
|
582
|
-
@rollback.each do |action|
|
583
|
-
action.apply
|
584
|
-
end
|
585
|
-
end
|
586
|
-
|
587
|
-
#
|
588
|
-
# Default opts
|
589
|
-
#
|
590
|
-
def defaults
|
591
|
-
return @defaults if @defaults
|
592
|
-
|
593
|
-
{}
|
594
|
-
end
|
595
|
-
|
596
|
-
def create_pools
|
597
|
-
dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
|
598
|
-
if dpool.respond_to?(:message)
|
599
|
-
raise "Could not get OpenNebula DatastorePool: \
|
600
|
-
#{dpool.message}"
|
601
|
-
end
|
602
|
-
|
603
|
-
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
|
604
|
-
if ipool.respond_to?(:message)
|
605
|
-
raise "Could not get OpenNebula ImagePool: #{ipool.message}"
|
606
|
-
end
|
607
|
-
|
608
|
-
npool = VCenterDriver::VIHelper
|
609
|
-
.one_pool(OpenNebula::VirtualNetworkPool)
|
610
|
-
if npool.respond_to?(:message)
|
611
|
-
raise "Could not get OpenNebula VirtualNetworkPool: \
|
612
|
-
#{npool.message}"
|
613
|
-
end
|
614
|
-
|
615
|
-
hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool)
|
616
|
-
if hpool.respond_to?(:message)
|
617
|
-
raise "Could not get OpenNebula VirtualNetworkPool: \
|
618
|
-
#{hpool.message}"
|
619
|
-
end
|
620
|
-
|
621
|
-
[dpool, ipool, npool, hpool]
|
622
|
-
end
|
623
|
-
|
624
|
-
end
|
625
|
-
|
626
|
-
end
|