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/nsxt_client.rb
ADDED
@@ -0,0 +1,176 @@
|
|
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
|
+
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
|
+
if File.directory?(GEMS_LOCATION)
|
33
|
+
real_gems_path = File.realpath(GEMS_LOCATION)
|
34
|
+
if !defined?(Gem) || Gem.path != [real_gems_path]
|
35
|
+
$LOAD_PATH.reject! {|l| l =~ /vendor_ruby/ }
|
36
|
+
require 'rubygems'
|
37
|
+
Gem.use_paths(real_gems_path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
$LOAD_PATH << RUBY_LIB_LOCATION
|
42
|
+
|
43
|
+
# Class NSXTClient
|
44
|
+
class NSXTClient < NSXClient
|
45
|
+
|
46
|
+
# ATTIBUTES
|
47
|
+
attr_accessor :nsxmgr
|
48
|
+
attr_accessor :nsx_user
|
49
|
+
attr_accessor :nsx_password
|
50
|
+
attr_accessor :nsx_type
|
51
|
+
|
52
|
+
# CONSTRUCTORS
|
53
|
+
def initialize(nsxmgr, nsx_user, nsx_password)
|
54
|
+
super(nsxmgr, nsx_user, nsx_password)
|
55
|
+
@nsx_type = NSXConstants::NSXT
|
56
|
+
end
|
57
|
+
|
58
|
+
# Prepare headers
|
59
|
+
def add_headers(aditional_headers = [])
|
60
|
+
headers = NSXConstants::HEADER_JSON.clone
|
61
|
+
unless aditional_headers.empty?
|
62
|
+
aditional_headers.each do |header|
|
63
|
+
headers[header.keys[0]] = header.values[0]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
headers
|
67
|
+
end
|
68
|
+
|
69
|
+
# METHODS
|
70
|
+
def get(url, aditional_headers = [], valid_codes = [])
|
71
|
+
if valid_codes.empty?
|
72
|
+
valid_codes = [NSXConstants::CODE_OK,
|
73
|
+
NSXConstants::CODE_NO_CONTENT]
|
74
|
+
end
|
75
|
+
uri = URI.parse(@nsxmgr + url)
|
76
|
+
headers = add_headers(aditional_headers)
|
77
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
78
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
79
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
80
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
81
|
+
https.request(request)
|
82
|
+
end
|
83
|
+
response = check_response(response, valid_codes)
|
84
|
+
JSON.parse(response.body)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_full_response(url, aditional_headers = [], valid_codes = [])
|
88
|
+
if valid_codes.empty?
|
89
|
+
valid_codes = [NSXConstants::CODE_OK,
|
90
|
+
NSXConstants::CODE_NO_CONTENT]
|
91
|
+
end
|
92
|
+
uri = URI.parse(@nsxmgr + url)
|
93
|
+
headers = add_headers(aditional_headers)
|
94
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
95
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
96
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
97
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
98
|
+
https.request(request)
|
99
|
+
end
|
100
|
+
check_response(response, valid_codes)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Return: id of the created object
|
104
|
+
def post(url, data, aditional_headers = [], valid_codes = [])
|
105
|
+
if valid_codes.empty?
|
106
|
+
valid_codes = [NSXConstants::CODE_CREATED,
|
107
|
+
NSXConstants::CODE_OK]
|
108
|
+
end
|
109
|
+
uri = URI.parse(@nsxmgr + url)
|
110
|
+
headers = add_headers(aditional_headers)
|
111
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
112
|
+
request.body = data
|
113
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
114
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
115
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
116
|
+
https.request(request)
|
117
|
+
end
|
118
|
+
response = check_response(response, valid_codes)
|
119
|
+
response_json = JSON.parse(response.body)
|
120
|
+
response_json['id']
|
121
|
+
end
|
122
|
+
|
123
|
+
def put(url, data, aditional_headers = [], valid_codes = [])
|
124
|
+
if valid_codes.empty?
|
125
|
+
valid_codes = [NSXConstants::CODE_CREATED,
|
126
|
+
NSXConstants::CODE_OK]
|
127
|
+
end
|
128
|
+
uri = URI.parse(@nsxmgr + url)
|
129
|
+
headers = add_headers(aditional_headers)
|
130
|
+
request = Net::HTTP::Put.new(uri.request_uri, headers)
|
131
|
+
request.body = data
|
132
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
133
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
134
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
135
|
+
https.request(request)
|
136
|
+
end
|
137
|
+
response = check_response(response, valid_codes)
|
138
|
+
response_json = JSON.parse(response.body)
|
139
|
+
response_json['id']
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete(url, aditional_headers = [], valid_codes = [])
|
143
|
+
if valid_codes.empty?
|
144
|
+
valid_codes = [NSXConstants::CODE_OK,
|
145
|
+
NSXConstants::CODE_NO_CONTENT]
|
146
|
+
end
|
147
|
+
uri = URI.parse(@nsxmgr + url)
|
148
|
+
headers = add_headers(aditional_headers)
|
149
|
+
request = Net::HTTP::Delete.new(uri.request_uri, headers)
|
150
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
151
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
152
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
153
|
+
https.request(request)
|
154
|
+
end
|
155
|
+
check_response(response, valid_codes)
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_token(url, aditional_headers = [], valid_codes = [])
|
159
|
+
if valid_codes.empty?
|
160
|
+
valid_codes = [NSXConstants::CODE_OK]
|
161
|
+
end
|
162
|
+
uri = URI.parse(@nsxmgr + url)
|
163
|
+
headers = add_headers(aditional_headers)
|
164
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
165
|
+
request.basic_auth(@nsx_user, @nsx_password)
|
166
|
+
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
|
167
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
|
168
|
+
https.request(request)
|
169
|
+
end
|
170
|
+
response = check_response(response, valid_codes)
|
171
|
+
response.body
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
data/lib/nsxt_dfw.rb
ADDED
@@ -0,0 +1,196 @@
|
|
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
|
+
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
|
@@ -0,0 +1,94 @@
|
|
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
|
+
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
|
data/lib/nsxt_rule.rb
ADDED
@@ -0,0 +1,188 @@
|
|
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
|
+
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
ADDED
@@ -0,0 +1,38 @@
|
|
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
|
+
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
|