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/nsxt_rule.rb
DELETED
@@ -1,188 +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
|
-
module NSXRule
|
19
|
-
|
20
|
-
# Class Logical Switch
|
21
|
-
module NSXTRule
|
22
|
-
|
23
|
-
def nsxt_rule_spec(rule, vm_data, nic_data)
|
24
|
-
# default spec
|
25
|
-
# Allow any-any to any port applied on the
|
26
|
-
# virtual machine logical port
|
27
|
-
rule_name = "#{rule[:id]}-#{rule[:name]}-#{vm_data[:id]}"
|
28
|
-
rule_name << "-#{vm_data[:deploy_id]}-#{nic_data[:id]}"
|
29
|
-
rule_spec = {
|
30
|
-
:display_name => rule_name,
|
31
|
-
:destinations_excluded => false,
|
32
|
-
:sources => [],
|
33
|
-
:destinations => [],
|
34
|
-
:services => [],
|
35
|
-
:applied_tos => [
|
36
|
-
{
|
37
|
-
:target_id => nic_data[:lp].id,
|
38
|
-
:target_display_name => nic_data[:name],
|
39
|
-
:target_type => nic_data[:lp].type,
|
40
|
-
:is_valid => true
|
41
|
-
}
|
42
|
-
],
|
43
|
-
:ip_protocol => 'IPV4_IPV6',
|
44
|
-
:logged => false,
|
45
|
-
:action => 'ALLOW',
|
46
|
-
:sources_excluded => false,
|
47
|
-
:disabled => false,
|
48
|
-
:direction => rule[:direction]
|
49
|
-
}
|
50
|
-
|
51
|
-
rule_protocol_template = {
|
52
|
-
'TCP' => [
|
53
|
-
{
|
54
|
-
:service => {
|
55
|
-
:l4_protocol => 'TCP',
|
56
|
-
:source_ports => [],
|
57
|
-
:destination_ports => [],
|
58
|
-
:resource_type => 'L4PortSetNSService'
|
59
|
-
}
|
60
|
-
}
|
61
|
-
],
|
62
|
-
'UDP' => [
|
63
|
-
{
|
64
|
-
:service => {
|
65
|
-
:l4_protocol => 'UDP',
|
66
|
-
:source_ports => [],
|
67
|
-
:destination_ports => [],
|
68
|
-
:resource_type => 'L4PortSetNSService'
|
69
|
-
}
|
70
|
-
}
|
71
|
-
],
|
72
|
-
'ICMP' => [
|
73
|
-
{
|
74
|
-
:service => {
|
75
|
-
:protocol => 'ICMPv4',
|
76
|
-
:resource_type => 'ICMPTypeNSService'
|
77
|
-
}
|
78
|
-
}
|
79
|
-
],
|
80
|
-
'ICMPv6' => [
|
81
|
-
{
|
82
|
-
:service => {
|
83
|
-
:protocol => 'ICMPv6',
|
84
|
-
:resource_type => 'ICMPTypeNSService'
|
85
|
-
}
|
86
|
-
}
|
87
|
-
],
|
88
|
-
'IPSEC' => [
|
89
|
-
{
|
90
|
-
:service => {
|
91
|
-
:l4_protocol => 'UDP',
|
92
|
-
:source_ports => [],
|
93
|
-
:destination_ports => [],
|
94
|
-
:resource_type => 'L4PortSetNSService'
|
95
|
-
}
|
96
|
-
},
|
97
|
-
{
|
98
|
-
:service => {
|
99
|
-
:protocol_number => 50,
|
100
|
-
:resource_type => 'IPProtocolNSService'
|
101
|
-
}
|
102
|
-
},
|
103
|
-
{
|
104
|
-
:service => {
|
105
|
-
:protocol_number => 51,
|
106
|
-
:resource_type => 'IPProtocolNSService'
|
107
|
-
}
|
108
|
-
}
|
109
|
-
]
|
110
|
-
}
|
111
|
-
|
112
|
-
# Modify default rule spec based on rule_data extracted
|
113
|
-
# from vm template
|
114
|
-
|
115
|
-
###### SOURCES / DESTINATIONS: Any | IP Address | Vnet #####
|
116
|
-
src_or_dst = []
|
117
|
-
|
118
|
-
# Target network: Vnet
|
119
|
-
if !rule[:network_id].empty?
|
120
|
-
|
121
|
-
src_or_dst << {
|
122
|
-
:target_id => rule[:network_nsxid],
|
123
|
-
:target_display_name => rule[:network_name],
|
124
|
-
:target_type => 'LogicalSwitch',
|
125
|
-
:is_valid => true
|
126
|
-
}
|
127
|
-
|
128
|
-
# Target network: Manual network (IP Address)
|
129
|
-
elsif !rule[:subnets].empty?
|
130
|
-
rule[:subnets].each do |subnet|
|
131
|
-
src_or_dst << {
|
132
|
-
:target_id => subnet,
|
133
|
-
:target_display_name => subnet,
|
134
|
-
:target_type => 'IPAddress',
|
135
|
-
:is_valid => true
|
136
|
-
}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# (OpenNebula) INBOUND => Destination (NSX)
|
141
|
-
# (OpenNebula) OUTBOUND => Source (NSX)
|
142
|
-
unless src_or_dst.empty?
|
143
|
-
rule_spec[:sources] = src_or_dst \
|
144
|
-
if rule[:direction] == 'IN'
|
145
|
-
rule_spec[:destinations] = src_or_dst \
|
146
|
-
if rule[:direction] == 'OUT'
|
147
|
-
end
|
148
|
-
|
149
|
-
##### SERVICES #####
|
150
|
-
services = []
|
151
|
-
service = rule_protocol_template[rule[:protocol]]
|
152
|
-
|
153
|
-
case rule[:protocol]
|
154
|
-
when 'TCP'
|
155
|
-
service[0][:service][:source_ports] = rule[:ports] \
|
156
|
-
if rule[:direction] == 'IN'
|
157
|
-
service[0][:service][:destination_ports] = rule[:ports] \
|
158
|
-
if rule[:direction] == 'OUT'
|
159
|
-
when 'UDP'
|
160
|
-
service[0][:service][:source_ports] = rule[:ports] \
|
161
|
-
if rule[:direction] == 'IN'
|
162
|
-
service[0][:service][:destination_ports] = rule[:ports] \
|
163
|
-
if rule[:direction] == 'OUT'
|
164
|
-
# when 'ICMP'
|
165
|
-
# when 'ICMPv6'
|
166
|
-
when 'IPSEC'
|
167
|
-
ipsec_ports = NSXConstants::NSX_RULE_IPSEC_PORTS
|
168
|
-
service[0][:service][:source_ports] = ipsec_ports \
|
169
|
-
if rule[:direction] == 'IN'
|
170
|
-
service[0][:service][:destination_ports] = ipsec_ports \
|
171
|
-
if rule[:direction] == 'OUT'
|
172
|
-
end
|
173
|
-
|
174
|
-
if rule[:protocol] != 'ALL' && !service.empty?
|
175
|
-
service.each do |s|
|
176
|
-
services << s
|
177
|
-
end
|
178
|
-
rule_spec[:services] = services
|
179
|
-
end
|
180
|
-
|
181
|
-
rule_spec
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
data/lib/nsxt_tz.rb
DELETED
@@ -1,38 +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 Transport Zone
|
19
|
-
class NSXTtz < TransportZone
|
20
|
-
|
21
|
-
# ATTRIBUTES
|
22
|
-
attr_reader :tz_id
|
23
|
-
|
24
|
-
# CONSTRUCTOR
|
25
|
-
def initialize(nsx_client)
|
26
|
-
super(nsx_client)
|
27
|
-
# Construct base URLs
|
28
|
-
@url_tzs_nsxt = NSXConstants::NSXT_TZS
|
29
|
-
end
|
30
|
-
|
31
|
-
# METHODS
|
32
|
-
def tzs
|
33
|
-
@nsx_client.get(@url_tzs_nsxt)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/lib/nsxv_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 NSXVClient
|
57
|
-
class NSXVClient < 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::NSXV
|
69
|
-
end
|
70
|
-
|
71
|
-
# Prepare headers
|
72
|
-
def add_headers(aditional_headers = [])
|
73
|
-
headers = NSXConstants::HEADER_XML.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
|
-
Nokogiri::XML 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.body
|
133
|
-
end
|
134
|
-
|
135
|
-
def put(url, data, aditional_headers = [], valid_codes = [])
|
136
|
-
if valid_codes.empty?
|
137
|
-
valid_codes = [NSXConstants::CODE_CREATED,
|
138
|
-
NSXConstants::CODE_OK]
|
139
|
-
end
|
140
|
-
uri = URI.parse(@nsxmgr + url)
|
141
|
-
headers = add_headers(aditional_headers)
|
142
|
-
request = Net::HTTP::Put.new(uri.request_uri, headers)
|
143
|
-
request.body = data
|
144
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
145
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
146
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
147
|
-
https.request(request)
|
148
|
-
end
|
149
|
-
response = check_response(response, valid_codes)
|
150
|
-
response.body
|
151
|
-
end
|
152
|
-
|
153
|
-
def delete(url, aditional_headers = [], valid_codes = [])
|
154
|
-
if valid_codes.empty?
|
155
|
-
valid_codes = [NSXConstants::CODE_OK,
|
156
|
-
NSXConstants::CODE_NO_CONTENT]
|
157
|
-
end
|
158
|
-
uri = URI.parse(@nsxmgr + url)
|
159
|
-
headers = add_headers(aditional_headers)
|
160
|
-
request = Net::HTTP::Delete.new(uri.request_uri, headers)
|
161
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
162
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
163
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
164
|
-
https.request(request)
|
165
|
-
end
|
166
|
-
check_response(response, valid_codes)
|
167
|
-
end
|
168
|
-
|
169
|
-
def get_token(url, aditional_headers = [], valid_codes = [])
|
170
|
-
if valid_codes.empty?
|
171
|
-
valid_codes = [NSXConstants::CODE_OK]
|
172
|
-
end
|
173
|
-
uri = URI.parse(@nsxmgr + url)
|
174
|
-
headers = add_headers(aditional_headers)
|
175
|
-
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
176
|
-
request.basic_auth(@nsx_user, @nsx_password)
|
177
|
-
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
178
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
179
|
-
https.request(request)
|
180
|
-
end
|
181
|
-
response = check_response(response, valid_codes)
|
182
|
-
response_xml = Nokogiri::XML response.body
|
183
|
-
token = response_xml.xpath('//authToken/value').text
|
184
|
-
{ 'token' => token }.to_json
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
data/lib/nsxv_dfw.rb
DELETED
@@ -1,202 +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 NSXVdfw < 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::NSXV_DFW_BASE
|
30
|
-
@url_sections = @base_url + \
|
31
|
-
NSXConstants::NSXV_DFW_SECTIONS
|
32
|
-
@one_section_id = init_section
|
33
|
-
end
|
34
|
-
|
35
|
-
# Sections
|
36
|
-
# Get all sections
|
37
|
-
# Creates OpenNebula section if not exists and returns
|
38
|
-
# its section_id. Returns its section_id if OpenNebula
|
39
|
-
# section already exists
|
40
|
-
def init_section
|
41
|
-
one_section = section_by_name(NSXConstants::ONE_SECTION_NAME)
|
42
|
-
one_section ||= create_section(NSXConstants::ONE_SECTION_NAME)
|
43
|
-
return one_section.xpath('@id').text if one_section
|
44
|
-
end
|
45
|
-
|
46
|
-
# Get all sections
|
47
|
-
# Params:
|
48
|
-
# - None
|
49
|
-
# Return:
|
50
|
-
# - nil | [Nokogiri::XML::NodeSet] sections
|
51
|
-
def sections
|
52
|
-
result = @nsx_client.get(@base_url)
|
53
|
-
xp = NSXConstants::NSXV_DFW_SECTION_XPATH
|
54
|
-
sections = result.xpath(xp)
|
55
|
-
return sections unless sections.empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
# Get section by id
|
59
|
-
# Params:
|
60
|
-
# - section_id: [String] ID of the section or @one_section_id
|
61
|
-
# Return:
|
62
|
-
# - nil | [Nokogiri::XML::NodeSet] section
|
63
|
-
def section_by_id(section_id = @one_section_id)
|
64
|
-
url = @url_sections + '/' + section_id
|
65
|
-
result = @nsx_client.get(url)
|
66
|
-
xp = NSXConstants::NSXV_DFW_SECTION_XPATH
|
67
|
-
section = result.xpath(xp)
|
68
|
-
return section unless section.empty?
|
69
|
-
end
|
70
|
-
|
71
|
-
# Get section etag needed to manage FW rules
|
72
|
-
# Params:
|
73
|
-
# - section_id: [String] ID of the section or @one_section_id
|
74
|
-
# Return:
|
75
|
-
# - nil | etag [String] ID of the etag header
|
76
|
-
def section_etag(section_id = @one_section_id)
|
77
|
-
url = @url_sections + '/' + section_id
|
78
|
-
response = @nsx_client.get_full_response(url)
|
79
|
-
etag = response['etag']
|
80
|
-
return etag.delete('\"') if etag
|
81
|
-
end
|
82
|
-
|
83
|
-
# Get section by name
|
84
|
-
# Params:
|
85
|
-
# - section_name: [String] Name of the section
|
86
|
-
# Return:
|
87
|
-
# - nil | [Nokogiri::XML::NodeSet] section
|
88
|
-
def section_by_name(section_name)
|
89
|
-
url = @url_sections + '?name=' + section_name
|
90
|
-
result = @nsx_client.get(url) rescue nil
|
91
|
-
return if result.nil?
|
92
|
-
|
93
|
-
xp = NSXConstants::NSXV_DFW_SECTION_XPATH
|
94
|
-
result.xpath(xp)
|
95
|
-
end
|
96
|
-
|
97
|
-
# Create new section
|
98
|
-
# Params:
|
99
|
-
# - section_name [String] Name of the section
|
100
|
-
# Return:
|
101
|
-
# - [Nokogiri::XML::NodeSet]
|
102
|
-
def create_section(section_name)
|
103
|
-
section_spec =
|
104
|
-
"<section name=\"#{section_name}\"\
|
105
|
-
stateless=\"false\" tcpStrict=\"true\" useSid=\"false\">\
|
106
|
-
</section>"
|
107
|
-
|
108
|
-
section = Nokogiri::XML @nsx_client
|
109
|
-
.post(@url_sections, section_spec)
|
110
|
-
section_id = section.xpath('//section/@id').text
|
111
|
-
result = section_by_id(section_id)
|
112
|
-
raise 'Section was not created in DFW' unless result
|
113
|
-
|
114
|
-
result
|
115
|
-
end
|
116
|
-
|
117
|
-
# Delete section
|
118
|
-
# Params:
|
119
|
-
# - section_id: [String] ID of the section or @one_section_id
|
120
|
-
def delete_section(section_id = @one_section_id)
|
121
|
-
url = @url_sections + '/' + section_id
|
122
|
-
@nsx_client.delete(url)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Rules
|
126
|
-
# Get all rules
|
127
|
-
# Params:
|
128
|
-
# - section_id: [String] ID of the section or @one_section_id
|
129
|
-
# Return:
|
130
|
-
# - [Nokogiri::XML::NodeSet]
|
131
|
-
def rules(section_id = @one_section_id)
|
132
|
-
url = @url_sections + '/' + section_id
|
133
|
-
rules = @nsx_client.get(url)
|
134
|
-
rules.xpath(NSXConstants::NSXV_DFW_RULE_XPATH)
|
135
|
-
end
|
136
|
-
|
137
|
-
# Get rule by id
|
138
|
-
# Return:
|
139
|
-
# - rule | nil
|
140
|
-
def rule_by_id(rule_id, section_id = @one_section_id)
|
141
|
-
url = @url_sections + '/' + section_id + '/rules/' + rule_id
|
142
|
-
valid_codes = [NSXConstants::CODE_CREATED,
|
143
|
-
NSXConstants::CODE_OK,
|
144
|
-
NSXConstants::CODE_BAD_REQUEST,
|
145
|
-
NSXConstants::CODE_NOT_FOUND]
|
146
|
-
additional_headers = []
|
147
|
-
result = @nsx_client.get(url, additional_headers, valid_codes)
|
148
|
-
result.xpath(NSXConstants::NSXV_DFW_RULE_XPATH)
|
149
|
-
end
|
150
|
-
|
151
|
-
# Get rules by name
|
152
|
-
# Return:
|
153
|
-
# - [Nokogiri::XML::NodeSet]
|
154
|
-
def rules_by_name(rule_name, section_id = @one_section_id)
|
155
|
-
rules = Nokogiri::XML::NodeSet.new(Nokogiri::XML::Document.new)
|
156
|
-
|
157
|
-
all_rules = rules(section_id)
|
158
|
-
return rules unless all_rules
|
159
|
-
|
160
|
-
all_rules.xpath("//rule[name=\"#{rule_name}\"]")
|
161
|
-
end
|
162
|
-
|
163
|
-
# Create new rule
|
164
|
-
def create_rule(rule_spec, section_id = @one_section_id)
|
165
|
-
# etag is needed to add a new header If-Match
|
166
|
-
etag = section_etag(section_id)
|
167
|
-
raise NSXError::ObjectNotFound('etag') \
|
168
|
-
unless etag
|
169
|
-
|
170
|
-
aditional_headers = [{ 'If-Match' => etag }]
|
171
|
-
url = @url_sections + '/' + section_id + '/rules'
|
172
|
-
@nsx_client.post(url, rule_spec, aditional_headers)
|
173
|
-
end
|
174
|
-
|
175
|
-
# Update rule
|
176
|
-
def update_rule(rule_id, rule_spec, section_id = @one_section_id)
|
177
|
-
url = @url_sections + '/' + section_id + '/rules/' + rule_id
|
178
|
-
rule = rule_by_id(rule_id)
|
179
|
-
raise "Rule id #{rule_id} not found" unless rule
|
180
|
-
|
181
|
-
# etag is needed to add a new header If-Match
|
182
|
-
etag = section_etag(section_id)
|
183
|
-
raise "Cannot get etag from section: #{section_id}" unless etag
|
184
|
-
|
185
|
-
aditional_headers = [{ 'If-Match' => etag }]
|
186
|
-
@nsx_client.put(url, rule_spec, aditional_headers)
|
187
|
-
end
|
188
|
-
|
189
|
-
# Delete rule
|
190
|
-
def delete_rule(rule_id, section_id = @one_section_id)
|
191
|
-
url = @url_sections + '/' + section_id + '/rules/' + rule_id
|
192
|
-
# etag is needed to add a new header If-Match
|
193
|
-
etag = section_etag(section_id)
|
194
|
-
raise "Cannot get etag from section: #{section_id}" unless etag
|
195
|
-
|
196
|
-
aditional_headers = [{ 'If-Match' => etag }]
|
197
|
-
@nsx_client.delete(url, aditional_headers)
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|