lorj 0.2.0 → 1.0.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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
# Keypair management
|
|
20
|
+
class CloudProcess
|
|
21
|
+
# KeyPair Create Process Handler
|
|
22
|
+
# The process implemented is:
|
|
23
|
+
# * Check local SSH keypairs
|
|
24
|
+
# * Check remote keypair existence
|
|
25
|
+
# * Compare and warn if needed.
|
|
26
|
+
# * Import public key found if missing remotely and name it.
|
|
27
|
+
#
|
|
28
|
+
# Return:
|
|
29
|
+
# - keypair : Lorj::Data keypair object. Following additional data should be
|
|
30
|
+
# found in the keypair attributes
|
|
31
|
+
# - :coherent : Boolean. True, if the local keypair (public AND
|
|
32
|
+
# private) is coherent with remote keypair found in
|
|
33
|
+
# the cloud
|
|
34
|
+
# - :private_key_file: String. Path to local private key file
|
|
35
|
+
# - :public_key_file : String. Path to local public key file
|
|
36
|
+
# - :public_key : String. Public key content. (config[:public_key] is
|
|
37
|
+
# also set - Used to import it)
|
|
38
|
+
#
|
|
39
|
+
def forj_get_or_create_keypair(sCloudObj, hParams)
|
|
40
|
+
keypair_name = hParams[:keypair_name]
|
|
41
|
+
# setup has configured and copied the appropriate key to forj keypairs.
|
|
42
|
+
|
|
43
|
+
loc_kpair = keypair_detect(keypair_name,
|
|
44
|
+
File.expand_path(hParams[:keypair_path]))
|
|
45
|
+
|
|
46
|
+
private_key_file = File.join(loc_kpair[:keypair_path],
|
|
47
|
+
loc_kpair[:private_key_name])
|
|
48
|
+
public_key_file = File.join(loc_kpair[:keypair_path],
|
|
49
|
+
loc_kpair[:public_key_name])
|
|
50
|
+
|
|
51
|
+
PrcLib.info("Found openssh private key file '%s'.",
|
|
52
|
+
private_key_file) if loc_kpair[:private_key_exist?]
|
|
53
|
+
PrcLib.info("Found openssh public key file '%s'.",
|
|
54
|
+
public_key_file) if loc_kpair[:public_key_exist?]
|
|
55
|
+
|
|
56
|
+
PrcLib.state("Searching for keypair '%s'", keypair_name)
|
|
57
|
+
|
|
58
|
+
keypairs = forj_query_keypair(sCloudObj,
|
|
59
|
+
{ :name => keypair_name }, hParams)
|
|
60
|
+
|
|
61
|
+
if keypairs.length == 0
|
|
62
|
+
keypair = keypair_import(keypair_name, loc_kpair)
|
|
63
|
+
else
|
|
64
|
+
keypair = keypairs[0]
|
|
65
|
+
keypair[:coherent] = coherent_keypair?(loc_kpair, keypair)
|
|
66
|
+
# Adding information about key files.
|
|
67
|
+
end
|
|
68
|
+
if keypair[:coherent]
|
|
69
|
+
keypair[:private_key_file] = loc_kpair[:private_key_file]
|
|
70
|
+
keypair[:public_key_file] = loc_kpair[:public_key_file]
|
|
71
|
+
end
|
|
72
|
+
keypair
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def forj_query_keypair(sCloudObj, sQuery, hParams)
|
|
76
|
+
key_name = hParams[:keypair_name]
|
|
77
|
+
ssl_error_obj = SSLErrorMgt.new
|
|
78
|
+
begin
|
|
79
|
+
list = controller_query(sCloudObj, sQuery)
|
|
80
|
+
query_single(sCloudObj, list, sQuery, key_name)
|
|
81
|
+
rescue => e
|
|
82
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Keypair management: Internal process functions
|
|
88
|
+
class CloudProcess
|
|
89
|
+
def keypair_import(keypair_name, loc_kpair)
|
|
90
|
+
PrcLib.fatal(1, "Unable to import keypair '%s'. "\
|
|
91
|
+
'Public key file is not found. '\
|
|
92
|
+
"Please run 'forj setup %s'",
|
|
93
|
+
keypair_name,
|
|
94
|
+
config[:account_name]) unless loc_kpair[:public_key_exist?]
|
|
95
|
+
begin
|
|
96
|
+
config[:public_key] = File.read(loc_kpair[:public_key_file])
|
|
97
|
+
rescue => e
|
|
98
|
+
PrcLib.fatal(1, "Unable to import keypair '%s'. '%s' is "\
|
|
99
|
+
"unreadable.\n%s", keypair_name,
|
|
100
|
+
loc_kpair[:public_key_file], e.message)
|
|
101
|
+
end
|
|
102
|
+
keypair = create_keypair(sCloudObj, hParams)
|
|
103
|
+
if !loc_kpair[:private_key_exist?]
|
|
104
|
+
keypair[:coherent] = false
|
|
105
|
+
else
|
|
106
|
+
keypair[:coherent] = true
|
|
107
|
+
end
|
|
108
|
+
keypair
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def create_keypair(sCloudObj, hParams)
|
|
112
|
+
key_name = hParams[:keypair_name]
|
|
113
|
+
PrcLib.state("Importing keypair '%s'", key_name)
|
|
114
|
+
ssl_error_obj = SSLErrorMgt.new
|
|
115
|
+
begin
|
|
116
|
+
keypair = controller_create(sCloudObj)
|
|
117
|
+
PrcLib.info("Keypair '%s' imported.", keypair[:name])
|
|
118
|
+
rescue StandardError => e
|
|
119
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
|
120
|
+
PrcLib.error "error importing keypair '%s'", key_name
|
|
121
|
+
end
|
|
122
|
+
keypair
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Build keypair data information structure with files found in
|
|
126
|
+
# local filesystem. Take care of priv with or without .pem
|
|
127
|
+
# and pubkey with pub.
|
|
128
|
+
def keypair_detect(keypair_name, key_fullpath)
|
|
129
|
+
key_basename = File.basename(key_fullpath)
|
|
130
|
+
key_path = File.expand_path(File.dirname(key_fullpath))
|
|
131
|
+
|
|
132
|
+
obj_match = key_basename.match(/^(.*?)(\.pem|\.pub)?$/)
|
|
133
|
+
key_basename = obj_match[1]
|
|
134
|
+
|
|
135
|
+
private_key_ext, files = _check_key_file(key_path, key_basename,
|
|
136
|
+
['', '.pem'])
|
|
137
|
+
|
|
138
|
+
if private_key_ext
|
|
139
|
+
priv_key_exist = true
|
|
140
|
+
priv_key_name = key_basename + private_key_ext
|
|
141
|
+
else
|
|
142
|
+
files.each do | temp_file |
|
|
143
|
+
PrcLib.warning('keypair_detect: Private key file name detection has '\
|
|
144
|
+
"detected '%s' as a directory. Usually, it should be a "\
|
|
145
|
+
'private key file. Please check.',
|
|
146
|
+
temp_file) if File.directory?(temp_file)
|
|
147
|
+
end
|
|
148
|
+
priv_key_exist = false
|
|
149
|
+
priv_key_name = key_basename
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
pub_key_exist = File.exist?(File.join(key_path, key_basename + '.pub'))
|
|
153
|
+
pub_key_name = key_basename + '.pub'
|
|
154
|
+
|
|
155
|
+
# keypair basic structure
|
|
156
|
+
{ :keypair_name => keypair_name,
|
|
157
|
+
:keypair_path => key_path, :key_basename => key_basename,
|
|
158
|
+
:private_key_name => priv_key_name, :private_key_exist? => priv_key_exist,
|
|
159
|
+
:public_key_name => pub_key_name, :public_key_exist? => pub_key_exist
|
|
160
|
+
}
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def _check_key_file(key_path, key_basename, extensions)
|
|
164
|
+
found_ext = nil
|
|
165
|
+
files = []
|
|
166
|
+
extensions.each do | ext |
|
|
167
|
+
temp_file = File.join(key_path, key_basename + ext)
|
|
168
|
+
if File.exist?(temp_file) && !File.directory?(temp_file)
|
|
169
|
+
found_ext = ext
|
|
170
|
+
files << temp_file
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
[found_ext, files]
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def forj_get_keypair(sCloudObj, sName, _hParams)
|
|
177
|
+
ssl_error_obj = SSLErrorMgt.new
|
|
178
|
+
begin
|
|
179
|
+
controller_get(sCloudObj, sName)
|
|
180
|
+
rescue => e
|
|
181
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def get_keypairs_path(hParams, hKeys)
|
|
186
|
+
keypair_name = hParams[:keypair_name]
|
|
187
|
+
|
|
188
|
+
if hKeys[:private_key_exist?]
|
|
189
|
+
hParams[:private_key_file] = File.join(hKeys[:keypair_path],
|
|
190
|
+
hKeys[:private_key_name])
|
|
191
|
+
PrcLib.info("Openssh private key file '%s' exists.",
|
|
192
|
+
hParams[:private_key_file])
|
|
193
|
+
end
|
|
194
|
+
if hKeys[:public_key_exist?]
|
|
195
|
+
hParams[:public_key_file] = File.join(hKeys[:keypair_path],
|
|
196
|
+
hKeys[:public_key_name])
|
|
197
|
+
else
|
|
198
|
+
PrcLib.fatal(1, 'Public key file is not found. Please run'\
|
|
199
|
+
" 'forj setup %s'", config[:account_name])
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
PrcLib.state("Searching for keypair '%s'", keypair_name)
|
|
203
|
+
|
|
204
|
+
hParams
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Check if 2 keypair objects are coherent (Same public key)
|
|
208
|
+
# Parameters:
|
|
209
|
+
# - +loc_kpair+ : Keypair structure representing local files existence.
|
|
210
|
+
# see keypair_detect
|
|
211
|
+
# - +keypair+ : Keypair object to check.
|
|
212
|
+
#
|
|
213
|
+
# return:
|
|
214
|
+
# - coherent : Boolean. True if same public key.
|
|
215
|
+
def coherent_keypair?(loc_kpair, keypair)
|
|
216
|
+
# send keypairs by parameter
|
|
217
|
+
|
|
218
|
+
keypair_name = loc_kpair[:keypair_name]
|
|
219
|
+
is_coherent = false
|
|
220
|
+
|
|
221
|
+
pub_keypair = keypair[:public_key]
|
|
222
|
+
|
|
223
|
+
# Check the public key with the one found here, locally.
|
|
224
|
+
if !pub_keypair.nil? && pub_keypair != ''
|
|
225
|
+
begin
|
|
226
|
+
loc_pubkey = File.read(File.join(loc_kpair[:keypair_path],
|
|
227
|
+
loc_kpair[:public_key_name]))
|
|
228
|
+
rescue => e
|
|
229
|
+
PrcLib.error("Unable to read '%s'.\n%s",
|
|
230
|
+
loc_kpair[:public_key_file], e.message)
|
|
231
|
+
else
|
|
232
|
+
if loc_pubkey.split(' ')[1].strip == pub_keypair.split(' ')[1].strip
|
|
233
|
+
PrcLib.info("keypair '%s' local files are coherent with keypair in "\
|
|
234
|
+
'your cloud service. You will be able to connect to '\
|
|
235
|
+
'your box over SSH.', keypair_name)
|
|
236
|
+
is_coherent = true
|
|
237
|
+
else
|
|
238
|
+
PrcLib.warning("Your local keypair file '%s' are incoherent with "\
|
|
239
|
+
"public key '%s' found in your cloud. You won't be "\
|
|
240
|
+
"able to access your box with this keypair.\nPublic "\
|
|
241
|
+
"key found in the cloud:\n%s",
|
|
242
|
+
loc_kpair[:public_key_file], keypair_name,
|
|
243
|
+
keypair[:public_key])
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
else
|
|
247
|
+
PrcLib.warning('Unable to verify keypair coherence with your local '\
|
|
248
|
+
'SSH keys. No public key (:public_key) provided.')
|
|
249
|
+
end
|
|
250
|
+
is_coherent
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Define framework object on BaseDefinition
|
|
255
|
+
module Lorj
|
|
256
|
+
# ************************************ keypairs Object
|
|
257
|
+
# Identify keypairs
|
|
258
|
+
class BaseDefinition
|
|
259
|
+
define_obj(:keypairs,
|
|
260
|
+
|
|
261
|
+
:create_e => :forj_get_or_create_keypair,
|
|
262
|
+
:query_e => :forj_query_keypair,
|
|
263
|
+
:get_e => :forj_get_keypair
|
|
264
|
+
# :delete_e => :forj_delete_keypair
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
obj_needs :CloudObject, :compute_connection
|
|
268
|
+
obj_needs :data, :keypair_name, :for => [:create_e]
|
|
269
|
+
obj_needs :data, :keypair_path, :for => [:create_e]
|
|
270
|
+
|
|
271
|
+
obj_needs_optional
|
|
272
|
+
obj_needs :data, :public_key, :for => [:create_e]
|
|
273
|
+
|
|
274
|
+
def_attribute :public_key
|
|
275
|
+
end
|
|
276
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
# Network Management
|
|
20
|
+
class CloudProcess
|
|
21
|
+
# Process Create handler
|
|
22
|
+
def forj_get_or_create_network(sCloudObj, hParams)
|
|
23
|
+
PrcLib.state("Searching for network '%s'", hParams[:network_name])
|
|
24
|
+
networks = find_network(sCloudObj, hParams)
|
|
25
|
+
if networks.length == 0
|
|
26
|
+
network = create_network(sCloudObj, hParams)
|
|
27
|
+
else
|
|
28
|
+
network = networks[0]
|
|
29
|
+
end
|
|
30
|
+
register(network)
|
|
31
|
+
|
|
32
|
+
# Attaching if missing the subnet.
|
|
33
|
+
# Creates an object subnet, attached to the network.
|
|
34
|
+
unless hParams[:subnetwork_name]
|
|
35
|
+
hParams[:subnetwork_name] = 'sub-' + hParams[:network_name]
|
|
36
|
+
config[:subnetwork_name] = hParams[:subnetwork_name]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# object.Create(:subnetwork)
|
|
40
|
+
Create(:subnetwork)
|
|
41
|
+
|
|
42
|
+
network
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Process Delete handler
|
|
46
|
+
def forj_delete_network(sCloudObj, hParams)
|
|
47
|
+
oProvider.delete(sCloudObj, hParams)
|
|
48
|
+
rescue => e
|
|
49
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def forj_get_network(sCloudObj, sID, hParams)
|
|
53
|
+
oProvider.get(sCloudObj, sID, hParams)
|
|
54
|
+
rescue => e
|
|
55
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Define framework object on BaseDefinition
|
|
60
|
+
module Lorj
|
|
61
|
+
# ************************************ Network Object
|
|
62
|
+
# Identify the network
|
|
63
|
+
class BaseDefinition
|
|
64
|
+
define_obj(:network,
|
|
65
|
+
:create_e => :forj_get_or_create_network,
|
|
66
|
+
:query_e => :controller_query,
|
|
67
|
+
:get_e => :forj_get_network,
|
|
68
|
+
:delete_e => :forj_delete_network
|
|
69
|
+
)
|
|
70
|
+
obj_needs :CloudObject, :network_connection
|
|
71
|
+
obj_needs :data, :network_name, :for => [:create_e]
|
|
72
|
+
|
|
73
|
+
obj_needs_optional
|
|
74
|
+
obj_needs :data, :subnetwork_name, :for => [:create_e]
|
|
75
|
+
|
|
76
|
+
def_query_attribute :external # true if network is external or not.
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Network Process internal functions #
|
|
81
|
+
class CloudProcess
|
|
82
|
+
# Network creation
|
|
83
|
+
# It returns:
|
|
84
|
+
# nil or Provider Object
|
|
85
|
+
def create_network(sCloudObj, hParams)
|
|
86
|
+
name = hParams[:network_name]
|
|
87
|
+
begin
|
|
88
|
+
PrcLib.state("Creating network '%s'", name)
|
|
89
|
+
network = controller_create(sCloudObj)
|
|
90
|
+
PrcLib.info("Network '%s' created", network[:name])
|
|
91
|
+
rescue => e
|
|
92
|
+
PrcLib.fatal(1, "Unable to create network '%s'", name, e)
|
|
93
|
+
end
|
|
94
|
+
network
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Search for a network from his name.
|
|
98
|
+
# Name may be unique in project context, but not in the cloud system
|
|
99
|
+
# It returns:
|
|
100
|
+
# nil or Provider Object
|
|
101
|
+
def find_network(sCloudObj, hParams)
|
|
102
|
+
query = { :name => hParams[:network_name] }
|
|
103
|
+
list = controller_query(sCloudObj, query)
|
|
104
|
+
query_single(sCloudObj, list, query, hParams[:network_name])
|
|
105
|
+
rescue => e
|
|
106
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
# Addresses management
|
|
20
|
+
class CloudProcess
|
|
21
|
+
# Process Handler functions
|
|
22
|
+
def forj_get_or_assign_public_address(sCloudObj, hParams)
|
|
23
|
+
# Function which to assign a public IP address to a server.
|
|
24
|
+
server_name = hParams[:server, :name]
|
|
25
|
+
|
|
26
|
+
PrcLib.state("Searching public IP for server '%s'", server_name)
|
|
27
|
+
addresses = controller_query(sCloudObj, :server_id => hParams[:server, :id])
|
|
28
|
+
if addresses.length == 0
|
|
29
|
+
assign_address(sCloudObj, hParams)
|
|
30
|
+
else
|
|
31
|
+
addresses[0]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def forj_query_public_address(sCloudObj, sQuery, hParams)
|
|
36
|
+
server_name = hParams[:server, :name]
|
|
37
|
+
ssl_error_obj = SSLErrorMgt.new
|
|
38
|
+
begin
|
|
39
|
+
info = {
|
|
40
|
+
:notfound => "No %s for '%s' found",
|
|
41
|
+
:checkmatch => "Found 1 %s. checking exact match for server '%s'.",
|
|
42
|
+
:nomatch => "No %s for '%s' match",
|
|
43
|
+
:found => "Found %s '%s' for #{server_name}.",
|
|
44
|
+
:more => "Found several %s. Searching for '%s'.",
|
|
45
|
+
:items => :public_ip
|
|
46
|
+
}
|
|
47
|
+
list = controller_query(sCloudObj, sQuery)
|
|
48
|
+
query_single(sCloudObj, list, sQuery, server_name, info)
|
|
49
|
+
rescue => e
|
|
50
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def forj_get_public_address(sCloudObj, sId, _hParams)
|
|
55
|
+
ssl_error_obj = SSLErrorMgt.new
|
|
56
|
+
begin
|
|
57
|
+
controller_get(sCloudObj, sId)
|
|
58
|
+
rescue => e
|
|
59
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Define framework object on BaseDefinition
|
|
65
|
+
module Lorj
|
|
66
|
+
# ************************************ SERVER Addresses Object
|
|
67
|
+
# Object representing the list of IP addresses attached to a server.
|
|
68
|
+
class BaseDefinition
|
|
69
|
+
define_obj(:public_ip,
|
|
70
|
+
:create_e => :forj_get_or_assign_public_address,
|
|
71
|
+
:query_e => :forj_query_public_address
|
|
72
|
+
# :get_e => :forj_get_address
|
|
73
|
+
# :update_e => :forj_update_address
|
|
74
|
+
# :delete_e => :forj_delete_address
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
obj_needs :CloudObject, :compute_connection
|
|
78
|
+
obj_needs :CloudObject, :server
|
|
79
|
+
|
|
80
|
+
def_attribute :server_id
|
|
81
|
+
def_attribute :public_ip
|
|
82
|
+
undefine_attribute :name # No name to extract
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Internal Process function
|
|
87
|
+
class CloudProcess
|
|
88
|
+
def assign_address(sCloudObj, hParams)
|
|
89
|
+
name = hParams[:server, :name]
|
|
90
|
+
begin
|
|
91
|
+
PrcLib.state('Getting public IP for server %s', name)
|
|
92
|
+
ip_address = controller_create(sCloudObj)
|
|
93
|
+
PrcLib.info("Public IP '%s' for server '%s' "\
|
|
94
|
+
'assigned.', ip_address[:public_ip], name)
|
|
95
|
+
rescue => e
|
|
96
|
+
PrcLib.fatal(1, "Unable to assign a public IP to server '%s'", name, e)
|
|
97
|
+
end
|
|
98
|
+
ip_address
|
|
99
|
+
end
|
|
100
|
+
end
|