lorj_cloud 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.gitreview +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +43 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/data.yaml +0 -0
- data/lib/defaults.yaml +0 -0
- data/lib/lorj_cloud/version.rb +4 -0
- data/lib/lorj_cloud.rb +6 -0
- data/lib/process/cloud/process/common.rb +60 -0
- data/lib/process/cloud/process/connection.rb +92 -0
- data/lib/process/cloud/process/external_network.rb +90 -0
- data/lib/process/cloud/process/flavor.rb +97 -0
- data/lib/process/cloud/process/images.rb +99 -0
- data/lib/process/cloud/process/internet_network.rb +33 -0
- data/lib/process/cloud/process/internet_server.rb +29 -0
- data/lib/process/cloud/process/keypairs.rb +332 -0
- data/lib/process/cloud/process/network.rb +107 -0
- data/lib/process/cloud/process/public_ip.rb +106 -0
- data/lib/process/cloud/process/router.rb +267 -0
- data/lib/process/cloud/process/rules.rb +120 -0
- data/lib/process/cloud/process/security_groups.rb +120 -0
- data/lib/process/cloud/process/server.rb +127 -0
- data/lib/process/cloud/process/server_log.rb +34 -0
- data/lib/process/cloud/process/subnetwork.rb +96 -0
- data/lib/process/cloud_process.rb +30 -0
- data/lib/providers/hpcloud/compute.rb +105 -0
- data/lib/providers/hpcloud/hpcloud.rb +463 -0
- data/lib/providers/hpcloud/network.rb +115 -0
- data/lib/providers/hpcloud/security_groups.rb +68 -0
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +410 -0
- data/lib/providers/openstack/openstack_create.rb +206 -0
- data/lib/providers/openstack/openstack_delete.rb +28 -0
- data/lib/providers/openstack/openstack_get.rb +39 -0
- data/lib/providers/openstack/openstack_process.rb +26 -0
- data/lib/providers/openstack/openstack_query.rb +96 -0
- data/lib/providers/openstack/openstack_update.rb +35 -0
- data/lib/providers/templates/compute.rb +40 -0
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +32 -0
- data/lorj_cloud.gemspec +32 -0
- metadata +175 -0
@@ -0,0 +1,267 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
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
|
@@ -0,0 +1,120 @@
|
|
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
|
@@ -0,0 +1,127 @@
|
|
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
|
+
# Server management
|
23
|
+
# ---------------------------------------------------------------------------
|
24
|
+
class CloudProcess
|
25
|
+
# Process Handler functions
|
26
|
+
def forj_get_or_create_server(sCloudObj, hParams)
|
27
|
+
server_name = hParams[:server_name]
|
28
|
+
PrcLib.state("Searching for server '%s'", server_name)
|
29
|
+
servers = forj_query_server(sCloudObj, { :name => server_name }, hParams)
|
30
|
+
if servers.length > 0
|
31
|
+
# Get server details
|
32
|
+
forj_get_server(sCloudObj, servers[0][:attrs][:id], hParams)
|
33
|
+
else
|
34
|
+
create_server(sCloudObj, hParams)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def forj_delete_server(sCloudObj, hParams)
|
39
|
+
ssl_error_obj = SSLErrorMgt.new
|
40
|
+
begin
|
41
|
+
controller_delete(sCloudObj)
|
42
|
+
PrcLib.info('Server %s was destroyed ', hParams[:server][:name])
|
43
|
+
rescue => e
|
44
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def forj_query_server(sCloudObj, sQuery, _hParams)
|
49
|
+
ssl_error_obj = SSLErrorMgt.new
|
50
|
+
begin
|
51
|
+
controller_query(sCloudObj, sQuery)
|
52
|
+
rescue => e
|
53
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def forj_get_server(sCloudObj, sId, _hParams)
|
58
|
+
ssl_error_obj = SSLErrorMgt.new
|
59
|
+
begin
|
60
|
+
controller_get(sCloudObj, sId)
|
61
|
+
rescue => e
|
62
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# SERVER Object
|
68
|
+
# Identify the server to use/build on the network/...
|
69
|
+
class Lorj::BaseDefinition
|
70
|
+
define_obj(:server,
|
71
|
+
|
72
|
+
:create_e => :forj_get_or_create_server,
|
73
|
+
:query_e => :forj_query_server,
|
74
|
+
:get_e => :forj_get_server,
|
75
|
+
# :update_e => :forj_update_server,
|
76
|
+
:delete_e => :forj_delete_server
|
77
|
+
)
|
78
|
+
|
79
|
+
obj_needs :CloudObject, :compute_connection
|
80
|
+
obj_needs :CloudObject, :flavor, :for => [:create_e]
|
81
|
+
obj_needs :CloudObject, :network, :for => [:create_e]
|
82
|
+
obj_needs :CloudObject, :security_groups, :for => [:create_e]
|
83
|
+
obj_needs :CloudObject, :keypairs, :for => [:create_e]
|
84
|
+
obj_needs :CloudObject, :image, :for => [:create_e]
|
85
|
+
obj_needs :data, :server_name, :for => [:create_e]
|
86
|
+
|
87
|
+
obj_needs_optional
|
88
|
+
obj_needs :data, :user_data, :for => [:create_e]
|
89
|
+
obj_needs :data, :meta_data, :for => [:create_e]
|
90
|
+
|
91
|
+
def_attribute :status
|
92
|
+
predefine_data_value :create, :desc => 'Server is creating.'
|
93
|
+
predefine_data_value :boot, :desc => 'Server is booting.'
|
94
|
+
predefine_data_value :active, :desc => 'Server is started.'
|
95
|
+
predefine_data_value :error, :desc => 'Server is in error.'
|
96
|
+
def_attribute :private_ip_address
|
97
|
+
def_attribute :public_ip_address
|
98
|
+
|
99
|
+
def_attribute :image_id
|
100
|
+
def_attribute :key_name
|
101
|
+
end
|
102
|
+
|
103
|
+
# Internal Process function
|
104
|
+
class CloudProcess
|
105
|
+
def create_server(sCloudObj, hParams)
|
106
|
+
name = hParams[:server_name]
|
107
|
+
begin
|
108
|
+
PrcLib.info('boot: meta-data provided.') if hParams[:meta_data]
|
109
|
+
PrcLib.info('boot: user-data provided.') if hParams[:user_data]
|
110
|
+
PrcLib.state('creating server %s', name)
|
111
|
+
server = controller_create(sCloudObj)
|
112
|
+
PrcLib.info("%s '%s' created.", sCloudObj, name)
|
113
|
+
rescue => e
|
114
|
+
PrcLib.fatal(1, "Unable to create server '%s'", name, e)
|
115
|
+
end
|
116
|
+
server
|
117
|
+
end
|
118
|
+
|
119
|
+
def forj_get_server_log(sCloudObj, sId, _hParams)
|
120
|
+
ssl_error_obj = SSLErrorMgt.new
|
121
|
+
begin
|
122
|
+
controller_get(sCloudObj, sId)
|
123
|
+
rescue => e
|
124
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
# SERVER Console Object
|
22
|
+
# Object representing the console log attached to a server
|
23
|
+
class Lorj::BaseDefinition
|
24
|
+
define_obj(:server_log,
|
25
|
+
|
26
|
+
:get_e => :forj_get_server_log
|
27
|
+
)
|
28
|
+
|
29
|
+
obj_needs :CloudObject, :server
|
30
|
+
obj_needs :data, :log_lines
|
31
|
+
undefine_attribute :name
|
32
|
+
undefine_attribute :id
|
33
|
+
def_attribute :output
|
34
|
+
end
|