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,29 @@
|
|
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
|
+
# Internet SERVER Object
|
22
|
+
# internet server is a server connected to the internet network.
|
23
|
+
class Lorj::BaseDefinition
|
24
|
+
define_obj(:internet_server, :nohandler => true)
|
25
|
+
|
26
|
+
obj_needs :CloudObject, :internet_network
|
27
|
+
obj_needs :CloudObject, :server
|
28
|
+
obj_needs :CloudObject, :public_ip
|
29
|
+
end
|
@@ -0,0 +1,332 @@
|
|
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
|
+
# Keypair management
|
22
|
+
class CloudProcess
|
23
|
+
# KeyPair Create Process Handler
|
24
|
+
# The process implemented is:
|
25
|
+
# * Check local SSH keypairs with given ':keypair_name'
|
26
|
+
# * Check remote keypair existence
|
27
|
+
# * Compare and warn if needed.
|
28
|
+
# * Import public key found if missing remotely and name it.
|
29
|
+
#
|
30
|
+
# Return:
|
31
|
+
# - keypair : Lorj::Data keypair object. Following additional data should be
|
32
|
+
# found in the keypair attributes
|
33
|
+
# - :coherent : Boolean. True, if the local keypair (public AND
|
34
|
+
# private) is coherent with remote keypair found in
|
35
|
+
# the cloud
|
36
|
+
# - :private_key_file: String. Path to local private key file
|
37
|
+
# - :public_key_file : String. Path to local public key file
|
38
|
+
# - :public_key : String. Public key content. (config[:public_key] is
|
39
|
+
# also set - Used to import it)
|
40
|
+
#
|
41
|
+
def forj_get_or_create_keypair(sCloudObj, hParams)
|
42
|
+
keypair_name = hParams[:keypair_name]
|
43
|
+
PrcLib.state("Searching for keypair '%s'", keypair_name)
|
44
|
+
|
45
|
+
keypair = forj_get_keypair(sCloudObj, keypair_name, hParams)
|
46
|
+
if keypair.empty?
|
47
|
+
loc_kpair = keypair_detect(keypair_name, hParams[:keypair_path],
|
48
|
+
hParams[:keypair_base])
|
49
|
+
keypair = keypair_import(hParams, loc_kpair)
|
50
|
+
else
|
51
|
+
keypair_display(keypair)
|
52
|
+
end
|
53
|
+
keypair
|
54
|
+
end
|
55
|
+
|
56
|
+
# Query cloud keypairs and check coherence with local files
|
57
|
+
# of same name in forj files located by :keypair_path
|
58
|
+
def forj_query_keypairs(sCloudObj, sQuery, hParams)
|
59
|
+
keypair_path = File.expand_path(hParams[:keypair_path])
|
60
|
+
keypair_base = File.expand_path(hParams[:keypair_base])
|
61
|
+
|
62
|
+
ssl_error_obj = SSLErrorMgt.new
|
63
|
+
begin
|
64
|
+
keypairs = controller_query(sCloudObj, sQuery)
|
65
|
+
rescue => e
|
66
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
67
|
+
end
|
68
|
+
# Looping on keypairs to identify if they have a valid local ssh key.
|
69
|
+
keypairs.each do |keypair|
|
70
|
+
loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_base)
|
71
|
+
keypair_files_detected(keypair, loc_kpair)
|
72
|
+
end
|
73
|
+
keypairs
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get cloud keypair and check coherence with local files
|
77
|
+
# of same name in forj files
|
78
|
+
def forj_get_keypair(sCloudObj, keypair_name, hParams)
|
79
|
+
ssl_error_obj = SSLErrorMgt.new
|
80
|
+
begin
|
81
|
+
keypair = controller_get(sCloudObj, keypair_name)
|
82
|
+
rescue => e
|
83
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
84
|
+
end
|
85
|
+
|
86
|
+
keypair_path = File.expand_path(hParams[:keypair_path])
|
87
|
+
loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_name)
|
88
|
+
keypair_files_detected(keypair, loc_kpair) unless keypair.empty?
|
89
|
+
keypair
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# ************************************ keypairs Object
|
94
|
+
# Identify keypairs
|
95
|
+
class Lorj::BaseDefinition
|
96
|
+
define_obj(:keypairs,
|
97
|
+
|
98
|
+
:create_e => :forj_get_or_create_keypair,
|
99
|
+
:query_e => :forj_query_keypairs,
|
100
|
+
:get_e => :forj_get_keypair
|
101
|
+
# :delete_e => :forj_delete_keypair
|
102
|
+
)
|
103
|
+
|
104
|
+
obj_needs :CloudObject, :compute_connection
|
105
|
+
obj_needs :data, :keypair_name, :for => [:create_e]
|
106
|
+
obj_needs :data, :keypair_path
|
107
|
+
obj_needs :data, :keypair_base
|
108
|
+
|
109
|
+
# By default optional. But required by the import case if needed.
|
110
|
+
obj_needs_optional
|
111
|
+
obj_needs :data, :public_key, :for => [:create_e]
|
112
|
+
|
113
|
+
def_attribute :public_key
|
114
|
+
end
|
115
|
+
|
116
|
+
# Keypair management: Internal process functions
|
117
|
+
class CloudProcess
|
118
|
+
# Function to display information about keypair object found.
|
119
|
+
#
|
120
|
+
def keypair_display(keypair)
|
121
|
+
PrcLib.info("Found keypair '%s'.", keypair[:name])
|
122
|
+
|
123
|
+
private_key_file = File.join(keypair[:keypair_path],
|
124
|
+
keypair[:private_key_name])
|
125
|
+
public_key_file = File.join(keypair[:keypair_path],
|
126
|
+
keypair[:public_key_name])
|
127
|
+
|
128
|
+
PrcLib.info("Found openssh private key file '%s'.",
|
129
|
+
private_key_file) if keypair[:private_key_exist?]
|
130
|
+
PrcLib.info("Found openssh public key file '%s'.",
|
131
|
+
public_key_file) if keypair[:public_key_exist?]
|
132
|
+
|
133
|
+
unless keypair[:public_key_exist?]
|
134
|
+
name = keypair[:name]
|
135
|
+
PrcLib.warning("The local public key file '%s' is missing.\n"\
|
136
|
+
"As the keypair name '%s' already exists in your cloud, "\
|
137
|
+
'you will need to get the original SSH keypair files '\
|
138
|
+
"used to create the keypair name '%s'. Otherwise, you "\
|
139
|
+
"won't be able to use it to connect to a box configured"\
|
140
|
+
" with '%s'."\
|
141
|
+
"\nPublic key found in the cloud:\n%s",
|
142
|
+
public_key_file, name, name, name,
|
143
|
+
keypair[:public_key])
|
144
|
+
return
|
145
|
+
end
|
146
|
+
|
147
|
+
if keypair[:coherent]
|
148
|
+
PrcLib.info("keypair '%s' local files are coherent with keypair in "\
|
149
|
+
'your cloud service. You will be able to use your local '\
|
150
|
+
'keys to connect to any box configured with this keypair '\
|
151
|
+
'name, over SSH.', keypair[:name])
|
152
|
+
else
|
153
|
+
PrcLib.warning("Your local public key file '%s' is incoherent with "\
|
154
|
+
"public key attached to the keypair '%s' in your cloud."\
|
155
|
+
" You won't be able to access your box with this keypair."\
|
156
|
+
"\nPublic key found in the cloud:\n%s",
|
157
|
+
public_key_file, keypair[:name], keypair[:public_key])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Keypair management: Internal process functions
|
163
|
+
class CloudProcess
|
164
|
+
# Function to update a keypair object with ssh files found in :keypair_path
|
165
|
+
#
|
166
|
+
def keypair_files_detected(keypair, loc_kpair)
|
167
|
+
keypair[:private_key_exist?] = loc_kpair[:private_key_exist?]
|
168
|
+
keypair[:public_key_exist?] = loc_kpair[:public_key_exist?]
|
169
|
+
keypair[:private_key_name] = loc_kpair[:private_key_name]
|
170
|
+
keypair[:public_key_name] = loc_kpair[:public_key_name]
|
171
|
+
keypair[:keypair_path] = loc_kpair[:keypair_path]
|
172
|
+
keypair[:coherent] = coherent_keypair?(loc_kpair, keypair)
|
173
|
+
end
|
174
|
+
|
175
|
+
def keypair_import(hParams, loc_kpair)
|
176
|
+
PrcLib.fatal(1, "Unable to import keypair '%s'. "\
|
177
|
+
'Public key file is not found. '\
|
178
|
+
"Please run 'forj setup %s'",
|
179
|
+
hParams[:keypair_name],
|
180
|
+
config[:account_name]) unless loc_kpair[:public_key_exist?]
|
181
|
+
public_key_file = File.join(loc_kpair[:keypair_path],
|
182
|
+
loc_kpair[:public_key_name])
|
183
|
+
|
184
|
+
begin
|
185
|
+
public_key = File.read(public_key_file)
|
186
|
+
rescue => e
|
187
|
+
PrcLib.fatal(1, "Unable to import keypair '%s'. '%s' is "\
|
188
|
+
"unreadable.\n%s", hParams[:keypair_name],
|
189
|
+
loc_kpair[:public_key_file],
|
190
|
+
e.message)
|
191
|
+
end
|
192
|
+
keypair = create_keypair(:keypairs, :public_key => public_key)
|
193
|
+
|
194
|
+
return nil if keypair.nil?
|
195
|
+
|
196
|
+
# Adding information about SSH key files.
|
197
|
+
keypair_files_detected(keypair, loc_kpair)
|
198
|
+
|
199
|
+
keypair
|
200
|
+
end
|
201
|
+
|
202
|
+
def create_keypair(sCloudObj, hParams)
|
203
|
+
key_name = hParams[:keypair_name]
|
204
|
+
PrcLib.state("Importing keypair '%s'", key_name)
|
205
|
+
ssl_error_obj = SSLErrorMgt.new
|
206
|
+
begin
|
207
|
+
keypair = controller_create(sCloudObj, hParams)
|
208
|
+
PrcLib.info("Keypair '%s' imported.", keypair[:name])
|
209
|
+
rescue StandardError => e
|
210
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
211
|
+
PrcLib.error "error importing keypair '%s'", key_name
|
212
|
+
end
|
213
|
+
keypair
|
214
|
+
end
|
215
|
+
|
216
|
+
# Build keypair data information structure with files found in
|
217
|
+
# local filesystem. Take care of priv with or without .pem
|
218
|
+
# and pubkey with pub.
|
219
|
+
# :keypair_path data settings is changing to become just a path to
|
220
|
+
# the keypair files, the base keypair.
|
221
|
+
# Which will introduce a :keypair_base in the setup.
|
222
|
+
def keypair_detect(keypair_name, key_fullpath, key_basename = nil)
|
223
|
+
# When uses key_basename, we switch to the new model
|
224
|
+
# using :keypair_path and :keypair_base in setup
|
225
|
+
if key_basename.nil?
|
226
|
+
key_basename = File.basename(key_fullpath)
|
227
|
+
key_path = File.expand_path(File.dirname(key_fullpath))
|
228
|
+
else
|
229
|
+
key_path = File.expand_path(key_fullpath)
|
230
|
+
end
|
231
|
+
|
232
|
+
obj_match = key_basename.match(/^(.*?)(\.pem|\.pub)?$/)
|
233
|
+
key_basename = obj_match[1]
|
234
|
+
|
235
|
+
private_key_ext, files = _check_key_file(key_path, key_basename,
|
236
|
+
['', '.pem'])
|
237
|
+
|
238
|
+
if private_key_ext
|
239
|
+
priv_key_exist = true
|
240
|
+
priv_key_name = key_basename + private_key_ext
|
241
|
+
else
|
242
|
+
files.each do |temp_file|
|
243
|
+
PrcLib.warning('keypair_detect: Private key file name detection has '\
|
244
|
+
"detected '%s' as a directory. Usually, it should be a "\
|
245
|
+
'private key file. Please check.',
|
246
|
+
temp_file) if File.directory?(temp_file)
|
247
|
+
end
|
248
|
+
priv_key_exist = false
|
249
|
+
priv_key_name = key_basename
|
250
|
+
end
|
251
|
+
|
252
|
+
pub_key_exist = File.exist?(File.join(key_path, key_basename + '.pub'))
|
253
|
+
pub_key_name = key_basename + '.pub'
|
254
|
+
|
255
|
+
# keypair basic structure
|
256
|
+
{ :keypair_name => keypair_name,
|
257
|
+
:keypair_path => key_path, :key_basename => key_basename,
|
258
|
+
:private_key_name => priv_key_name, :private_key_exist? => priv_key_exist,
|
259
|
+
:public_key_name => pub_key_name, :public_key_exist? => pub_key_exist
|
260
|
+
}
|
261
|
+
end
|
262
|
+
|
263
|
+
def _check_key_file(key_path, key_basename, extensions)
|
264
|
+
found_ext = nil
|
265
|
+
files = []
|
266
|
+
extensions.each do |ext|
|
267
|
+
temp_file = File.join(key_path, key_basename + ext)
|
268
|
+
if File.exist?(temp_file) && !File.directory?(temp_file)
|
269
|
+
found_ext = ext
|
270
|
+
files << temp_file
|
271
|
+
end
|
272
|
+
end
|
273
|
+
[found_ext, files]
|
274
|
+
end
|
275
|
+
|
276
|
+
def get_keypairs_path(hParams, hKeys)
|
277
|
+
keypair_name = hParams[:keypair_name]
|
278
|
+
|
279
|
+
if hKeys[:private_key_exist?]
|
280
|
+
hParams[:private_key_file] = File.join(hKeys[:keypair_path],
|
281
|
+
hKeys[:private_key_name])
|
282
|
+
PrcLib.info("Openssh private key file '%s' exists.",
|
283
|
+
hParams[:private_key_file])
|
284
|
+
end
|
285
|
+
if hKeys[:public_key_exist?]
|
286
|
+
hParams[:public_key_file] = File.join(hKeys[:keypair_path],
|
287
|
+
hKeys[:public_key_name])
|
288
|
+
else
|
289
|
+
PrcLib.fatal(1, 'Public key file is not found. Please run'\
|
290
|
+
" 'forj setup %s'", config[:account_name])
|
291
|
+
end
|
292
|
+
|
293
|
+
PrcLib.state("Searching for keypair '%s'", keypair_name)
|
294
|
+
|
295
|
+
hParams
|
296
|
+
end
|
297
|
+
|
298
|
+
# Check if 2 keypair objects are coherent (Same public key)
|
299
|
+
# Parameters:
|
300
|
+
# - +loc_kpair+ : Keypair structure representing local files existence.
|
301
|
+
# see keypair_detect
|
302
|
+
# - +keypair+ : Keypair object to check.
|
303
|
+
#
|
304
|
+
# return:
|
305
|
+
# - coherent : Boolean. True if same public key.
|
306
|
+
def coherent_keypair?(loc_kpair, keypair)
|
307
|
+
# send keypairs by parameter
|
308
|
+
is_coherent = false
|
309
|
+
|
310
|
+
pub_keypair = keypair[:public_key]
|
311
|
+
|
312
|
+
# Check the public key with the one found here, locally.
|
313
|
+
if !pub_keypair.nil? && pub_keypair != ''
|
314
|
+
return false unless loc_kpair[:public_key_exist?]
|
315
|
+
begin
|
316
|
+
loc_pubkey = File.read(File.join(loc_kpair[:keypair_path],
|
317
|
+
loc_kpair[:public_key_name]))
|
318
|
+
rescue => e
|
319
|
+
PrcLib.error("Unable to read '%s'.\n%s",
|
320
|
+
loc_kpair[:public_key_file], e.message)
|
321
|
+
else
|
322
|
+
if loc_pubkey.split(' ')[1].strip == pub_keypair.split(' ')[1].strip
|
323
|
+
is_coherent = true
|
324
|
+
end
|
325
|
+
end
|
326
|
+
else
|
327
|
+
PrcLib.warning('Unable to verify keypair coherence with your local '\
|
328
|
+
'SSH keys. No public key (:public_key) provided.')
|
329
|
+
end
|
330
|
+
is_coherent
|
331
|
+
end
|
332
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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
|
+
# Network Management
|
22
|
+
class CloudProcess
|
23
|
+
# Process Create handler
|
24
|
+
def forj_get_or_create_network(sCloudObj, hParams)
|
25
|
+
PrcLib.state("Searching for network '%s'", hParams[:network_name])
|
26
|
+
networks = find_network(sCloudObj, hParams)
|
27
|
+
if networks.length == 0
|
28
|
+
network = create_network(sCloudObj, hParams)
|
29
|
+
else
|
30
|
+
network = networks[0]
|
31
|
+
end
|
32
|
+
register(network)
|
33
|
+
|
34
|
+
# Attaching if missing the subnet.
|
35
|
+
# Creates an object subnet, attached to the network.
|
36
|
+
params = {}
|
37
|
+
unless hParams[:subnetwork_name]
|
38
|
+
params[:subnetwork_name] = 'sub-' + hParams[:network_name]
|
39
|
+
end
|
40
|
+
|
41
|
+
process_create(:subnetwork, params)
|
42
|
+
|
43
|
+
network
|
44
|
+
end
|
45
|
+
|
46
|
+
# Process Delete handler
|
47
|
+
def forj_delete_network(sCloudObj, hParams)
|
48
|
+
oProvider.delete(sCloudObj, hParams)
|
49
|
+
rescue => e
|
50
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
51
|
+
end
|
52
|
+
|
53
|
+
def forj_get_network(sCloudObj, sID, hParams)
|
54
|
+
oProvider.get(sCloudObj, sID, hParams)
|
55
|
+
rescue => e
|
56
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Network Object
|
61
|
+
# Identify the network
|
62
|
+
class Lorj::BaseDefinition
|
63
|
+
define_obj(:network,
|
64
|
+
:create_e => :forj_get_or_create_network,
|
65
|
+
:query_e => :controller_query,
|
66
|
+
:get_e => :forj_get_network,
|
67
|
+
:delete_e => :forj_delete_network
|
68
|
+
)
|
69
|
+
obj_needs :CloudObject, :network_connection
|
70
|
+
obj_needs :data, :network_name, :for => [:create_e]
|
71
|
+
|
72
|
+
obj_needs_optional
|
73
|
+
obj_needs :data, :subnetwork_name, :for => [:create_e]
|
74
|
+
|
75
|
+
# Any attribute are queriable
|
76
|
+
def_attribute :external # true if network is external or not.
|
77
|
+
end
|
78
|
+
|
79
|
+
# Network Process internal functions #
|
80
|
+
class CloudProcess
|
81
|
+
# Network creation
|
82
|
+
# It returns:
|
83
|
+
# nil or Provider Object
|
84
|
+
def create_network(sCloudObj, hParams)
|
85
|
+
name = hParams[:network_name]
|
86
|
+
begin
|
87
|
+
PrcLib.state("Creating network '%s'", name)
|
88
|
+
network = controller_create(sCloudObj)
|
89
|
+
PrcLib.info("Network '%s' created", network[:name])
|
90
|
+
rescue => e
|
91
|
+
PrcLib.fatal(1, "Unable to create network '%s'", name, e)
|
92
|
+
end
|
93
|
+
network
|
94
|
+
end
|
95
|
+
|
96
|
+
# Search for a network from his name.
|
97
|
+
# Name may be unique in project context, but not in the cloud system
|
98
|
+
# It returns:
|
99
|
+
# nil or Provider Object
|
100
|
+
def find_network(sCloudObj, hParams)
|
101
|
+
query = { :name => hParams[:network_name] }
|
102
|
+
|
103
|
+
query_single(sCloudObj, query, hParams[:network_name])
|
104
|
+
rescue => e
|
105
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,106 @@
|
|
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
|
+
if ip_address.empty?
|
96
|
+
PrcLib.error("Unable to assign a public IP to server '%s'", name)
|
97
|
+
return ip_address
|
98
|
+
end
|
99
|
+
PrcLib.info("Public IP '%s' for server '%s' "\
|
100
|
+
'assigned.', ip_address[:public_ip], name)
|
101
|
+
rescue => e
|
102
|
+
PrcLib.fatal(1, "Unable to assign a public IP to server '%s'", name, e)
|
103
|
+
end
|
104
|
+
ip_address
|
105
|
+
end
|
106
|
+
end
|