lorj 1.0.9 → 1.0.10
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/.rspec +2 -0
- data/example/students_1/process/students.rb +1 -1
- data/example/students_1/student_v1.md +2 -0
- data/example/students_1/students.rb +2 -1
- data/example/students_2/process/students.rb +1 -1
- data/example/students_2/students.rb +4 -2
- data/example/students_3/controller/yaml_students_def.rb +1 -1
- data/example/students_3/process/students.rb +1 -1
- data/example/students_3/student_v3.md +5 -3
- data/example/students_3/students.rb +5 -3
- data/example/students_4/controller/yaml_students_def.rb +1 -1
- data/example/students_4/process/students/definition/students.rb +1 -1
- data/example/students_4/students.rb +5 -3
- data/example/students_5/controller/yaml_students.rb +1 -1
- data/example/students_5/process/students.rb +1 -1
- data/example/students_5/student_v5.md +4 -4
- data/example/students_5/students.rb +8 -7
- data/example/yaml_students/students.rb +4 -4
- data/lib/core/core.rb +110 -64
- data/lib/core/core_internal.rb +110 -15
- data/lib/core/core_object_data.rb +4 -4
- data/lib/core/core_process_setup.rb +3 -30
- data/lib/core/lorj_data.rb +1 -1
- data/lib/core/lorj_keypath.rb +3 -1
- data/lib/core/process.rb +67 -0
- data/lib/lorj/version.rb +2 -1
- data/lib/lorj.rb +3 -4
- data/lib/lorj_account.rb +6 -5
- data/lib/lorj_config.rb +3 -2
- data/lib/providers/templates/compute.rb +1 -1
- data/lorj-spec/controllers/mock/mock.rb +144 -0
- data/lorj-spec/data.yaml +0 -0
- data/lorj-spec/process/mock2_process.rb +48 -0
- data/lorj-spec/process/mock_process.rb +48 -0
- data/lorj-spec/providers/mock2/mock2.rb +0 -0
- data/lorj.gemspec +2 -4
- data/spec/05_lorj_keypath_spec.rb +78 -0
- data/spec/20_lorj_meta_spec.rb +1 -1
- data/spec/21_lorj_processes_spec.rb +115 -0
- metadata +27 -42
- data/lib/core_process/cloud/process/common.rb +0 -60
- data/lib/core_process/cloud/process/connection.rb +0 -92
- data/lib/core_process/cloud/process/external_network.rb +0 -90
- data/lib/core_process/cloud/process/flavor.rb +0 -97
- data/lib/core_process/cloud/process/images.rb +0 -99
- data/lib/core_process/cloud/process/internet_network.rb +0 -33
- data/lib/core_process/cloud/process/internet_server.rb +0 -29
- data/lib/core_process/cloud/process/keypairs.rb +0 -332
- data/lib/core_process/cloud/process/network.rb +0 -107
- data/lib/core_process/cloud/process/public_ip.rb +0 -102
- data/lib/core_process/cloud/process/router.rb +0 -267
- data/lib/core_process/cloud/process/rules.rb +0 -120
- data/lib/core_process/cloud/process/security_groups.rb +0 -120
- data/lib/core_process/cloud/process/server.rb +0 -126
- data/lib/core_process/cloud/process/server_log.rb +0 -34
- data/lib/core_process/cloud/process/subnetwork.rb +0 -96
- data/lib/core_process/cloud_process.rb +0 -30
- data/lib/prc_base_config.rb +0 -300
- data/lib/prc_core_config.rb +0 -1258
- data/lib/prc_section_config.rb +0 -90
- data/lib/providers/hpcloud/compute.rb +0 -105
- data/lib/providers/hpcloud/hpcloud.rb +0 -462
- data/lib/providers/hpcloud/network.rb +0 -115
- data/lib/providers/hpcloud/security_groups.rb +0 -68
- data/lib/providers/openstack/openstack.rb +0 -410
- data/lib/providers/openstack/openstack_create.rb +0 -205
- data/lib/providers/openstack/openstack_delete.rb +0 -28
- data/lib/providers/openstack/openstack_get.rb +0 -39
- data/lib/providers/openstack/openstack_process.rb +0 -26
- data/lib/providers/openstack/openstack_query.rb +0 -96
- data/lib/providers/openstack/openstack_update.rb +0 -35
- data/lib/rh.rb +0 -426
- data/spec/01_hash_rh_spec.rb +0 -282
- data/spec/02_prc_base_config_spec.rb +0 -227
- data/spec/03_prc_section_config_spec.rb +0 -196
- data/spec/04_prc_core_config_spec.rb +0 -325
@@ -1,102 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
-
|
19
|
-
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
-
|
21
|
-
# Addresses management
|
22
|
-
class CloudProcess
|
23
|
-
# Process Handler functions
|
24
|
-
def forj_get_or_assign_public_address(sCloudObj, hParams)
|
25
|
-
# Function which to assign a public IP address to a server.
|
26
|
-
server_name = hParams[:server, :name]
|
27
|
-
|
28
|
-
PrcLib.state("Searching public IP for server '%s'", server_name)
|
29
|
-
addresses = controller_query(sCloudObj, :server_id => hParams[:server, :id])
|
30
|
-
if addresses.length == 0
|
31
|
-
assign_address(sCloudObj, hParams)
|
32
|
-
else
|
33
|
-
addresses[0]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Function to query the list of addresses for one server
|
38
|
-
def forj_query_public_address(sCloudObj, sQuery, hParams)
|
39
|
-
server_name = hParams[:server, :name]
|
40
|
-
ssl_error_obj = SSLErrorMgt.new
|
41
|
-
begin
|
42
|
-
info = {
|
43
|
-
:notfound => "No %s for '%s' found",
|
44
|
-
:checkmatch => "Found 1 %s. checking exact match for server '%s'.",
|
45
|
-
:nomatch => "No %s for '%s' match",
|
46
|
-
:found => "Found %s '%s' for #{server_name}.",
|
47
|
-
:more => "Found several %s. Searching for '%s'.",
|
48
|
-
:items => :public_ip
|
49
|
-
}
|
50
|
-
# list = controller_query(sCloudObj, sQuery)
|
51
|
-
# query_single(sCloudObj, list, sQuery, server_name, info)
|
52
|
-
query_single(sCloudObj, sQuery, server_name, info)
|
53
|
-
rescue => e
|
54
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Function to get the IP address
|
59
|
-
def forj_get_public_address(sCloudObj, sId, _hParams)
|
60
|
-
ssl_error_obj = SSLErrorMgt.new
|
61
|
-
begin
|
62
|
-
controller_get(sCloudObj, sId)
|
63
|
-
rescue => e
|
64
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# SERVER Addresses Object
|
70
|
-
# Object representing the list of IP addresses attached to a server.
|
71
|
-
class Lorj::BaseDefinition
|
72
|
-
define_obj(:public_ip,
|
73
|
-
:create_e => :forj_get_or_assign_public_address,
|
74
|
-
:query_e => :forj_query_public_address
|
75
|
-
# :get_e => :forj_get_address
|
76
|
-
# :update_e => :forj_update_address
|
77
|
-
# :delete_e => :forj_delete_address
|
78
|
-
)
|
79
|
-
|
80
|
-
obj_needs :CloudObject, :compute_connection
|
81
|
-
obj_needs :CloudObject, :server
|
82
|
-
|
83
|
-
def_attribute :server_id
|
84
|
-
def_attribute :public_ip
|
85
|
-
undefine_attribute :name # No name to extract
|
86
|
-
end
|
87
|
-
|
88
|
-
# Internal Process function
|
89
|
-
class CloudProcess
|
90
|
-
def assign_address(sCloudObj, hParams)
|
91
|
-
name = hParams[:server, :name]
|
92
|
-
begin
|
93
|
-
PrcLib.state('Getting public IP for server %s', name)
|
94
|
-
ip_address = controller_create(sCloudObj)
|
95
|
-
PrcLib.info("Public IP '%s' for server '%s' "\
|
96
|
-
'assigned.', ip_address[:public_ip], name)
|
97
|
-
rescue => e
|
98
|
-
PrcLib.fatal(1, "Unable to assign a public IP to server '%s'", name, e)
|
99
|
-
end
|
100
|
-
ip_address
|
101
|
-
end
|
102
|
-
end
|
@@ -1,267 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
-
|
19
|
-
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
-
|
21
|
-
# ---------------------------------------------------------------------------
|
22
|
-
# Router management
|
23
|
-
# ---------------------------------------------------------------------------
|
24
|
-
class CloudProcess
|
25
|
-
# Process Create handler
|
26
|
-
def forj_get_or_create_router(_sCloudObj, hParams)
|
27
|
-
sub_net_obj = hParams[:subnetwork]
|
28
|
-
|
29
|
-
if hParams[:router_name].nil?
|
30
|
-
router_name = format('router-%s', hParams[:network, :name])
|
31
|
-
else
|
32
|
-
router_name = hParams[:router_name]
|
33
|
-
end
|
34
|
-
|
35
|
-
_get_router(router_name, sub_net_obj, hParams)
|
36
|
-
end
|
37
|
-
|
38
|
-
def _get_router(router_name, sub_net_obj, hParams)
|
39
|
-
router_port = get_router_interface_attached(:port, hParams)
|
40
|
-
|
41
|
-
if router_port.nil? || router_port.length == 0
|
42
|
-
# Trying to get router
|
43
|
-
router = get_router(router_name)
|
44
|
-
router = create_router(router_name) if router.empty?
|
45
|
-
create_router_interface(sub_net_obj, router) if router
|
46
|
-
else
|
47
|
-
router = query_router_from_port(router_port[0], hParams)
|
48
|
-
end
|
49
|
-
router
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Router Object
|
54
|
-
# Identify the router of a network.
|
55
|
-
class Lorj::BaseDefinition
|
56
|
-
define_obj(:router,
|
57
|
-
|
58
|
-
:create_e => :forj_get_or_create_router,
|
59
|
-
# :query_e => :forj_query_router,
|
60
|
-
# :get_e => :forj_get_router,
|
61
|
-
:update_e => :controller_update
|
62
|
-
# :delete_e => :forj_delete_router
|
63
|
-
)
|
64
|
-
obj_needs :CloudObject, :network_connection
|
65
|
-
obj_needs :CloudObject, :network, :for => [:create_e]
|
66
|
-
obj_needs :CloudObject, :subnetwork, :for => [:create_e]
|
67
|
-
obj_needs_optional
|
68
|
-
obj_needs :data, :router_name, :for => [:create_e]
|
69
|
-
|
70
|
-
def_attribute :gateway_network_id
|
71
|
-
end
|
72
|
-
|
73
|
-
# Port Object
|
74
|
-
# Identify port attached to network
|
75
|
-
class Lorj::BaseDefinition
|
76
|
-
define_obj :port, :nohandler => true
|
77
|
-
|
78
|
-
obj_needs :CloudObject, :network_connection
|
79
|
-
def_attribute :device_id
|
80
|
-
|
81
|
-
def_attribute :network_id
|
82
|
-
def_attribute :device_owner
|
83
|
-
end
|
84
|
-
|
85
|
-
# Router interface Object
|
86
|
-
# Identify interface attached to a router
|
87
|
-
# This object will probably be moved to controller task
|
88
|
-
# To keep the network model more generic.
|
89
|
-
class Lorj::BaseDefinition
|
90
|
-
# No process handler defined. Just Controller object
|
91
|
-
define_obj :router_interface, :nohandler => true
|
92
|
-
|
93
|
-
obj_needs :CloudObject, :network_connection
|
94
|
-
obj_needs :CloudObject, :router, :for => [:create_e]
|
95
|
-
obj_needs :CloudObject, :subnetwork, :for => [:create_e]
|
96
|
-
|
97
|
-
undefine_attribute :name
|
98
|
-
undefine_attribute :id
|
99
|
-
end
|
100
|
-
|
101
|
-
# Router Process internal functions
|
102
|
-
class CloudProcess
|
103
|
-
def get_router(name)
|
104
|
-
PrcLib.state("Searching for router '%s'", name)
|
105
|
-
begin
|
106
|
-
query = { :name => name }
|
107
|
-
routers = query_single(:router, query, name)
|
108
|
-
return Lorj::Data.new if routers.length == 0
|
109
|
-
register(routers[0])
|
110
|
-
rescue => e
|
111
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def create_router(router_name, oExternalNetwork = nil)
|
116
|
-
begin
|
117
|
-
if oExternalNetwork
|
118
|
-
ext_net = get_data(oExternalNetwork, :name)
|
119
|
-
PrcLib.state("Creating router '%s' attached to the external "\
|
120
|
-
"Network '%s'", router_name, ext_net)
|
121
|
-
config[:external_gateway_id] = get_data(oExternalNetwork, :id)
|
122
|
-
else
|
123
|
-
PrcLib.state("Creating router '%s' without external Network",
|
124
|
-
router_name)
|
125
|
-
end
|
126
|
-
|
127
|
-
router = controller_create(:router, :router_name => router_name)
|
128
|
-
if oExternalNetwork
|
129
|
-
PrcLib.info("Router '%s' created and attached to the external "\
|
130
|
-
"Network '%s'.", router_name, ext_net)
|
131
|
-
else
|
132
|
-
PrcLib.info("Router '%s' created without external Network.",
|
133
|
-
router_name)
|
134
|
-
end
|
135
|
-
rescue => e
|
136
|
-
PrcLib.error "Unable to create '%s' router\n%s\n%s", router_name,
|
137
|
-
e.message, e.backtrace.join("\n")
|
138
|
-
end
|
139
|
-
router
|
140
|
-
end
|
141
|
-
|
142
|
-
def delete_router(net_conn_obj, router_obj)
|
143
|
-
PrcLib.state("Deleting router '%s'", router.name)
|
144
|
-
begin
|
145
|
-
#################
|
146
|
-
provider_delete_router(net_conn_obj, router_obj)
|
147
|
-
# net_conn_obj.routers.get(router.id).destroy
|
148
|
-
rescue => e
|
149
|
-
PrcLib.error("Unable to delete '%s' router ID", router_id, e)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def query_router_from_port(router_port, _hParams)
|
154
|
-
query = { :id => router_port[:device_id] }
|
155
|
-
info = {
|
156
|
-
:notfound => 'No %s for port ID %s found',
|
157
|
-
:checkmatch => 'Found 1 %s. Checking exact match for port ID %s.',
|
158
|
-
:nomatch => 'No %s for port ID %s match',
|
159
|
-
:found => "Found %s '%s' from port ID #{router_port[:device_id]}.",
|
160
|
-
:more => 'Found several %s. Searching for port ID %s.'
|
161
|
-
}
|
162
|
-
routers = query_single(:router, query, router_port[:device_id], info)
|
163
|
-
return Lorj::Data.new if routers.length == 0
|
164
|
-
register(routers[0])
|
165
|
-
end
|
166
|
-
|
167
|
-
# TODO: Move router interface management to hpcloud controller.
|
168
|
-
# Router interface to connect to the network
|
169
|
-
def create_router_interface(oSubnet, router_obj)
|
170
|
-
PrcLib.state("Attaching subnet '%s' to router '%s'",
|
171
|
-
oSubnet[:name], router_obj[:name])
|
172
|
-
begin
|
173
|
-
controller_create(:router_interface)
|
174
|
-
|
175
|
-
#################
|
176
|
-
# provider_add_interface()
|
177
|
-
# router_obj.add_interface(oSubnet.id, nil)
|
178
|
-
rescue => e
|
179
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def delete_router_interface(oSubnet, router_obj)
|
184
|
-
PrcLib.state("Removing subnet '%s' from router '%s'",
|
185
|
-
oSubnet.name, router_obj.name)
|
186
|
-
subnet_id = oSubnet.id
|
187
|
-
begin
|
188
|
-
#################
|
189
|
-
router_obj.remove_interface(subnet_id)
|
190
|
-
rescue => e
|
191
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# Function to get the router ID in the network
|
196
|
-
# from the list of routers found.
|
197
|
-
# Query ports devices.
|
198
|
-
def get_router_interface_attached(sCloudObj, hParams)
|
199
|
-
name = hParams[:network, :name]
|
200
|
-
PrcLib.state("Searching for router port attached to the network '%s'", name)
|
201
|
-
routers = controller_query(:router, {})
|
202
|
-
routers.each do |router|
|
203
|
-
begin
|
204
|
-
router_name = router[:name]
|
205
|
-
# Searching for router port attached
|
206
|
-
#################
|
207
|
-
query = { :network_id => hParams[:network, :id],
|
208
|
-
:device_id => router[:id] }
|
209
|
-
info = {
|
210
|
-
:notfound => "Network '#{name}' not attached to router "\
|
211
|
-
"'#{router_name}'",
|
212
|
-
:checkmatch => 'Found 1 router %s. '\
|
213
|
-
"Checking exact match for network '%s'.",
|
214
|
-
:nomatch => "No router %s for network '%s' match",
|
215
|
-
:found => "Found router %s ID (#{router_name}) %s attached to "\
|
216
|
-
"network '#{name}'.",
|
217
|
-
:more => "Found several router %s. Searching for network '%s'.",
|
218
|
-
:items => [:id]
|
219
|
-
}
|
220
|
-
interfaces = query_single(sCloudObj, query, name, info)
|
221
|
-
return interfaces unless interfaces.length == 0
|
222
|
-
rescue => e
|
223
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
# Gateway management
|
229
|
-
def get_gateway(net_conn_obj, name)
|
230
|
-
return nil if !name || !net_conn_obj
|
231
|
-
|
232
|
-
PrcLib.state("Getting gateway '%s'", name)
|
233
|
-
networks = net_conn_obj
|
234
|
-
begin
|
235
|
-
netty = networks.get(name)
|
236
|
-
rescue => e
|
237
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
238
|
-
end
|
239
|
-
PrcLib.state("Found gateway '%s'", name) if netty
|
240
|
-
PrcLib.state("Unable to find gateway '%s'", name) unless netty
|
241
|
-
netty
|
242
|
-
end
|
243
|
-
|
244
|
-
def query_external_network(_hParams)
|
245
|
-
PrcLib.state('Identifying External gateway')
|
246
|
-
begin
|
247
|
-
# Searching for router port attached
|
248
|
-
#################
|
249
|
-
query = { :router_external => true }
|
250
|
-
networks = controller_query(:network, query)
|
251
|
-
case networks.length
|
252
|
-
when 0
|
253
|
-
PrcLib.info('No external network')
|
254
|
-
Lorj::Data.new
|
255
|
-
when 1
|
256
|
-
PrcLib.info("Found external network '%s'.", networks[0, :name])
|
257
|
-
networks[0]
|
258
|
-
else
|
259
|
-
PrcLib.warn('Found several external networks. Selecting the '\
|
260
|
-
"first one '%s'", networks[0, :name])
|
261
|
-
networks[0]
|
262
|
-
end
|
263
|
-
rescue => e
|
264
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
-
|
19
|
-
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
-
|
21
|
-
# SecurityGroups rules management
|
22
|
-
class CloudProcess
|
23
|
-
# Process Delete handler
|
24
|
-
def forj_delete_rule(sCloudObj, _hParams)
|
25
|
-
ssl_error_obj = SSLErrorMgt.new
|
26
|
-
begin
|
27
|
-
controller_delete(sCloudObj)
|
28
|
-
rescue => e
|
29
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Process Query handler
|
34
|
-
def forj_query_rule(sCloudObj, sQuery, hParams)
|
35
|
-
rule = format('%s %s:%s - %s to %s', hParams[:dir], hParams[:rule_proto],
|
36
|
-
hParams[:port_min], hParams[:port_max],
|
37
|
-
hParams[:addr_map])
|
38
|
-
PrcLib.state("Searching for rule '%s'", rule)
|
39
|
-
ssl_error_obj = SSLErrorMgt.new
|
40
|
-
begin
|
41
|
-
info = {
|
42
|
-
:items => [:dir, :proto, :port_min, :port_max, :addr_map],
|
43
|
-
:items_form => '%s %s:%s - %s to %s'
|
44
|
-
}
|
45
|
-
# list = controller_query(sCloudObj, sQuery)
|
46
|
-
# query_single(sCloudObj, list, sQuery, rule, info)
|
47
|
-
query_single(sCloudObj, sQuery, rule, info)
|
48
|
-
rescue => e
|
49
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Process Create handler
|
54
|
-
def forj_get_or_create_rule(sCloudObj, hParams)
|
55
|
-
query = {
|
56
|
-
:dir => hParams[:dir],
|
57
|
-
:proto => hParams[:proto],
|
58
|
-
:port_min => hParams[:port_min],
|
59
|
-
:port_max => hParams[:port_max],
|
60
|
-
:addr_map => hParams[:addr_map],
|
61
|
-
:sg_id => hParams[:sg_id]
|
62
|
-
}
|
63
|
-
rules = forj_query_rule(sCloudObj, query, hParams)
|
64
|
-
if rules.length == 0
|
65
|
-
create_rule(sCloudObj, hParams)
|
66
|
-
else
|
67
|
-
rules[0]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Security group rules Object
|
73
|
-
# Identify Rules attached to the security group
|
74
|
-
class Lorj::BaseDefinition
|
75
|
-
define_obj(:rule,
|
76
|
-
|
77
|
-
:create_e => :forj_get_or_create_rule,
|
78
|
-
:query_e => :forj_query_rule
|
79
|
-
# :delete_e => :forj_delete_rule
|
80
|
-
)
|
81
|
-
|
82
|
-
undefine_attribute :name # Do not return any predefined name attribute
|
83
|
-
|
84
|
-
obj_needs :CloudObject, :network_connection
|
85
|
-
obj_needs :CloudObject, :security_groups, :for => [:create_e]
|
86
|
-
obj_needs :data, :sg_id, :for => [:create_e],
|
87
|
-
:extract_from => [:security_groups,
|
88
|
-
:attrs, :id]
|
89
|
-
|
90
|
-
obj_needs :data, :dir, :for => [:create_e]
|
91
|
-
predefine_data_value :IN, :desc => 'Input NAT/firewall rule map type'
|
92
|
-
predefine_data_value :OUT, :desc => 'Output NAT/firewall rule map type'
|
93
|
-
|
94
|
-
obj_needs :data, :proto, :for => [:create_e]
|
95
|
-
obj_needs :data, :port_min, :for => [:create_e]
|
96
|
-
obj_needs :data, :port_max, :for => [:create_e]
|
97
|
-
obj_needs :data, :addr_map, :for => [:create_e]
|
98
|
-
end
|
99
|
-
|
100
|
-
# SecurityGroups rules management
|
101
|
-
class CloudProcess
|
102
|
-
# Rules internal #
|
103
|
-
#----------------#
|
104
|
-
def create_rule(sCloudObj, hParams)
|
105
|
-
rule_msg = format('%s %s:%s - %s to %s',
|
106
|
-
hParams[:dir], hParams[:rule_proto],
|
107
|
-
hParams[:port_min], hParams[:port_max],
|
108
|
-
hParams[:addr_map])
|
109
|
-
PrcLib.state("Creating rule '%s'", rule_msg)
|
110
|
-
ssl_error_obj = SSLErrorMgt.new
|
111
|
-
begin
|
112
|
-
rule = controller_create(sCloudObj)
|
113
|
-
PrcLib.info("Rule '%s' created.", rule_msg)
|
114
|
-
rescue StandardError => e
|
115
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
116
|
-
PrcLib.error 'error creating the rule "%s"', rule_msg
|
117
|
-
end
|
118
|
-
rule
|
119
|
-
end
|
120
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
-
|
19
|
-
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
-
|
21
|
-
# SecurityGroups management
|
22
|
-
class CloudProcess
|
23
|
-
# Process Create handler
|
24
|
-
def forj_get_or_create_sg(sCloudObj, hParams)
|
25
|
-
sg_name = hParams[:security_group]
|
26
|
-
PrcLib.state("Searching for security group '%s'", sg_name)
|
27
|
-
|
28
|
-
security_group = forj_query_sg(sCloudObj, { :name => sg_name }, hParams)
|
29
|
-
security_group = create_security_group(sCloudObj,
|
30
|
-
hParams) unless security_group
|
31
|
-
register(security_group)
|
32
|
-
|
33
|
-
PrcLib.info('Configuring Security Group \'%s\'', sg_name)
|
34
|
-
ports = config.get(:ports)
|
35
|
-
|
36
|
-
ports.each do |port|
|
37
|
-
port = port.to_s if port.class != String
|
38
|
-
if !(/^\d+(-\d+)?$/ =~ port)
|
39
|
-
PrcLib.error("Port '%s' is not valid. Must be <Port> or "\
|
40
|
-
'<PortMin>-<PortMax>', port)
|
41
|
-
else
|
42
|
-
port_found_match = /^(\d+)(-(\d+))?$/.match(port)
|
43
|
-
portmin = port_found_match[1]
|
44
|
-
portmax = (port_found_match[3]) ? (port_found_match[3]) : (portmin)
|
45
|
-
# Need to set runtime data to get or if missing
|
46
|
-
# create the required rule.
|
47
|
-
params = {}
|
48
|
-
params[:dir] = :IN
|
49
|
-
params[:proto] = 'tcp'
|
50
|
-
params[:port_min] = portmin.to_i
|
51
|
-
params[:port_max] = portmax.to_i
|
52
|
-
params[:addr_map] = '0.0.0.0/0'
|
53
|
-
|
54
|
-
# object.Create(:rule)
|
55
|
-
process_create(:rule, params)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
security_group
|
59
|
-
end
|
60
|
-
|
61
|
-
# Process Delete handler
|
62
|
-
def forj_delete_sg(sCloudObj, _hParams)
|
63
|
-
ssl_error_obj = SSLErrorMgt.new
|
64
|
-
begin
|
65
|
-
controller_delete(sCloudObj)
|
66
|
-
rescue => e
|
67
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Process Query handler
|
72
|
-
def forj_query_sg(sCloudObj, sQuery, hParams)
|
73
|
-
ssl_error_obj = SSLErrorMgt.new
|
74
|
-
|
75
|
-
begin
|
76
|
-
sgroups = controller_query(sCloudObj, sQuery)
|
77
|
-
rescue => e
|
78
|
-
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
79
|
-
PrcLib.fatal(1, 'Unable to get list of security groups.', e)
|
80
|
-
end
|
81
|
-
case sgroups.length
|
82
|
-
when 0
|
83
|
-
PrcLib.info("No security group '%s' found",
|
84
|
-
hParams[:security_group])
|
85
|
-
nil
|
86
|
-
when 1
|
87
|
-
PrcLib.info("Found security group '%s'", sgroups[0, :name])
|
88
|
-
sgroups[0]
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# ************************************ Security groups Object
|
94
|
-
# Identify security_groups
|
95
|
-
class Lorj::BaseDefinition
|
96
|
-
define_obj(:security_groups,
|
97
|
-
:create_e => :forj_get_or_create_sg,
|
98
|
-
:query_e => :forj_query_sg,
|
99
|
-
:delete_e => :forj_delete_sg
|
100
|
-
)
|
101
|
-
|
102
|
-
obj_needs :CloudObject, :network_connection
|
103
|
-
obj_needs :data, :security_group, :for => [:create_e]
|
104
|
-
obj_needs_optional
|
105
|
-
obj_needs :data, :sg_desc, :for => [:create_e]
|
106
|
-
end
|
107
|
-
|
108
|
-
# SecurityGroups Process internal functions #
|
109
|
-
class CloudProcess
|
110
|
-
def create_security_group(sCloudObj, hParams)
|
111
|
-
PrcLib.state("Creating security group '%s'", hParams[:security_group])
|
112
|
-
begin
|
113
|
-
sg = controller_create(sCloudObj)
|
114
|
-
PrcLib.info("Security group '%s' created.", sg[:name])
|
115
|
-
rescue => e
|
116
|
-
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
117
|
-
end
|
118
|
-
sg
|
119
|
-
end
|
120
|
-
end
|