opennebula 5.12.13 → 5.13.80.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/ActionManager.rb +1 -1
- data/lib/CommandManager.rb +1 -1
- data/lib/DriverExecHelper.rb +44 -28
- data/lib/OpenNebulaDriver.rb +8 -4
- data/lib/VirtualMachineDriver.rb +9 -2
- data/lib/cloud/CloudClient.rb +3 -3
- data/lib/datacenter.rb +1258 -0
- data/lib/datastore.rb +1025 -0
- data/lib/distributed_firewall.rb +280 -0
- data/lib/file_helper.rb +370 -0
- data/lib/host.rb +1517 -0
- data/lib/logical_port.rb +50 -0
- data/lib/logical_switch.rb +77 -0
- data/lib/memoize.rb +74 -0
- data/lib/models/role.rb +39 -8
- data/lib/models/service.rb +92 -31
- data/lib/models.rb +5 -5
- data/lib/network.rb +635 -0
- data/lib/nsx_client.rb +144 -0
- data/lib/nsx_component.rb +28 -0
- data/lib/nsx_constants.rb +149 -0
- data/lib/nsx_driver.rb +78 -0
- data/lib/nsx_error.rb +77 -0
- data/lib/nsx_rule.rb +193 -0
- data/lib/nsxt_client.rb +176 -0
- data/lib/nsxt_dfw.rb +196 -0
- data/lib/nsxt_logical_port.rb +94 -0
- data/lib/nsxt_rule.rb +188 -0
- data/lib/nsxt_tz.rb +38 -0
- data/lib/nsxv_client.rb +176 -0
- data/lib/nsxv_dfw.rb +202 -0
- data/lib/nsxv_logical_port.rb +107 -0
- data/lib/nsxv_rule.rb +172 -0
- data/lib/nsxv_tz.rb +41 -0
- data/lib/opaque_network.rb +134 -0
- data/lib/opennebula/acl.rb +1 -1
- data/lib/opennebula/acl_pool.rb +1 -1
- data/lib/opennebula/client.rb +1 -1
- data/lib/opennebula/cluster.rb +1 -1
- 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 +8 -29
- data/lib/opennebula/document_json.rb +42 -12
- data/lib/opennebula/document_pool.rb +1 -1
- data/lib/opennebula/document_pool_json.rb +1 -1
- data/lib/opennebula/error.rb +4 -1
- data/lib/opennebula/flow/grammar.rb +1195 -0
- data/lib/{models → opennebula/flow}/service_pool.rb +26 -2
- data/lib/{models → opennebula/flow}/service_template.rb +86 -17
- data/lib/opennebula/flow/service_template_ext.rb +84 -0
- data/lib/{models → opennebula/flow}/service_template_pool.rb +1 -1
- data/lib/opennebula/flow/validator.rb +499 -0
- data/lib/opennebula/flow.rb +23 -0
- data/lib/opennebula/group.rb +1 -1
- data/lib/opennebula/group_pool.rb +1 -1
- data/lib/opennebula/hook.rb +5 -12
- data/lib/opennebula/hook_log.rb +1 -1
- data/lib/opennebula/hook_pool.rb +1 -1
- data/lib/opennebula/host.rb +1 -1
- data/lib/opennebula/host_pool.rb +1 -1
- data/lib/opennebula/image.rb +17 -14
- 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 +163 -0
- data/lib/opennebula/marketplace.rb +1 -1
- data/lib/opennebula/marketplace_pool.rb +1 -1
- data/lib/opennebula/marketplaceapp.rb +9 -119
- data/lib/opennebula/marketplaceapp_ext.rb +522 -0
- data/lib/opennebula/marketplaceapp_pool.rb +1 -1
- data/lib/opennebula/oneflow_client.rb +4 -3
- data/lib/opennebula/pool.rb +4 -3
- 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 +4 -13
- data/lib/opennebula/template_ext.rb +325 -0
- data/lib/opennebula/template_pool.rb +1 -1
- data/lib/opennebula/user.rb +26 -2
- data/lib/opennebula/user_pool.rb +1 -1
- data/lib/opennebula/utils.rb +1 -1
- data/lib/opennebula/vdc.rb +1 -1
- data/lib/opennebula/vdc_pool.rb +1 -1
- data/lib/opennebula/virtual_machine.rb +25 -207
- data/lib/opennebula/virtual_machine_ext.rb +469 -0
- data/lib/opennebula/virtual_machine_pool.rb +1 -5
- data/lib/opennebula/virtual_network.rb +4 -10
- data/lib/opennebula/virtual_network_pool.rb +1 -1
- data/lib/opennebula/virtual_router.rb +4 -12
- data/lib/opennebula/virtual_router_pool.rb +1 -1
- data/lib/opennebula/vm_group.rb +4 -11
- data/lib/opennebula/vm_group_pool.rb +1 -1
- data/lib/opennebula/vntemplate.rb +4 -13
- data/lib/opennebula/vntemplate_pool.rb +1 -1
- data/lib/opennebula/wait_ext.rb +222 -0
- data/lib/opennebula/x509_auth.rb +1 -1
- data/lib/opennebula/xml_element.rb +1 -1
- 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 +5 -2
- data/lib/rest_client.rb +201 -0
- data/lib/scripts_common.rb +180 -0
- data/lib/transport_zone.rb +43 -0
- data/lib/vcenter_driver.rb +9 -22
- data/lib/vcenter_importer.rb +616 -0
- data/lib/vi_client.rb +281 -0
- data/lib/vi_helper.rb +312 -0
- data/lib/virtual_machine.rb +3477 -0
- data/lib/virtual_wire.rb +158 -0
- data/lib/vm_device.rb +80 -0
- data/lib/vm_disk.rb +202 -0
- data/lib/vm_folder.rb +69 -0
- data/lib/vm_helper.rb +30 -0
- data/lib/vm_monitor.rb +303 -0
- data/lib/vm_nic.rb +70 -0
- data/lib/vm_template.rb +1961 -0
- data/lib/vmm_importer.rb +121 -0
- metadata +101 -35
@@ -0,0 +1,616 @@
|
|
1
|
+
# -------------------------------------------------------------------------- #
|
2
|
+
# Copyright 2002-2021, 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: '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
|
+
cluster_list[c['ID']] = c['NAME'] if c['ID'].to_i != 0
|
267
|
+
end
|
268
|
+
|
269
|
+
# Get OpenNebula's host pool
|
270
|
+
hpool = VCenterDriver::VIHelper
|
271
|
+
.one_pool(OpenNebula::HostPool, false)
|
272
|
+
if hpool.respond_to?(:message)
|
273
|
+
raise "Could not get OpenNebula HostPool: #{hpool.message}"
|
274
|
+
end
|
275
|
+
|
276
|
+
rs = dc_folder.get_unimported_hosts(hpool,
|
277
|
+
vcenter_instance_name)
|
278
|
+
|
279
|
+
STDOUT.print "done!\n\n"
|
280
|
+
|
281
|
+
rs.each do |dc, clusters|
|
282
|
+
if !use_defaults
|
283
|
+
# rubocop:disable Layout/LineLength
|
284
|
+
STDOUT.print "Do you want to process datacenter #{dc} (y/[n])? "
|
285
|
+
# rubocop:enable Layout/LineLength
|
286
|
+
next if STDIN.gets.strip.downcase != 'y'
|
287
|
+
end
|
288
|
+
|
289
|
+
if clusters.empty?
|
290
|
+
STDOUT.puts "\n No new clusters found in #{dc}..."
|
291
|
+
next
|
292
|
+
end
|
293
|
+
|
294
|
+
clusters.each do |cluster|
|
295
|
+
one_cluster_id = nil
|
296
|
+
rpool = nil
|
297
|
+
|
298
|
+
# Handle OpenNebula cluster creation or reuse
|
299
|
+
if !use_defaults
|
300
|
+
# rubocop:disable Layout/LineLength
|
301
|
+
STDOUT.print "\n * vCenter cluster found:\n"\
|
302
|
+
" - Name : \e[92m#{cluster[:simple_name]}\e[39m\n"\
|
303
|
+
" - Location : #{cluster[:cluster_location]}\n"\
|
304
|
+
' Import cluster (y/[n])? '
|
305
|
+
# rubocop:enable Layout/LineLength
|
306
|
+
next if STDIN.gets.strip.downcase != 'y'
|
307
|
+
|
308
|
+
if !cluster_list.empty?
|
309
|
+
# rubocop:disable Layout/LineLength
|
310
|
+
STDOUT.print "\n In which OpenNebula cluster do you want the vCenter cluster to be included?\n "
|
311
|
+
# rubocop:enable Layout/LineLength
|
312
|
+
|
313
|
+
cluster_list_str = "\n"
|
314
|
+
cluster_list.each do |key, value|
|
315
|
+
cluster_list_str << " - \e[94mID: " \
|
316
|
+
<< key \
|
317
|
+
<< "\e[39m - NAME: " \
|
318
|
+
<< value << "\n"
|
319
|
+
end
|
320
|
+
|
321
|
+
STDOUT.print "\n #{cluster_list_str}"
|
322
|
+
# rubocop:disable Layout/LineLength
|
323
|
+
STDOUT.print "\n Specify the ID of the cluster or press Enter if you want OpenNebula to create a new cluster for you: "
|
324
|
+
# rubocop:enable Layout/LineLength
|
325
|
+
answer = STDIN.gets.strip
|
326
|
+
|
327
|
+
if !answer.empty?
|
328
|
+
one_cluster_id = answer
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Check if the OpenNebula Cluster exists, and reuse it
|
334
|
+
one_cluster_id ||= cluster_list
|
335
|
+
.key(cluster[:cluster_name])
|
336
|
+
|
337
|
+
if !one_cluster_id
|
338
|
+
one_cluster = VCenterDriver::VIHelper
|
339
|
+
.new_one_item(OpenNebula::Cluster)
|
340
|
+
rc = one_cluster
|
341
|
+
.allocate((cluster[:cluster_name]).to_s)
|
342
|
+
if ::OpenNebula.is_error?(rc)
|
343
|
+
# rubocop:disable Layout/LineLength
|
344
|
+
STDOUT.puts " Error creating OpenNebula cluster: #{rc.message}\n"
|
345
|
+
# rubocop:enable Layout/LineLength
|
346
|
+
next
|
347
|
+
end
|
348
|
+
one_cluster_id = one_cluster.id
|
349
|
+
end
|
350
|
+
|
351
|
+
# Generate host template and allocate new host
|
352
|
+
one_host = VCenterDriver::ClusterComputeResource
|
353
|
+
.to_one(cluster,
|
354
|
+
con_ops,
|
355
|
+
rpool,
|
356
|
+
one_cluster_id)
|
357
|
+
# rubocop:disable Layout/LineLength
|
358
|
+
STDOUT.puts "\n OpenNebula host \e[92m#{cluster[:cluster_name]}\e[39m with"\
|
359
|
+
" ID \e[94m#{one_host.id}\e[39m successfully created."
|
360
|
+
STDOUT.puts
|
361
|
+
# rubocop:enable Layout/LineLength
|
362
|
+
end
|
363
|
+
end
|
364
|
+
VCenterDriver::VcImporter.register_hooks
|
365
|
+
rescue Interrupt
|
366
|
+
puts "\n"
|
367
|
+
exit 0 # Ctrl+C
|
368
|
+
rescue StandardError => e
|
369
|
+
error_msg = "\nError: #{e.message}\n"
|
370
|
+
error_msg << "#{e.backtrace}\n" \
|
371
|
+
if VCenterDriver::CONFIG[:debug_information]
|
372
|
+
STDOUT.puts error_msg
|
373
|
+
ensure
|
374
|
+
vi_client.close_connection if vi_client
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def self.register_hooks
|
379
|
+
hooks_path = HOOK_LOCATION + '/vcenter/templates'
|
380
|
+
client = OpenNebula::Client.new
|
381
|
+
hook = OpenNebula::Hook.new(OpenNebula::Hook.build_xml, client)
|
382
|
+
hook_files = Dir["#{hooks_path}/*.tmpl"]
|
383
|
+
hook_files.each do |hook_file|
|
384
|
+
hook.allocate(File.open(hook_file).read)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
def self.sanitize(text)
|
389
|
+
bad_chars = ['|']
|
390
|
+
bad_chars.each do |bad_char|
|
391
|
+
text.gsub!(bad_char, '_')
|
392
|
+
end
|
393
|
+
text
|
394
|
+
end
|
395
|
+
|
396
|
+
protected
|
397
|
+
|
398
|
+
#
|
399
|
+
# Object used for stack action and perform rollback
|
400
|
+
#
|
401
|
+
# Constructor:
|
402
|
+
# @param object [Ruby Object] Any object related to the action.
|
403
|
+
# @param method [Symbol] Symbol representing the method
|
404
|
+
# (must belong to object)
|
405
|
+
# @param args [Array] Array with list of arguments,
|
406
|
+
# will be passed to method
|
407
|
+
#
|
408
|
+
# apply:
|
409
|
+
# The stored @object call ther @method with @args
|
410
|
+
class Raction
|
411
|
+
|
412
|
+
def initialize(object, method, args = [])
|
413
|
+
@object = object
|
414
|
+
@action = method
|
415
|
+
@args = args
|
416
|
+
end
|
417
|
+
|
418
|
+
def apply
|
419
|
+
@object.method(@action).call(*@args)
|
420
|
+
end
|
421
|
+
|
422
|
+
def self.delete_ars(ar_ids, opts)
|
423
|
+
error = opts[:error]
|
424
|
+
|
425
|
+
raise error if ar_ids.nil?
|
426
|
+
|
427
|
+
# key = opts[:key]
|
428
|
+
vc_uuid = opts[:uuid]
|
429
|
+
npool = opts[:npool]
|
430
|
+
|
431
|
+
ar_ids.each do |key, value|
|
432
|
+
network = VCenterDriver::VIHelper
|
433
|
+
.find_by_ref(OpenNebula::VirtualNetworkPool,
|
434
|
+
'TEMPLATE/VCENTER_NET_REF',
|
435
|
+
key,
|
436
|
+
vc_uuid, npool)
|
437
|
+
value.each {|ar| network.rm_ar(ar) }
|
438
|
+
end
|
439
|
+
|
440
|
+
raise error
|
441
|
+
end
|
442
|
+
|
443
|
+
end
|
444
|
+
|
445
|
+
#######################################################################
|
446
|
+
# ABSTRACT INTERFACE
|
447
|
+
#######################################################################
|
448
|
+
#
|
449
|
+
# This Interface should be implemented by the specific importer.
|
450
|
+
|
451
|
+
MESS = 'missing method from parent'
|
452
|
+
|
453
|
+
#
|
454
|
+
# Retrieves a list with the unimported resources
|
455
|
+
# The importer needs to perform this operation
|
456
|
+
# before any import operation,
|
457
|
+
#
|
458
|
+
# @param args [Hash] Hash with the needed arguments
|
459
|
+
#
|
460
|
+
# @return [Hash{String => Hash}] operation results.
|
461
|
+
#
|
462
|
+
def get_list(_args = {})
|
463
|
+
raise MESS
|
464
|
+
end
|
465
|
+
|
466
|
+
#
|
467
|
+
# Add certain resource to OpenNebula Cluster.
|
468
|
+
#
|
469
|
+
# @param cid [Int] opennebula cluster id
|
470
|
+
# @param eid [Int] the id of the imported opennebula resource
|
471
|
+
#
|
472
|
+
def add_cluster(_cid, _eid)
|
473
|
+
raise MESS
|
474
|
+
end
|
475
|
+
|
476
|
+
#
|
477
|
+
# Remove the imported resource from the default cluster
|
478
|
+
#
|
479
|
+
# @param id [Int] id of the imported resource
|
480
|
+
#
|
481
|
+
def remove_default(_id)
|
482
|
+
raise MESS
|
483
|
+
end
|
484
|
+
|
485
|
+
#
|
486
|
+
# Retrieves information about the run-time state of a virtual machine.
|
487
|
+
#
|
488
|
+
# @param selected [Hash] Hash with the info of the
|
489
|
+
# vCenter object that will
|
490
|
+
# be imported
|
491
|
+
#
|
492
|
+
# @return [Hash{:id => [], :name => String}] operation results.
|
493
|
+
#
|
494
|
+
def import(_selected)
|
495
|
+
raise MESS
|
496
|
+
end
|
497
|
+
|
498
|
+
#
|
499
|
+
# Create and allocate a Opennebula Object.
|
500
|
+
#
|
501
|
+
# @param info [String] Info passed to opennebula Core.
|
502
|
+
#
|
503
|
+
# @return [&block] the allocated object through a block.
|
504
|
+
#
|
505
|
+
def create(info, &block)
|
506
|
+
resource = VCenterDriver::VIHelper.new_one_item(@one_class)
|
507
|
+
message = 'Error creating the OpenNebula resource'
|
508
|
+
|
509
|
+
rc = resource.allocate(info)
|
510
|
+
VCenterDriver::VIHelper.check_error(rc, message)
|
511
|
+
|
512
|
+
resource.info
|
513
|
+
id = resource['ID']
|
514
|
+
@rollback << Raction.new(resource, :delete)
|
515
|
+
block.call(resource, id)
|
516
|
+
end
|
517
|
+
|
518
|
+
#
|
519
|
+
# Asks if @list is empty
|
520
|
+
#
|
521
|
+
def list_empty?
|
522
|
+
@list == {}
|
523
|
+
end
|
524
|
+
|
525
|
+
#
|
526
|
+
# Gets a certain element from the list, ref given.
|
527
|
+
#
|
528
|
+
# @param ref [String] vCenter reference and index of importer list.
|
529
|
+
#
|
530
|
+
# @return [Hash] Hash with all the info related to the reference
|
531
|
+
#
|
532
|
+
def get_element(ref)
|
533
|
+
raise 'the list is empty' if list_empty? || @list.values[0].empty?
|
534
|
+
|
535
|
+
list = @list.values[0]
|
536
|
+
|
537
|
+
return list[ref] if list[ref]
|
538
|
+
|
539
|
+
raise "#{ref} not found!"
|
540
|
+
end
|
541
|
+
|
542
|
+
#
|
543
|
+
# Add the imported resources to n OpenNebula Clusters.
|
544
|
+
# And remove the default one(0).
|
545
|
+
#
|
546
|
+
# @param one_id [Int] The id of the imported OpenNebula object.
|
547
|
+
# @param clusters [Array] Array with all the ids of the desired
|
548
|
+
# OpenNebula clusters.
|
549
|
+
#
|
550
|
+
def add_clusters(one_id, clusters)
|
551
|
+
clusters.each do |cid|
|
552
|
+
next if cid < 0
|
553
|
+
|
554
|
+
@info[:clusters][cid] ||= VCenterDriver::VIHelper
|
555
|
+
.one_item(OpenNebula::Cluster,
|
556
|
+
cid.to_s,
|
557
|
+
false)
|
558
|
+
rc = add_cluster(cid, one_id.to_i)
|
559
|
+
VCenterDriver::VIHelper
|
560
|
+
.check_error(rc, 'add element to cluster')
|
561
|
+
end
|
562
|
+
remove_default(one_id)
|
563
|
+
end
|
564
|
+
|
565
|
+
#
|
566
|
+
# Call this function to use the rollback Stack, and delete every
|
567
|
+
# corrupted object created by the importer.
|
568
|
+
#
|
569
|
+
def apply_rollback
|
570
|
+
return if @rollback.empty?
|
571
|
+
|
572
|
+
@rollback.each do |action|
|
573
|
+
action.apply
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
#
|
578
|
+
# Default opts
|
579
|
+
#
|
580
|
+
def defaults
|
581
|
+
return @defaults if @defaults
|
582
|
+
|
583
|
+
{}
|
584
|
+
end
|
585
|
+
|
586
|
+
def create_pools
|
587
|
+
dpool = VCenterDriver::VIHelper.one_pool(OpenNebula::DatastorePool)
|
588
|
+
if dpool.respond_to?(:message)
|
589
|
+
raise "Could not get OpenNebula DatastorePool: \
|
590
|
+
#{dpool.message}"
|
591
|
+
end
|
592
|
+
|
593
|
+
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
|
594
|
+
if ipool.respond_to?(:message)
|
595
|
+
raise "Could not get OpenNebula ImagePool: #{ipool.message}"
|
596
|
+
end
|
597
|
+
|
598
|
+
npool = VCenterDriver::VIHelper
|
599
|
+
.one_pool(OpenNebula::VirtualNetworkPool)
|
600
|
+
if npool.respond_to?(:message)
|
601
|
+
raise "Could not get OpenNebula VirtualNetworkPool: \
|
602
|
+
#{npool.message}"
|
603
|
+
end
|
604
|
+
|
605
|
+
hpool = VCenterDriver::VIHelper.one_pool(OpenNebula::HostPool)
|
606
|
+
if hpool.respond_to?(:message)
|
607
|
+
raise "Could not get OpenNebula VirtualNetworkPool: \
|
608
|
+
#{hpool.message}"
|
609
|
+
end
|
610
|
+
|
611
|
+
[dpool, ipool, npool, hpool]
|
612
|
+
end
|
613
|
+
|
614
|
+
end
|
615
|
+
|
616
|
+
end
|