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/nsx_rule.rb
DELETED
@@ -1,206 +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
|
-
require 'ipaddr'
|
18
|
-
|
19
|
-
# Module NSXDriver
|
20
|
-
module NSXDriver
|
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
|
-
else
|
30
|
-
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' \
|
31
|
-
unless defined?(RUBY_LIB_LOCATION)
|
32
|
-
GEMS_LOCATION = ONE_LOCATION + '/share/gems' \
|
33
|
-
unless defined?(GEMS_LOCATION)
|
34
|
-
end
|
35
|
-
|
36
|
-
# rubocop: disable all
|
37
|
-
# %%RUBYGEMS_SETUP_BEGIN%%
|
38
|
-
if File.directory?(GEMS_LOCATION)
|
39
|
-
real_gems_path = File.realpath(GEMS_LOCATION)
|
40
|
-
if !defined?(Gem) || Gem.path != [real_gems_path]
|
41
|
-
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
42
|
-
|
43
|
-
# Suppress warnings from Rubygems
|
44
|
-
# https://github.com/OpenNebula/one/issues/5379
|
45
|
-
begin
|
46
|
-
verb = $VERBOSE
|
47
|
-
$VERBOSE = nil
|
48
|
-
require 'rubygems'
|
49
|
-
Gem.use_paths(real_gems_path)
|
50
|
-
ensure
|
51
|
-
$VERBOSE = verb
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
# %%RUBYGEMS_SETUP_END%%
|
56
|
-
# rubocop: enable all
|
57
|
-
|
58
|
-
$LOAD_PATH << RUBY_LIB_LOCATION
|
59
|
-
|
60
|
-
require 'nsxt_rule'
|
61
|
-
require 'nsxv_rule'
|
62
|
-
|
63
|
-
# Class Logical Switch
|
64
|
-
module NSXRule
|
65
|
-
|
66
|
-
include NSXTRule
|
67
|
-
include NSXVRule
|
68
|
-
|
69
|
-
def to_nets(ip_start, size)
|
70
|
-
nets = []
|
71
|
-
ipaddr = IPAddr.new ip_start
|
72
|
-
ip_i = ipaddr.to_i
|
73
|
-
|
74
|
-
if ipaddr.ipv4?
|
75
|
-
ip_length = 32
|
76
|
-
elsif ipaddr.ipv6?
|
77
|
-
ip_length = 128
|
78
|
-
else
|
79
|
-
return
|
80
|
-
end
|
81
|
-
|
82
|
-
# Find the largest address block (look for the first 1-bit)
|
83
|
-
lblock = 0
|
84
|
-
|
85
|
-
lblock += 1 while ip_i[lblock] == 0 && lblock < ip_length
|
86
|
-
|
87
|
-
# Allocate whole blocks till the size fits
|
88
|
-
while size >= 2**lblock
|
89
|
-
nets << "#{IPAddr.new(ip_i, ipaddr.family)}" \
|
90
|
-
"/#{ip_length-lblock}"
|
91
|
-
|
92
|
-
ip_i += 2**lblock
|
93
|
-
size -= 2**lblock
|
94
|
-
|
95
|
-
lblock += 1 while ip_i[lblock] == 0 && lblock < ip_length
|
96
|
-
end
|
97
|
-
|
98
|
-
# Fit remaining address blocks
|
99
|
-
ip_length.downto(0) do |i|
|
100
|
-
next if size[i] == 0
|
101
|
-
|
102
|
-
nets << "#{IPAddr.new(ip_i, ipaddr.family)}/#{ip_length-i}"
|
103
|
-
|
104
|
-
ip_i += 2**i
|
105
|
-
end
|
106
|
-
|
107
|
-
nets
|
108
|
-
end
|
109
|
-
|
110
|
-
# Adapt port from ["22, 443"] to '22, 443'
|
111
|
-
# Adapt port from ["22", "443"] to '22, 443'
|
112
|
-
def parse_ports(rule_ports)
|
113
|
-
unless rule_ports.empty?
|
114
|
-
rule_ports = rule_ports.join(',')
|
115
|
-
end
|
116
|
-
rule_ports
|
117
|
-
end
|
118
|
-
|
119
|
-
def extract_vnet_data(vnet_id)
|
120
|
-
if vnet_id == ''
|
121
|
-
return {
|
122
|
-
:nsxid => '',
|
123
|
-
:name => ''
|
124
|
-
}
|
125
|
-
end
|
126
|
-
# Create client to communicate with OpenNebula
|
127
|
-
one_client = OpenNebula::Client.new
|
128
|
-
# Get the network XML from OpenNebula
|
129
|
-
# This is potentially different from the Netowrk Template
|
130
|
-
# provided as the API call argument
|
131
|
-
one_vnet = OpenNebula::VirtualNetwork.new_with_id(vnet_id,
|
132
|
-
one_client)
|
133
|
-
rc = one_vnet.info
|
134
|
-
if OpenNebula.is_error?(rc)
|
135
|
-
err_msg = rc.message
|
136
|
-
raise CreateNetworkError, err_msg
|
137
|
-
end
|
138
|
-
{
|
139
|
-
:nsxid => one_vnet['TEMPLATE/NSX_ID'],
|
140
|
-
:name => one_vnet['NAME']
|
141
|
-
}
|
142
|
-
end
|
143
|
-
|
144
|
-
def extract_rule_data(xml_rule)
|
145
|
-
sg_id = xml_rule.xpath('SECURITY_GROUP_ID').text
|
146
|
-
sg_name = xml_rule.xpath('SECURITY_GROUP_NAME').text
|
147
|
-
in_out = xml_rule.xpath('RULE_TYPE').text.upcase
|
148
|
-
in_out == 'INBOUND' ? sg_direction = 'IN' : sg_direction = 'OUT'
|
149
|
-
# Protocol: TCP, UDP, ICMP...
|
150
|
-
sg_protocol = xml_rule.xpath('PROTOCOL').text
|
151
|
-
if sg_protocol == 'ICMP'
|
152
|
-
sg_icmp_type = xml_rule.xpath('ICMP_TYPE').text
|
153
|
-
end
|
154
|
-
# OpenNebula network ID
|
155
|
-
sg_network_id = xml_rule.xpath('NETWORK_ID').text
|
156
|
-
vnet_data = extract_vnet_data(sg_network_id)
|
157
|
-
|
158
|
-
# ip / netmask
|
159
|
-
sg_ip = xml_rule.xpath('IP').text
|
160
|
-
sg_ipsize = xml_rule.xpath('SIZE').text
|
161
|
-
sg_subnets = []
|
162
|
-
if sg_ip != '' && sg_ipsize != ''
|
163
|
-
sg_subnets = to_nets(sg_ip, sg_ipsize.to_i)
|
164
|
-
end
|
165
|
-
# Ports
|
166
|
-
sg_ports = ''
|
167
|
-
sg_range_port = xml_rule.xpath('RANGE').text
|
168
|
-
if sg_range_port
|
169
|
-
if sg_range_port.index(':')
|
170
|
-
sg_port_from = sg_range_port[0..sg_range_port.index(':')-1]
|
171
|
-
sg_port_to = sg_range_port[sg_range_port.index(':')+1,
|
172
|
-
sg_range_port.length]
|
173
|
-
sg_ports = "#{sg_port_from}-#{sg_port_to}"
|
174
|
-
else
|
175
|
-
sg_ports = sg_range_port
|
176
|
-
end
|
177
|
-
end
|
178
|
-
# Create hash with data
|
179
|
-
{
|
180
|
-
:id => sg_id,
|
181
|
-
:name => sg_name,
|
182
|
-
:direction => sg_direction,
|
183
|
-
:protocol => sg_protocol,
|
184
|
-
:icmp_type => sg_icmp_type,
|
185
|
-
:network_id => sg_network_id,
|
186
|
-
:network_name => vnet_data[:name],
|
187
|
-
:network_nsxid => vnet_data[:nsxid],
|
188
|
-
:subnets => sg_subnets,
|
189
|
-
:ports => sg_ports.split(',')
|
190
|
-
}
|
191
|
-
end
|
192
|
-
|
193
|
-
def rule_spec(rule, vm_data, nic_data, nsx_client)
|
194
|
-
case nsx_client.nsx_type
|
195
|
-
when NSXDriver::NSXConstants::NSXT
|
196
|
-
nsxt_rule_spec(rule, vm_data, nic_data)
|
197
|
-
when NSXDriver::NSXConstants::NSXV
|
198
|
-
nsxv_rule_spec(rule, vm_data, nic_data)
|
199
|
-
else
|
200
|
-
raise "Unsupported NSX type: #{nsx_type}"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
data/lib/nsxt_client.rb
DELETED
@@ -1,189 +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
|
-
module NSXDriver
|
17
|
-
|
18
|
-
ONE_LOCATION = ENV['ONE_LOCATION'] unless defined?(ONE_LOCATION)
|
19
|
-
|
20
|
-
if !ONE_LOCATION
|
21
|
-
RUBY_LIB_LOCATION = '/usr/lib/one/ruby' \
|
22
|
-
unless defined?(RUBY_LIB_LOCATION)
|
23
|
-
GEMS_LOCATION = '/usr/share/one/gems' \
|
24
|
-
unless defined?(GEMS_LOCATION)
|
25
|
-
else
|
26
|
-
RUBY_LIB_LOCATION = ONE_LOCATION + '/lib/ruby' \
|
27
|
-
unless defined?(RUBY_LIB_LOCATION)
|
28
|
-
GEMS_LOCATION = ONE_LOCATION + '/share/gems' \
|
29
|
-
unless defined?(GEMS_LOCATION)
|
30
|
-
end
|
31
|
-
|
32
|
-
# rubocop: disable all
|
33
|
-
# %%RUBYGEMS_SETUP_BEGIN%%
|
34
|
-
if File.directory?(GEMS_LOCATION)
|
35
|
-
real_gems_path = File.realpath(GEMS_LOCATION)
|
36
|
-
if !defined?(Gem) || Gem.path != [real_gems_path]
|
37
|
-
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
38
|
-
|
39
|
-
# Suppress warnings from Rubygems
|
40
|
-
# https://github.com/OpenNebula/one/issues/5379
|
41
|
-
begin
|
42
|
-
verb = $VERBOSE
|
43
|
-
$VERBOSE = nil
|
44
|
-
require 'rubygems'
|
45
|
-
Gem.use_paths(real_gems_path)
|
46
|
-
ensure
|
47
|
-
$VERBOSE = verb
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
# %%RUBYGEMS_SETUP_END%%
|
52
|
-
# rubocop: enable all
|
53
|
-
|
54
|
-
$LOAD_PATH << RUBY_LIB_LOCATION
|
55
|
-
|
56
|
-
# Class NSXTClient
|
57
|
-
class NSXTClient < NSXClient
|
58
|
-
|
59
|
-
# ATTIBUTES
|
60
|
-
attr_accessor :nsxmgr
|
61
|
-
attr_accessor :nsx_user
|
62
|
-
attr_accessor :nsx_password
|
63
|
-
attr_accessor :nsx_type
|
64
|
-
|
65
|
-
# CONSTRUCTORS
|
66
|
-
def initialize(nsxmgr, nsx_user, nsx_password)
|
67
|
-
super(nsxmgr, nsx_user, nsx_password)
|
68
|
-
@nsx_type = NSXConstants::NSXT
|
69
|
-
end
|
70
|
-
|
71
|
-
# Prepare headers
|
72
|
-
def add_headers(aditional_headers = [])
|
73
|
-
headers = NSXConstants::HEADER_JSON.clone
|
74
|
-
unless aditional_headers.empty?
|
75
|
-
aditional_headers.each do |header|
|
76
|
-
headers[header.keys[0]] = header.values[0]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
headers
|
80
|
-
end
|
81
|
-
|
82
|
-
# METHODS
|
83
|
-
def get(url, aditional_headers = [], valid_codes = [])
|
84
|
-
if valid_codes.empty?
|
85
|
-
valid_codes = [NSXConstants::CODE_OK,
|
86
|
-
NSXConstants::CODE_NO_CONTENT]
|
87
|
-
end
|
88
|
-
uri = URI.parse(@nsxmgr + url)
|
89
|
-
headers = add_headers(aditional_headers)
|
90
|
-
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
91
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
92
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
93
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
94
|
-
https.request(request)
|
95
|
-
end
|
96
|
-
response = check_response(response, valid_codes)
|
97
|
-
JSON.parse(response.body)
|
98
|
-
end
|
99
|
-
|
100
|
-
def get_full_response(url, aditional_headers = [], valid_codes = [])
|
101
|
-
if valid_codes.empty?
|
102
|
-
valid_codes = [NSXConstants::CODE_OK,
|
103
|
-
NSXConstants::CODE_NO_CONTENT]
|
104
|
-
end
|
105
|
-
uri = URI.parse(@nsxmgr + url)
|
106
|
-
headers = add_headers(aditional_headers)
|
107
|
-
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
108
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
109
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
110
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
111
|
-
https.request(request)
|
112
|
-
end
|
113
|
-
check_response(response, valid_codes)
|
114
|
-
end
|
115
|
-
|
116
|
-
# Return: id of the created object
|
117
|
-
def post(url, data, aditional_headers = [], valid_codes = [])
|
118
|
-
if valid_codes.empty?
|
119
|
-
valid_codes = [NSXConstants::CODE_CREATED,
|
120
|
-
NSXConstants::CODE_OK]
|
121
|
-
end
|
122
|
-
uri = URI.parse(@nsxmgr + url)
|
123
|
-
headers = add_headers(aditional_headers)
|
124
|
-
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
125
|
-
request.body = data
|
126
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
127
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
128
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
129
|
-
https.request(request)
|
130
|
-
end
|
131
|
-
response = check_response(response, valid_codes)
|
132
|
-
response_json = JSON.parse(response.body)
|
133
|
-
response_json['id']
|
134
|
-
end
|
135
|
-
|
136
|
-
def put(url, data, aditional_headers = [], valid_codes = [])
|
137
|
-
if valid_codes.empty?
|
138
|
-
valid_codes = [NSXConstants::CODE_CREATED,
|
139
|
-
NSXConstants::CODE_OK]
|
140
|
-
end
|
141
|
-
uri = URI.parse(@nsxmgr + url)
|
142
|
-
headers = add_headers(aditional_headers)
|
143
|
-
request = Net::HTTP::Put.new(uri.request_uri, headers)
|
144
|
-
request.body = data
|
145
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
146
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
147
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
148
|
-
https.request(request)
|
149
|
-
end
|
150
|
-
response = check_response(response, valid_codes)
|
151
|
-
response_json = JSON.parse(response.body)
|
152
|
-
response_json['id']
|
153
|
-
end
|
154
|
-
|
155
|
-
def delete(url, aditional_headers = [], valid_codes = [])
|
156
|
-
if valid_codes.empty?
|
157
|
-
valid_codes = [NSXConstants::CODE_OK,
|
158
|
-
NSXConstants::CODE_NO_CONTENT]
|
159
|
-
end
|
160
|
-
uri = URI.parse(@nsxmgr + url)
|
161
|
-
headers = add_headers(aditional_headers)
|
162
|
-
request = Net::HTTP::Delete.new(uri.request_uri, headers)
|
163
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
164
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
165
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
166
|
-
https.request(request)
|
167
|
-
end
|
168
|
-
check_response(response, valid_codes)
|
169
|
-
end
|
170
|
-
|
171
|
-
def get_token(url, aditional_headers = [], valid_codes = [])
|
172
|
-
if valid_codes.empty?
|
173
|
-
valid_codes = [NSXConstants::CODE_OK]
|
174
|
-
end
|
175
|
-
uri = URI.parse(@nsxmgr + url)
|
176
|
-
headers = add_headers(aditional_headers)
|
177
|
-
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
178
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
179
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
180
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
181
|
-
https.request(request)
|
182
|
-
end
|
183
|
-
response = check_response(response, valid_codes)
|
184
|
-
response.body
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
data/lib/nsxt_dfw.rb
DELETED
@@ -1,196 +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
|
-
module NSXDriver
|
17
|
-
|
18
|
-
# Class Logical Switch
|
19
|
-
class NSXTdfw < DistributedFirewall
|
20
|
-
|
21
|
-
# ATTRIBUTES
|
22
|
-
attr_reader :one_section_id
|
23
|
-
|
24
|
-
# CONSTRUCTOR
|
25
|
-
# Creates OpenNebula section if not exists
|
26
|
-
def initialize(nsx_client)
|
27
|
-
super(nsx_client)
|
28
|
-
# Construct base URLs
|
29
|
-
@base_url = NSXConstants::NSXT_DFW_BASE
|
30
|
-
@url_sections = @base_url + \
|
31
|
-
NSXConstants::NSXT_DFW_SECTIONS
|
32
|
-
@one_section_id = init_section
|
33
|
-
end
|
34
|
-
|
35
|
-
# Sections
|
36
|
-
# Creates OpenNebula section if not exists and returns
|
37
|
-
# its section_id. Returns its section_id if OpenNebula
|
38
|
-
# section already exists
|
39
|
-
def init_section
|
40
|
-
one_section = section_by_name(NSXConstants::ONE_SECTION_NAME)
|
41
|
-
one_section ||= create_section(NSXConstants::ONE_SECTION_NAME)
|
42
|
-
return one_section['id'] if one_section
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get all sections
|
46
|
-
# Params:
|
47
|
-
# - None
|
48
|
-
# Return
|
49
|
-
# - nil | sections
|
50
|
-
def sections
|
51
|
-
result = @nsx_client.get(@url_sections)
|
52
|
-
result['results']
|
53
|
-
end
|
54
|
-
|
55
|
-
# Get section by id
|
56
|
-
# Params:
|
57
|
-
# - section_id: [String] ID of the section or @one_section_id
|
58
|
-
# Return
|
59
|
-
# - nil | section
|
60
|
-
def section_by_id(section_id = @one_section_id)
|
61
|
-
url = @url_sections + '/' + section_id
|
62
|
-
@nsx_client.get(url)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Get section by name
|
66
|
-
# Params:
|
67
|
-
# - section_name: Name of the section
|
68
|
-
# Return
|
69
|
-
# - nil | section
|
70
|
-
def section_by_name(section_name)
|
71
|
-
result = nil
|
72
|
-
all_sections = sections
|
73
|
-
return result unless all_sections
|
74
|
-
|
75
|
-
all_sections.each do |section|
|
76
|
-
result = section if section['display_name'] == section_name
|
77
|
-
end
|
78
|
-
result
|
79
|
-
end
|
80
|
-
|
81
|
-
# Create new section and return the section
|
82
|
-
def create_section(section_name)
|
83
|
-
section_spec = %(
|
84
|
-
{
|
85
|
-
"display_name": "#{section_name}",
|
86
|
-
"section_type": "LAYER3",
|
87
|
-
"stateful": true
|
88
|
-
}
|
89
|
-
)
|
90
|
-
section_id = @nsx_client.post(@url_sections, section_spec)
|
91
|
-
result = section_by_id(section_id)
|
92
|
-
raise 'Section was not created in DFW' unless result
|
93
|
-
|
94
|
-
result
|
95
|
-
end
|
96
|
-
|
97
|
-
# Delete section
|
98
|
-
# Params:
|
99
|
-
# - section_id: [String] ID of the section or @one_section_id
|
100
|
-
def delete_section(section_id = @one_section_id)
|
101
|
-
url = @url_sections + '/' + section_id
|
102
|
-
@nsx_client.delete(url)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Rules
|
106
|
-
# Get all rules of a Section, OpenNebula section if it's not defined
|
107
|
-
# Return:
|
108
|
-
# - [Array]
|
109
|
-
def rules(section_id = @one_section_id)
|
110
|
-
url = @url_sections + '/' + section_id + '/rules'
|
111
|
-
@nsx_client.get(url)
|
112
|
-
end
|
113
|
-
|
114
|
-
# Get rule by id
|
115
|
-
# Return:
|
116
|
-
# rule | nil
|
117
|
-
def rule_by_id(rule_id)
|
118
|
-
url = @base_url + '/rules/' + rule_id
|
119
|
-
valid_codes = [NSXConstants::CODE_CREATED,
|
120
|
-
NSXConstants::CODE_OK,
|
121
|
-
NSXConstants::CODE_BAD_REQUEST,
|
122
|
-
NSXConstants::CODE_NOT_FOUND]
|
123
|
-
additional_headers = []
|
124
|
-
@nsx_client.get(url, additional_headers, valid_codes)
|
125
|
-
end
|
126
|
-
|
127
|
-
# Get rules by name
|
128
|
-
# Return:
|
129
|
-
# - Array with rules or an empty array
|
130
|
-
def rules_by_name(rule_name, section_id = @one_section_id)
|
131
|
-
rules = []
|
132
|
-
return rules unless section_id
|
133
|
-
|
134
|
-
all_rules = rules(section_id)
|
135
|
-
return rules unless all_rules
|
136
|
-
|
137
|
-
all_rules['results'].each do |rule|
|
138
|
-
rules << rule if rule['display_name'] == rule_name
|
139
|
-
end
|
140
|
-
rules
|
141
|
-
end
|
142
|
-
|
143
|
-
# Get rule by regex
|
144
|
-
# Return:
|
145
|
-
# - Array with rules or an empty array
|
146
|
-
def rules_by_regex(regex, section_id = @one_section_id)
|
147
|
-
rules = []
|
148
|
-
return rules unless section_id
|
149
|
-
|
150
|
-
all_rules = rules(section_id)
|
151
|
-
return rules unless all_rules
|
152
|
-
|
153
|
-
all_rules['results'].each do |rule|
|
154
|
-
rules << rule if rule['display_name'].match(regex)
|
155
|
-
end
|
156
|
-
rules
|
157
|
-
end
|
158
|
-
|
159
|
-
# Create new rule
|
160
|
-
def create_rule(rule_spec, section_id = @one_section_id)
|
161
|
-
# Get revision from section
|
162
|
-
section = section_by_id(section_id)
|
163
|
-
unless section
|
164
|
-
error_msg = "Section with id #{section_id} not found"
|
165
|
-
error = NSXError::ObjectNotFound
|
166
|
-
.new(error_msg)
|
167
|
-
raise error
|
168
|
-
end
|
169
|
-
revision_id = section['_revision']
|
170
|
-
rule_spec['_revision'] = revision_id
|
171
|
-
rule_spec = rule_spec.to_json
|
172
|
-
url = @url_sections + '/' + section_id + '/rules'
|
173
|
-
@nsx_client.post(url, rule_spec)
|
174
|
-
end
|
175
|
-
|
176
|
-
# Update rule
|
177
|
-
def update_rule(rule_id, rule_spec, section_id = @one_section_id)
|
178
|
-
url = @url_sections + '/' + section_id + '/rules/' + rule_id
|
179
|
-
rule = rule_by_id(rule_id)
|
180
|
-
raise "Rule id #{rule_id} not found" unless rule
|
181
|
-
|
182
|
-
rule_spec['_revision'] = rule['_revision']
|
183
|
-
rule_spec = rule_spec.to_json
|
184
|
-
@nsx_client.put(url, rule_spec)
|
185
|
-
end
|
186
|
-
|
187
|
-
# Delete rule
|
188
|
-
def delete_rule(rule_id, section_id = @one_section_id)
|
189
|
-
url = @url_sections + '/' + section_id + '/rules/' + rule_id
|
190
|
-
# Delete receive a 200 OK also if the rule doesn't exist
|
191
|
-
@nsx_client.delete(url)
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
data/lib/nsxt_logical_port.rb
DELETED
@@ -1,94 +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
|
-
module NSXDriver
|
17
|
-
|
18
|
-
# Class NSXTLogicalPort
|
19
|
-
class NSXTLogicalPort < LogicalPort
|
20
|
-
|
21
|
-
# ATTRIBUTES
|
22
|
-
attr_reader :id, :name, :type, :url
|
23
|
-
|
24
|
-
# CONSTRUCTOR
|
25
|
-
# Logical port class variables:
|
26
|
-
# @lp_id
|
27
|
-
# @url_lp
|
28
|
-
# @lp_name
|
29
|
-
# @lp_type
|
30
|
-
def initialize(nsx_client, id = nil, data = nil)
|
31
|
-
super(nsx_client)
|
32
|
-
# lpid can be:
|
33
|
-
# - Logical port attach ID
|
34
|
-
if id
|
35
|
-
initialize_with_id(id)
|
36
|
-
else
|
37
|
-
if data
|
38
|
-
begin
|
39
|
-
@id = new_logical_port(data)
|
40
|
-
rescue NSXError::IncorrectResponseCodeError => e
|
41
|
-
raise 'Logical Port not created in ' \
|
42
|
-
"NSX Manager: #{e.message}"
|
43
|
-
end
|
44
|
-
unless @id
|
45
|
-
raise 'Logical Port not created in NSX Manager: '\
|
46
|
-
'generic error'
|
47
|
-
end
|
48
|
-
# Construct logical port class variables
|
49
|
-
@url = NSXConstants::NSXT_LP_BASE + @id
|
50
|
-
@name = lp_name
|
51
|
-
@type = lp_type
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Creates a NSXTLogicalPort from its id
|
57
|
-
def initialize_with_id(id)
|
58
|
-
@id = lp_with_attachid(id)
|
59
|
-
# Construct URL of the created logical switch
|
60
|
-
@url = NSXConstants::NSXT_LP_BASE + @id
|
61
|
-
return unless lp?
|
62
|
-
|
63
|
-
@name = lp_name
|
64
|
-
@type = lp_type
|
65
|
-
end
|
66
|
-
|
67
|
-
# Check if logical port exists
|
68
|
-
def lp?
|
69
|
-
@nsx_client.get(@url)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Get logical port id from attach id
|
73
|
-
def lp_with_attachid(attach_id)
|
74
|
-
lps = @nsx_client.get(NSXConstants::NSXT_LP_BASE)
|
75
|
-
lps['results'].each do |lp|
|
76
|
-
return lp['id'] if lp['attachment']['id'] == attach_id
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# # Get logical port display name
|
81
|
-
def lp_name
|
82
|
-
lp = @nsx_client.get(@url)
|
83
|
-
lp['display_name']
|
84
|
-
end
|
85
|
-
|
86
|
-
# # Get resource type
|
87
|
-
def lp_type
|
88
|
-
lp = @nsx_client.get(@url)
|
89
|
-
lp['resource_type']
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|