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
data/lib/network.rb
ADDED
@@ -0,0 +1,635 @@
|
|
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
|
+
require 'digest'
|
18
|
+
|
19
|
+
##############################################################################
|
20
|
+
# Module VCenterDriver
|
21
|
+
##############################################################################
|
22
|
+
module VCenterDriver
|
23
|
+
|
24
|
+
##########################################################################
|
25
|
+
# Class NetworkFolder
|
26
|
+
##########################################################################
|
27
|
+
class NetworkFolder
|
28
|
+
|
29
|
+
attr_accessor :item, :items
|
30
|
+
|
31
|
+
def initialize(item)
|
32
|
+
@item = item
|
33
|
+
@items = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
######################################################################
|
37
|
+
# Builds a hash with Network-Ref / Network to be used as a cache
|
38
|
+
# @return [Hash] in the form
|
39
|
+
# { ds_ref [Symbol] => Network object }
|
40
|
+
######################################################################
|
41
|
+
def fetch!
|
42
|
+
VIClient.get_entities(@item, 'Network').each do |item|
|
43
|
+
item_name = item._ref
|
44
|
+
@items[item_name.to_sym] = PortGroup.new(item)
|
45
|
+
end
|
46
|
+
|
47
|
+
VIClient
|
48
|
+
.get_entities(
|
49
|
+
@item,
|
50
|
+
'DistributedVirtualPortgroup'
|
51
|
+
).each do |item|
|
52
|
+
item_name = item._ref
|
53
|
+
@items[item_name.to_sym] = DistributedPortGroup.new(item)
|
54
|
+
end
|
55
|
+
|
56
|
+
VIClient
|
57
|
+
.get_entities(
|
58
|
+
@item,
|
59
|
+
'VmwareDistributedVirtualSwitch'
|
60
|
+
).each do |item|
|
61
|
+
item_name = item._ref
|
62
|
+
@items[item_name.to_sym] = DistributedVirtualSwitch.new(item)
|
63
|
+
end
|
64
|
+
|
65
|
+
VIClient.get_entities(@item, 'OpaqueNetwork').each do |item|
|
66
|
+
item_name = item._ref
|
67
|
+
@items[item_name.to_sym] = OpaqueNetwork.new(item)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
########################################################################
|
72
|
+
# Returns a Network. Uses the cache if available.
|
73
|
+
# @param ref [Symbol] the vcenter ref
|
74
|
+
# @return Network
|
75
|
+
########################################################################
|
76
|
+
def get(ref)
|
77
|
+
if !@items[ref.to_sym]
|
78
|
+
rbvmomi_net = RbVmomi::VIM::Network.new(@item._connection, ref)
|
79
|
+
@items[ref.to_sym] = Network.new(rbvmomi_net)
|
80
|
+
end
|
81
|
+
|
82
|
+
@items[ref.to_sym]
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
# class NetworkFolder
|
87
|
+
|
88
|
+
##########################################################################
|
89
|
+
# Class Network
|
90
|
+
##########################################################################
|
91
|
+
class Network
|
92
|
+
|
93
|
+
attr_accessor :item
|
94
|
+
|
95
|
+
include Memoize
|
96
|
+
|
97
|
+
NETWORK_TYPE_PG = 'Port Group'
|
98
|
+
NETWORK_TYPE_DPG = 'Distributed Port Group'
|
99
|
+
NETWORK_TYPE_NSXV = 'NSX-V' # "Virtual Wire"
|
100
|
+
NETWORK_TYPE_NSXT = 'Opaque Network'
|
101
|
+
NETWORK_TYPE_UNKNOWN = 'Unknown Network'
|
102
|
+
|
103
|
+
def initialize(item, vi_client = nil, check = true)
|
104
|
+
if check
|
105
|
+
begin
|
106
|
+
check_item(item, RbVmomi::VIM::Network)
|
107
|
+
rescue StandardError
|
108
|
+
check_item(item, RbVmomi::VIM::DistributedVirtualPortgroup)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
@vi_client = vi_client
|
113
|
+
@item = item
|
114
|
+
end
|
115
|
+
|
116
|
+
# Checks if a RbVmomi::VIM::VirtualDevice is a network interface
|
117
|
+
def self.nic?(device)
|
118
|
+
!device
|
119
|
+
.class
|
120
|
+
.ancestors
|
121
|
+
.index(
|
122
|
+
RbVmomi::VIM::VirtualEthernetCard
|
123
|
+
).nil?
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.vlanid(vid)
|
127
|
+
case vid
|
128
|
+
when -1
|
129
|
+
'error'
|
130
|
+
when 0
|
131
|
+
'disabled'
|
132
|
+
when 4095
|
133
|
+
'VGT'
|
134
|
+
else
|
135
|
+
vid.to_s
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.retrieve_vlanid(network)
|
140
|
+
begin
|
141
|
+
name = network.name
|
142
|
+
id = network
|
143
|
+
.host
|
144
|
+
.first
|
145
|
+
.configManager
|
146
|
+
.networkSystem
|
147
|
+
.networkConfig
|
148
|
+
.portgroup
|
149
|
+
.select do |p|
|
150
|
+
p.spec.name == name
|
151
|
+
end.first.spec.vlanId
|
152
|
+
rescue StandardError
|
153
|
+
id = -1
|
154
|
+
end
|
155
|
+
id
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.generate_name(name, opts = {})
|
159
|
+
vcenter_instance_name = opts[:vcenter_name] || nil
|
160
|
+
dc_name = opts[:dc_name] || nil
|
161
|
+
|
162
|
+
hash_name = "#{name} - [#{vcenter_instance_name} - #{dc_name}]"
|
163
|
+
sha256 = Digest::SHA256.new
|
164
|
+
network_hash = sha256.hexdigest(hash_name)[0..11]
|
165
|
+
"#{name} - [#{vcenter_instance_name} - #{dc_name}]_#{network_hash}"
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.to_one_template(opts = {})
|
169
|
+
one_tmp = {}
|
170
|
+
network_name = opts[:network_name]
|
171
|
+
network_ref = opts[:network_ref]
|
172
|
+
network_type = opts[:network_type]
|
173
|
+
sw_name = opts[:sw_name]
|
174
|
+
|
175
|
+
vcenter_uuid = opts[:vcenter_uuid]
|
176
|
+
cluster_id = opts[:cluster_id]
|
177
|
+
|
178
|
+
unmanaged = opts[:unmanaged] || nil
|
179
|
+
template_ref = opts[:template_ref] || nil
|
180
|
+
dc_ref = opts[:dc_ref] || nil
|
181
|
+
template_id = opts[:template_id] || nil
|
182
|
+
|
183
|
+
nsx_id = opts[:nsx_id] || nil
|
184
|
+
nsx_vni = opts[:nsx_vni] || nil
|
185
|
+
nsx_tz_id = opts[:nsx_tz_id] || nil
|
186
|
+
|
187
|
+
vlanid = opts[:vlanid] || nil
|
188
|
+
|
189
|
+
bridge_name = network_name
|
190
|
+
network_name = network_name.gsub('/', '_')
|
191
|
+
|
192
|
+
network_import_name =
|
193
|
+
VCenterDriver::VIHelper
|
194
|
+
.one_name(
|
195
|
+
OpenNebula::VirtualNetworkPool,
|
196
|
+
network_name,
|
197
|
+
network_ref+vcenter_uuid
|
198
|
+
)
|
199
|
+
|
200
|
+
one_tmp[:name] = bridge_name
|
201
|
+
one_tmp[:import_name] = network_import_name
|
202
|
+
one_tmp[:bridge] = bridge_name
|
203
|
+
one_tmp[:type] = network_type
|
204
|
+
one_tmp[:one_cluster_id] = cluster_id
|
205
|
+
one_tmp[:ref] = network_ref
|
206
|
+
|
207
|
+
opts = {
|
208
|
+
:network_import_name => network_import_name,
|
209
|
+
:bridge_name => bridge_name,
|
210
|
+
:network_ref => network_ref,
|
211
|
+
:network_type => network_type,
|
212
|
+
:vcenter_uuid => vcenter_uuid,
|
213
|
+
:unmanaged => unmanaged,
|
214
|
+
:template_ref => template_ref,
|
215
|
+
:dc_ref => dc_ref,
|
216
|
+
:template_id => template_id,
|
217
|
+
:sw_name => sw_name,
|
218
|
+
:nsx_id => nsx_id,
|
219
|
+
:nsx_vni => nsx_vni,
|
220
|
+
:nsx_tz_id => nsx_tz_id,
|
221
|
+
:vlanid => vlanid
|
222
|
+
}
|
223
|
+
|
224
|
+
one_tmp[:one] = to_one(opts)
|
225
|
+
one_tmp
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.to_one(opts)
|
229
|
+
template = "NAME=\"#{opts[:network_import_name]}\"\n"\
|
230
|
+
"BRIDGE=\"#{opts[:bridge_name]}\"\n"\
|
231
|
+
"VN_MAD=\"vcenter\"\n"\
|
232
|
+
"VCENTER_PORTGROUP_TYPE=\"#{opts[:network_type]}\"\n"\
|
233
|
+
"VCENTER_NET_REF=\"#{opts[:network_ref]}\"\n"\
|
234
|
+
"VCENTER_INSTANCE_ID=\"#{opts[:vcenter_uuid]}\"\n"\
|
235
|
+
"VCENTER_IMPORTED=\"YES\"\n"
|
236
|
+
|
237
|
+
if opts[:unmanaged] == 'wild'
|
238
|
+
template += "VCENTER_FROM_WILD=\"#{opts[:template_id]}\"\n"
|
239
|
+
end
|
240
|
+
|
241
|
+
if opts[:template_ref]
|
242
|
+
template +=
|
243
|
+
"VCENTER_TEMPLATE_REF=\"#{opts[:template_ref]}\"\n"
|
244
|
+
end
|
245
|
+
|
246
|
+
if opts[:sw_name]
|
247
|
+
template +=
|
248
|
+
"VCENTER_SWITCH_NAME=\"#{opts[:sw_name]}\"\n"
|
249
|
+
end
|
250
|
+
|
251
|
+
if opts[:nsx_id]
|
252
|
+
template +=
|
253
|
+
"NSX_ID=\"#{opts[:nsx_id]}\"\n"
|
254
|
+
end
|
255
|
+
if opts[:nsx_vni]
|
256
|
+
template +=
|
257
|
+
"NSX_VNI=\"#{opts[:nsx_vni]}\"\n"
|
258
|
+
end
|
259
|
+
if opts[:nsx_tz_id]
|
260
|
+
template +=
|
261
|
+
"NSX_TZ_ID=\"#{opts[:nsx_tz_id]}\"\n"
|
262
|
+
end
|
263
|
+
|
264
|
+
if opts[:vlanid]
|
265
|
+
template +=
|
266
|
+
"VCENTER_VLAN_ID=\"#{opts[:vlanid]}\"\n"
|
267
|
+
end
|
268
|
+
|
269
|
+
template
|
270
|
+
end
|
271
|
+
|
272
|
+
REQUIRED_ATTRS = [:refs, :one_ids, :one_object]
|
273
|
+
def self.create_one_network(net_config)
|
274
|
+
# mandatory parameters:
|
275
|
+
REQUIRED_ATTRS.each do |attr|
|
276
|
+
if net_config[attr].nil?
|
277
|
+
raise "#{attr} required for importing nics operation!"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
one_vn = VCenterDriver::VIHelper
|
282
|
+
.new_one_item(
|
283
|
+
OpenNebula::VirtualNetwork
|
284
|
+
)
|
285
|
+
|
286
|
+
done = []
|
287
|
+
(0..net_config[:refs].size-1).each do |i|
|
288
|
+
cl_id = net_config[:one_ids][i]
|
289
|
+
next if cl_id == -1 || done.include?(cl_id)
|
290
|
+
|
291
|
+
if done.empty?
|
292
|
+
rc = one_vn.allocate(net_config[:one_object], cl_id.to_i)
|
293
|
+
VCenterDriver::VIHelper.check_error(rc, 'create network')
|
294
|
+
one_vn.info
|
295
|
+
else
|
296
|
+
one_cluster = VCenterDriver::VIHelper
|
297
|
+
.one_item(
|
298
|
+
OpenNebula::Cluster,
|
299
|
+
cl_id,
|
300
|
+
false
|
301
|
+
)
|
302
|
+
rc = one_cluster.addvnet(one_vn['ID'].to_i)
|
303
|
+
VCenterDriver::VIHelper
|
304
|
+
.check_error(rc, 'addvnet to cluster')
|
305
|
+
end
|
306
|
+
done << cl_id
|
307
|
+
end
|
308
|
+
|
309
|
+
one_vn
|
310
|
+
end
|
311
|
+
|
312
|
+
def self.get_network_type(network, network_name)
|
313
|
+
case network
|
314
|
+
when RbVmomi::VIM::DistributedVirtualPortgroup
|
315
|
+
if network_name
|
316
|
+
.match(/^vxw-dvs-(.*)-virtualwire-(.*)-sid-(.*)/)
|
317
|
+
VCenterDriver::Network::NETWORK_TYPE_NSXV
|
318
|
+
else
|
319
|
+
VCenterDriver::Network::NETWORK_TYPE_DPG
|
320
|
+
end
|
321
|
+
when RbVmomi::VIM::OpaqueNetwork
|
322
|
+
VCenterDriver::Network::NETWORK_TYPE_NSXT
|
323
|
+
when RbVmomi::VIM::Network
|
324
|
+
VCenterDriver::Network::NETWORK_TYPE_PG
|
325
|
+
else
|
326
|
+
VCenterDriver::Network::NETWORK_TYPE_UNKNOWN
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
# Get vSwitch of Standard PortGroup
|
331
|
+
# If there is differents vSwitches returns the first.
|
332
|
+
def self.virtual_switch(vc_pg)
|
333
|
+
vswitch = []
|
334
|
+
vc_hosts = vc_pg.host
|
335
|
+
vc_hosts.each do |vc_host|
|
336
|
+
host_pgs = vc_host
|
337
|
+
.configManager
|
338
|
+
.networkSystem
|
339
|
+
.networkInfo
|
340
|
+
.portgroup
|
341
|
+
host_pgs.each do |pg|
|
342
|
+
if vc_pg.name == pg.spec.name
|
343
|
+
vswitch << pg.spec.vswitchName
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
vswitch.uniq!
|
348
|
+
vswitch << 'Invalid configuration' if vswitch.length > 1
|
349
|
+
vswitch.join(' / ')
|
350
|
+
end
|
351
|
+
|
352
|
+
def self.remove_net_ref(network_id)
|
353
|
+
one_vnet = VCenterDriver::VIHelper
|
354
|
+
.one_item(
|
355
|
+
OpenNebula::VirtualNetwork,
|
356
|
+
network_id
|
357
|
+
)
|
358
|
+
one_vnet.info
|
359
|
+
one_vnet.delete_element('TEMPLATE/VCENTER_NET_REF')
|
360
|
+
one_vnet.delete_element('TEMPLATE/VCENTER_INSTANCE_ID')
|
361
|
+
tmp_str = one_vnet.template_str
|
362
|
+
one_vnet.update(tmp_str)
|
363
|
+
one_vnet.info
|
364
|
+
end
|
365
|
+
|
366
|
+
# This is never cached
|
367
|
+
def self.new_from_ref(ref, vi_client)
|
368
|
+
new(RbVmomi::VIM::Network.new(vi_client.vim, ref), vi_client)
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
# class Network
|
373
|
+
|
374
|
+
##########################################################################
|
375
|
+
# Class PortGroup
|
376
|
+
##########################################################################
|
377
|
+
class PortGroup < Network
|
378
|
+
|
379
|
+
def initialize(item, vi_client = nil, _check = true)
|
380
|
+
check_item(item, RbVmomi::VIM::Network)
|
381
|
+
|
382
|
+
super(item, vi_client, false)
|
383
|
+
end
|
384
|
+
|
385
|
+
def clusters
|
386
|
+
net_clusters = {}
|
387
|
+
host_members =@item['host']
|
388
|
+
host_members.each do |h|
|
389
|
+
if !net_clusters.key?(h.parent._ref.to_s)
|
390
|
+
net_clusters[h.parent._ref.to_s] = h.parent.name.to_s
|
391
|
+
end
|
392
|
+
end
|
393
|
+
net_clusters
|
394
|
+
end
|
395
|
+
|
396
|
+
def network_type
|
397
|
+
VCenterDriver::Network::NETWORK_TYPE_PG
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
# class PortGroup
|
402
|
+
|
403
|
+
##########################################################################
|
404
|
+
# Class DistributedPortGroup
|
405
|
+
##########################################################################
|
406
|
+
class DistributedPortGroup < Network
|
407
|
+
|
408
|
+
def initialize(item, vi_client = nil, _check = true)
|
409
|
+
check_item(item, RbVmomi::VIM::DistributedVirtualPortgroup)
|
410
|
+
|
411
|
+
super(item, vi_client, false)
|
412
|
+
end
|
413
|
+
|
414
|
+
def clusters
|
415
|
+
net_clusters = {}
|
416
|
+
# should have to work
|
417
|
+
# host_members =@item['host']
|
418
|
+
host_members =
|
419
|
+
self['config.distributedVirtualSwitch.summary.hostMember']
|
420
|
+
host_members.each do |h|
|
421
|
+
if !net_clusters.key?(h.parent._ref.to_s)
|
422
|
+
net_clusters[h.parent._ref.to_s] = h.parent.name.to_s
|
423
|
+
end
|
424
|
+
end
|
425
|
+
net_clusters
|
426
|
+
end
|
427
|
+
|
428
|
+
def network_type
|
429
|
+
VCenterDriver::Network::NETWORK_TYPE_DPG
|
430
|
+
end
|
431
|
+
|
432
|
+
end
|
433
|
+
# class DistributedPortGroup
|
434
|
+
|
435
|
+
##########################################################################
|
436
|
+
# Class OpaqueNetwork
|
437
|
+
##########################################################################
|
438
|
+
class OpaqueNetwork < Network
|
439
|
+
|
440
|
+
def initialize(item, vi_client = nil, _check = true)
|
441
|
+
check_item(item, RbVmomi::VIM::OpaqueNetwork)
|
442
|
+
|
443
|
+
super(item, vi_client, false)
|
444
|
+
end
|
445
|
+
|
446
|
+
def clusters
|
447
|
+
net_clusters = {}
|
448
|
+
host_members =@item['host']
|
449
|
+
host_members.each do |h|
|
450
|
+
if !net_clusters.key?(h.parent._ref.to_s)
|
451
|
+
net_clusters[h.parent._ref.to_s] = h.parent.name.to_s
|
452
|
+
end
|
453
|
+
end
|
454
|
+
net_clusters
|
455
|
+
end
|
456
|
+
|
457
|
+
def network_type
|
458
|
+
VCenterDriver::Network::NETWORK_TYPE_NSXT
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
# class OpaqueNetwork
|
463
|
+
|
464
|
+
##########################################################################
|
465
|
+
# Class DistributedVirtualSwitch
|
466
|
+
##########################################################################
|
467
|
+
class DistributedVirtualSwitch < Network
|
468
|
+
|
469
|
+
def initialize(item, vi_client = nil, _check = true)
|
470
|
+
check_item(item, RbVmomi::VIM::VmwareDistributedVirtualSwitch)
|
471
|
+
|
472
|
+
super(item, vi_client, false)
|
473
|
+
end
|
474
|
+
|
475
|
+
end
|
476
|
+
# class DistributedVirtualSwitch
|
477
|
+
|
478
|
+
##########################################################################
|
479
|
+
# Class NetImporter
|
480
|
+
##########################################################################
|
481
|
+
class NetImporter < VCenterDriver::VcImporter
|
482
|
+
|
483
|
+
def initialize(one_client, vi_client)
|
484
|
+
super(one_client, vi_client)
|
485
|
+
@one_class = OpenNebula::VirtualNetwork
|
486
|
+
@defaults = { :size => '255', :type => 'ether' }
|
487
|
+
end
|
488
|
+
|
489
|
+
def get_list(args = {})
|
490
|
+
dc_folder = VCenterDriver::DatacenterFolder.new(@vi_client)
|
491
|
+
|
492
|
+
# OpenNebula's VirtualNetworkPool
|
493
|
+
npool = VCenterDriver::VIHelper
|
494
|
+
.one_pool(
|
495
|
+
OpenNebula::VirtualNetworkPool,
|
496
|
+
false
|
497
|
+
)
|
498
|
+
if npool.respond_to?(:message)
|
499
|
+
raise "Could not get \
|
500
|
+
OpenNebula VirtualNetworkPool: #{npool.message}"
|
501
|
+
end
|
502
|
+
|
503
|
+
# Get OpenNebula's host pool
|
504
|
+
hpool = VCenterDriver::VIHelper
|
505
|
+
.one_pool(
|
506
|
+
OpenNebula::HostPool,
|
507
|
+
false
|
508
|
+
)
|
509
|
+
if hpool.respond_to?(:message)
|
510
|
+
raise "Could not get OpenNebula HostPool: #{hpool.message}"
|
511
|
+
end
|
512
|
+
|
513
|
+
rs = dc_folder
|
514
|
+
.get_unimported_networks(
|
515
|
+
npool,
|
516
|
+
@vi_client.vc_name,
|
517
|
+
hpool,
|
518
|
+
args
|
519
|
+
)
|
520
|
+
@list = rs
|
521
|
+
end
|
522
|
+
|
523
|
+
def add_cluster(cid, eid)
|
524
|
+
one_cluster = @info[:clusters][cid]
|
525
|
+
raise 'no cluster defined' unless one_cluster
|
526
|
+
|
527
|
+
one_cluster.addvnet(eid)
|
528
|
+
end
|
529
|
+
|
530
|
+
def remove_default(id)
|
531
|
+
cid = 0
|
532
|
+
@info[:clusters][cid] ||=
|
533
|
+
VCenterDriver::VIHelper
|
534
|
+
.one_item(
|
535
|
+
OpenNebula::Cluster,
|
536
|
+
cid.to_s,
|
537
|
+
false
|
538
|
+
)
|
539
|
+
@info[:clusters][cid].delvnet(id.to_i)
|
540
|
+
end
|
541
|
+
|
542
|
+
def build_ar(opts)
|
543
|
+
str = "\nAR=[TYPE=\""
|
544
|
+
type = opts[:type].downcase
|
545
|
+
|
546
|
+
case type
|
547
|
+
when '4', 'ip4', 'ip'
|
548
|
+
str << 'IP4"'
|
549
|
+
opts[:ip] = '192.168.1.1' if opts[:ip].empty?
|
550
|
+
str << ",IP=\"#{opts[:ip]}\""
|
551
|
+
when 'ip6'
|
552
|
+
str << 'IP6"'
|
553
|
+
if opts[:global_prefix]
|
554
|
+
str << ",GLOBAL_PREFIX=\"#{opts[:global_prefix]}\""
|
555
|
+
end
|
556
|
+
if opts[:ula_prefix]
|
557
|
+
str << ",ULA_PREFIX=\"#{opts[:ula_prefix]}\""
|
558
|
+
end
|
559
|
+
when 'ether', 'e'
|
560
|
+
str << 'ETHER"'
|
561
|
+
when 'ip6_static'
|
562
|
+
str << 'IP6_STATIC"'
|
563
|
+
str << ",IP6=\"#{opts[:ip6]}\"" if opts[:ip6]
|
564
|
+
if opts[:prefix_length]
|
565
|
+
str << ",PREFIX_LENGTH=\"#{opts[:prefix_length]}\""
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
str << ",MAC=\"#{opts[:mac]}\"" if opts[:mac]
|
570
|
+
str << ",SIZE = \"#{opts[:size]}\"]"
|
571
|
+
|
572
|
+
str
|
573
|
+
end
|
574
|
+
|
575
|
+
def import(selected)
|
576
|
+
opts = @info[selected[:ref]][:opts]
|
577
|
+
|
578
|
+
net = VCenterDriver::Network
|
579
|
+
.new_from_ref(selected[:ref], @vi_client)
|
580
|
+
if net
|
581
|
+
vid = VCenterDriver::Network
|
582
|
+
.retrieve_vlanid(net.item)
|
583
|
+
end
|
584
|
+
|
585
|
+
# If type is NSX we need to update values
|
586
|
+
if selected[:type] == VCenterDriver::Network::NETWORK_TYPE_NSXV
|
587
|
+
host_id = @vi_client.instance_variable_get '@host_id'
|
588
|
+
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
589
|
+
nsx_net = NSXDriver::VirtualWire
|
590
|
+
.new_from_name(nsx_client, selected[:name])
|
591
|
+
selected[:one] << "NSX_ID=\"#{nsx_net.ls_id}\"\n"
|
592
|
+
selected[:one] << "NSX_VNI=\"#{nsx_net.ls_vni}\"\n"
|
593
|
+
selected[:one] << "NSX_TZ_ID=\"#{nsx_net.tz_id}\"\n"
|
594
|
+
end
|
595
|
+
|
596
|
+
if selected[:type] == VCenterDriver::Network::NETWORK_TYPE_NSXT
|
597
|
+
host_id = @vi_client.instance_variable_get '@host_id'
|
598
|
+
nsx_client = NSXDriver::NSXClient.new_from_id(host_id)
|
599
|
+
nsx_net = NSXDriver::OpaqueNetwork
|
600
|
+
.new_from_name(nsx_client, selected[:name])
|
601
|
+
selected[:one] << "NSX_ID=\"#{nsx_net.ls_id}\"\n"
|
602
|
+
selected[:one] << "NSX_VNI=\"#{nsx_net.ls_vni}\"\n"
|
603
|
+
selected[:one] << "NSX_TZ_ID=\"#{nsx_net.tz_id}\"\n"
|
604
|
+
end
|
605
|
+
|
606
|
+
if vid
|
607
|
+
vlanid = VCenterDriver::Network.vlanid(vid)
|
608
|
+
|
609
|
+
# we have vlan id
|
610
|
+
if /\A\d+\z/.match(vlanid)
|
611
|
+
selected[:one] << "VCENTER_VLAN_ID=\"#{vlanid}\"\n"
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
615
|
+
selected[:one] << build_ar(opts)
|
616
|
+
if opts['selected_clusters']
|
617
|
+
selected[:clusters][:one_ids] =
|
618
|
+
opts['selected_clusters']
|
619
|
+
.each
|
620
|
+
.map(&:to_i)
|
621
|
+
end
|
622
|
+
|
623
|
+
res = { :id => [], :name => selected[:name] }
|
624
|
+
create(selected[:one]) do |_one_object, id|
|
625
|
+
res[:id] << id
|
626
|
+
add_clusters(id, selected[:clusters][:one_ids])
|
627
|
+
end
|
628
|
+
|
629
|
+
res
|
630
|
+
end
|
631
|
+
|
632
|
+
end
|
633
|
+
|
634
|
+
end
|
635
|
+
# module VCenterDriver
|