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
|
@@ -1,502 +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
|
-
class SSLErrorMgt
|
|
18
|
-
|
|
19
|
-
def initialize(iMaxRetry = 5)
|
|
20
|
-
@iRetry = 0
|
|
21
|
-
@iMaxRetry = iMaxRetry
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def ErrorDetected(message,backtrace, e)
|
|
25
|
-
if message.match('SSLv2/v3 read server hello A: unknown protocol')
|
|
26
|
-
if @iRetry <@iMaxRetry
|
|
27
|
-
sleep(2)
|
|
28
|
-
@iRetry+=1
|
|
29
|
-
print "%s/%s try... 'unknown protocol' SSL Error\r" % [@iRetry, @iMaxRetry] if PrcLib.level == 0
|
|
30
|
-
return false
|
|
31
|
-
else
|
|
32
|
-
PrcLib.error('Too many retry. %s' % message)
|
|
33
|
-
return true
|
|
34
|
-
end
|
|
35
|
-
elsif e.is_a?(Excon::Errors::InternalServerError)
|
|
36
|
-
if @iRetry <@iMaxRetry
|
|
37
|
-
sleep(2)
|
|
38
|
-
@iRetry+=1
|
|
39
|
-
print "%s/%s try... %s\n" % [@iRetry, @iMaxRetry, ANSI.red(e.class)] if PrcLib.level == 0
|
|
40
|
-
return false
|
|
41
|
-
else
|
|
42
|
-
PrcLib.error('Too many retry. %s' % message)
|
|
43
|
-
return true
|
|
44
|
-
end
|
|
45
|
-
else
|
|
46
|
-
PrcLib.error("Exception %s: %s\n%s" % [e.class, message,backtrace.join("\n")])
|
|
47
|
-
return true
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
class CloudProcess
|
|
55
|
-
def connect(sCloudObj, hParams)
|
|
56
|
-
oSSLError = SSLErrorMgt.new # Retry object
|
|
57
|
-
PrcLib.debug("%s:%s Connecting to '%s' - Project '%s'" % [self.class, sCloudObj, config.get(:provider), hParams[:tenant]])
|
|
58
|
-
begin
|
|
59
|
-
controller_connect(sCloudObj)
|
|
60
|
-
rescue => e
|
|
61
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
62
|
-
retry
|
|
63
|
-
end
|
|
64
|
-
PrcLib.error('%s:%s: Unable to connect.\n%s' % [self.class, sCloudObj, e.message ])
|
|
65
|
-
nil
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# ---------------------------------------------------------------------------
|
|
71
|
-
# Keypair management
|
|
72
|
-
# ---------------------------------------------------------------------------
|
|
73
|
-
class CloudProcess
|
|
74
|
-
|
|
75
|
-
# KeyPair Create Process Handler
|
|
76
|
-
# The process implemented is:
|
|
77
|
-
# * Check local SSH keypairs
|
|
78
|
-
# * Check remote keypair existence
|
|
79
|
-
# * Compare and warn if needed.
|
|
80
|
-
# * Import public key found if missing remotely and name it.
|
|
81
|
-
#
|
|
82
|
-
# Return:
|
|
83
|
-
# - keypair : Lorj::Data keypair object. Following additional data should be found in the keypair attributes
|
|
84
|
-
# - :coherent : Boolean. True, if the local keypair (public AND private) is coherent with remote keypair found in the cloud
|
|
85
|
-
# - :private_key_file: String. Path to local private key file
|
|
86
|
-
# - :public_key_file : String. Path to local public key file
|
|
87
|
-
# - :public_key : String. Public key content. (config[:public_key] is also set - Used to import it)
|
|
88
|
-
#
|
|
89
|
-
def forj_get_or_create_keypair(sCloudObj, hParams)
|
|
90
|
-
sKeypair_name = hParams[:keypair_name]
|
|
91
|
-
# setup has configured and copied the appropriate key to forj keypairs.
|
|
92
|
-
|
|
93
|
-
hLocalKeypair = keypair_detect(sKeypair_name, File.expand_path(hParams[:keypair_path]))
|
|
94
|
-
|
|
95
|
-
private_key_file = File.join(hLocalKeypair[:keypair_path], hLocalKeypair[:private_key_name])
|
|
96
|
-
public_key_file = File.join(hLocalKeypair[:keypair_path], hLocalKeypair[:private_key_name])
|
|
97
|
-
|
|
98
|
-
PrcLib.info("Found openssh private key file '%s'." % private_key_file) if hLocalKeypair[:private_key_exist? ]
|
|
99
|
-
PrcLib.info("Found openssh public key file '%s'." % public_key_file) if hLocalKeypair[:public_key_exist? ]
|
|
100
|
-
|
|
101
|
-
PrcLib.state("Searching for keypair '%s'" % [sKeypair_name] )
|
|
102
|
-
|
|
103
|
-
keypairs = forj_query_keypair(sCloudObj, {:name => sKeypair_name}, hParams)
|
|
104
|
-
|
|
105
|
-
if keypairs.length == 0
|
|
106
|
-
PrcLib.fatal(1, "Unable to import keypair '%s'. Public key file is not found. Please run 'forj setup %s'" % [sKeypair_name, config[:account_name]]) if not hLocalKeypair[:public_key_exist? ]
|
|
107
|
-
begin
|
|
108
|
-
config[:public_key] = File.read(hLocalKeypair[:public_key_file])
|
|
109
|
-
rescue => e
|
|
110
|
-
PrcLib.error("Unable to import keypair '%s'. '%s' is unreadable.\n%s",[hLocalKeypair[:public_key_file], e.message] )
|
|
111
|
-
end
|
|
112
|
-
keypair = create_keypair(sCloudObj, hParams)
|
|
113
|
-
if not hLocalKeypair[:private_key_exist? ]
|
|
114
|
-
keypair[:coherent] = false
|
|
115
|
-
else
|
|
116
|
-
keypair[:coherent] = true
|
|
117
|
-
end
|
|
118
|
-
else
|
|
119
|
-
keypair = keypairs[0]
|
|
120
|
-
keypair[:coherent] = coherent_keypair?(hLocalKeypair, keypair)
|
|
121
|
-
# Adding information about key files.
|
|
122
|
-
end
|
|
123
|
-
if keypair[:coherent]
|
|
124
|
-
keypair[:private_key_file] = hLocalKeypair[:private_key_file]
|
|
125
|
-
keypair[:public_key_file] = hLocalKeypair[:public_key_file]
|
|
126
|
-
end
|
|
127
|
-
keypair
|
|
128
|
-
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def forj_query_keypair(sCloudObj, sQuery, hParams)
|
|
132
|
-
key_name = hParams[:keypair_name]
|
|
133
|
-
oSSLError = SSLErrorMgt.new
|
|
134
|
-
begin
|
|
135
|
-
oList = controller_query(sCloudObj, sQuery)
|
|
136
|
-
query_single(sCloudObj, oList, sQuery, key_name)
|
|
137
|
-
rescue => e
|
|
138
|
-
if not oSSLError.ErrorDetected(e.message, e.backtrace, e)
|
|
139
|
-
retry
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# Internal process function: Create keypair
|
|
146
|
-
def create_keypair(sCloudObj, hParams)
|
|
147
|
-
key_name = hParams[:keypair_name]
|
|
148
|
-
PrcLib.state("Importing keypair '%s'" % [key_name])
|
|
149
|
-
oSSLError=SSLErrorMgt.new
|
|
150
|
-
begin
|
|
151
|
-
keypair = controller_create(sCloudObj)
|
|
152
|
-
PrcLib.info("Keypair '%s' imported." % [keypair[:name]])
|
|
153
|
-
rescue StandardError => e
|
|
154
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
155
|
-
retry
|
|
156
|
-
end
|
|
157
|
-
PrcLib.error "error importing keypair '%s'" % [key_name]
|
|
158
|
-
end
|
|
159
|
-
keypair
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# Build keypair data information structure with files found in local filesystem.
|
|
163
|
-
# Take care of priv with or without .pem and pubkey with pub.
|
|
164
|
-
def keypair_detect(keypair_name, key_fullpath)
|
|
165
|
-
|
|
166
|
-
key_basename = File.basename(key_fullpath)
|
|
167
|
-
key_path = File.expand_path(File.dirname(key_fullpath))
|
|
168
|
-
|
|
169
|
-
mObj = key_basename.match(/^(.*?)(\.pem|\.pub)?$/)
|
|
170
|
-
key_basename = mObj[1]
|
|
171
|
-
|
|
172
|
-
private_key_ext = nil
|
|
173
|
-
temp_file1 = File.join(key_path, key_basename)
|
|
174
|
-
private_key_ext = "" if File.exists?(temp_file1) and not File.directory?(temp_file1)
|
|
175
|
-
temp_file2 = File.join(key_path, key_basename + '.pem')
|
|
176
|
-
private_key_ext = '.pem' if File.exists?(temp_file2) and not File.directory?(temp_file2)
|
|
177
|
-
|
|
178
|
-
if private_key_ext
|
|
179
|
-
private_key_exist = true
|
|
180
|
-
private_key_name = key_basename + private_key_ext
|
|
181
|
-
else
|
|
182
|
-
[ temp_file1, temp_file2].each { | temp_file |
|
|
183
|
-
PrcLib.warning("keypair_detect: Private key file name detection has detected '%s' as a directory. Usually, it should be a private key file. Please check." % temp_file) if File.directory?(temp_file)
|
|
184
|
-
}
|
|
185
|
-
private_key_exist = false
|
|
186
|
-
private_key_name = key_basename
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
public_key_exist = File.exists?(File.join(key_path, key_basename + '.pub'))
|
|
190
|
-
public_key_name = key_basename + '.pub'
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
# keypair basic structure
|
|
194
|
-
{:keypair_name => keypair_name,
|
|
195
|
-
:keypair_path => key_path, :key_basename => key_basename,
|
|
196
|
-
:private_key_name => private_key_name, :private_key_exist? => private_key_exist,
|
|
197
|
-
:public_key_name => public_key_name, :public_key_exist? => public_key_exist
|
|
198
|
-
}
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def forj_get_keypair(sCloudObj, sName, hParams)
|
|
202
|
-
oSSLError = SSLErrorMgt.new
|
|
203
|
-
begin
|
|
204
|
-
controller_get(sCloudObj, sName)
|
|
205
|
-
rescue => e
|
|
206
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
207
|
-
retry
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def get_keypairs_path(hParams, hKeys)
|
|
213
|
-
sKeypair_name = hParams[:keypair_name]
|
|
214
|
-
|
|
215
|
-
if hKeys[:private_key_exist? ]
|
|
216
|
-
hParams[:private_key_file] = File.join(hKeys[:keypair_path], hKeys[:private_key_name])
|
|
217
|
-
PrcLib.info("Openssh private key file '%s' exists." % hParams[:private_key_file])
|
|
218
|
-
end
|
|
219
|
-
if hKeys[:public_key_exist? ]
|
|
220
|
-
hParams[:public_key_file] = File.join(hKeys[:keypair_path], hKeys[:public_key_name])
|
|
221
|
-
else
|
|
222
|
-
PrcLib.fatal(1, "Public key file is not found. Please run 'forj setup %s'" % config[:account_name])
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
PrcLib.state("Searching for keypair '%s'" % [sKeypair_name] )
|
|
226
|
-
|
|
227
|
-
hParams
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
# Check if 2 keypair objects are coherent (Same public key)
|
|
231
|
-
# Parameters:
|
|
232
|
-
# - +hLocalKeypair+ : Keypair structure representing local files existence. see keypair_detect
|
|
233
|
-
# - +keypair+ : Keypair object to check.
|
|
234
|
-
#
|
|
235
|
-
# return:
|
|
236
|
-
# - coherent : Boolean. True if same public key.
|
|
237
|
-
def coherent_keypair?(hLocalKeypair, keypair)
|
|
238
|
-
#send keypairs by parameter
|
|
239
|
-
|
|
240
|
-
sKeypair_name = hLocalKeypair[:keypair_name]
|
|
241
|
-
bCoherent = false
|
|
242
|
-
|
|
243
|
-
# Check the public key with the one found here, locally.
|
|
244
|
-
if not keypair[:public_key].nil? and keypair[:public_key] != ""
|
|
245
|
-
begin
|
|
246
|
-
local_pub_key = File.read(File.join(hLocalKeypair[:keypair_path], hLocalKeypair[:public_key_name]))
|
|
247
|
-
rescue => e
|
|
248
|
-
PrcLib.error("Unable to read '%s'.\n%s" % [hLocalKeypair[:public_key_file], e.message] )
|
|
249
|
-
else
|
|
250
|
-
if local_pub_key.split(' ')[1].strip == keypair[:public_key].split(' ')[1].strip
|
|
251
|
-
PrcLib.info("keypair '%s' local files are coherent with keypair in your cloud service. You will be able to connect to your box over SSH." % sKeypair_name)
|
|
252
|
-
bCoherent = true
|
|
253
|
-
else
|
|
254
|
-
PrcLib.warning("Your local keypair file '%s' are incoherent with public key '%s' found in your cloud. You won't be able to access your box with this keypair.\nPublic key found in the cloud:\n%s" % [hLocalKeypair[:public_key_file], sKeypair_name, keypair[:public_key]])
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
else
|
|
258
|
-
PrcLib.warning("Unable to verify keypair coherence with your local SSH keys. No public key (:public_key) provided.")
|
|
259
|
-
end
|
|
260
|
-
bCoherent
|
|
261
|
-
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
# ---------------------------------------------------------------------------
|
|
266
|
-
# flavor management
|
|
267
|
-
# ---------------------------------------------------------------------------
|
|
268
|
-
class CloudProcess
|
|
269
|
-
# Depending on clouds/rights, we can create flavor or not.
|
|
270
|
-
# Usually, flavor records already exists, and the controller may map them
|
|
271
|
-
# CloudProcess predefines some values. Consult CloudProcess.rb for details
|
|
272
|
-
def forj_get_or_create_flavor(sCloudObj, hParams)
|
|
273
|
-
sFlavor_name = hParams[:flavor_name]
|
|
274
|
-
PrcLib.state("Searching for flavor '%s'" % [sFlavor_name] )
|
|
275
|
-
|
|
276
|
-
flavors = query_flavor(sCloudObj, {:name => sFlavor_name}, hParams)
|
|
277
|
-
if flavors.length == 0
|
|
278
|
-
if not hParams[:create]
|
|
279
|
-
PrcLib.error("Unable to create %s '%s'. Creation is not supported." % [sCloudObj, sFlavor_name])
|
|
280
|
-
ForjLib::Data.new.set(nil, sCloudObj)
|
|
281
|
-
else
|
|
282
|
-
create_flavor(sCloudObj,hParams)
|
|
283
|
-
end
|
|
284
|
-
else
|
|
285
|
-
flavors[0]
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
# Should return 1 or 0 flavor.
|
|
290
|
-
def query_flavor(sCloudObj, sQuery, hParams)
|
|
291
|
-
sFlavor_name = hParams[:flavor_name]
|
|
292
|
-
oList = forj_query_flavor(sCloudObj, sQuery, hParams)
|
|
293
|
-
query_single(sCloudObj, oList, sQuery, sFlavor_name)
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
# Should return 1 or 0 flavor.
|
|
297
|
-
def forj_query_flavor(sCloudObj, sQuery, hParams)
|
|
298
|
-
sFlavor_name = hParams[:flavor_name]
|
|
299
|
-
oSSLError = SSLErrorMgt.new
|
|
300
|
-
begin
|
|
301
|
-
oList = controller_query(sCloudObj, sQuery)
|
|
302
|
-
rescue => e
|
|
303
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
304
|
-
retry
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
oList
|
|
308
|
-
end
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
# ---------------------------------------------------------------------------
|
|
312
|
-
# Image management
|
|
313
|
-
# ---------------------------------------------------------------------------
|
|
314
|
-
class CloudProcess
|
|
315
|
-
def forj_get_or_create_image(sCloudObj, hParams)
|
|
316
|
-
sImage_name = hParams[:image_name]
|
|
317
|
-
PrcLib.state("Searching for image '%s'" % [sImage_name] )
|
|
318
|
-
|
|
319
|
-
search_the_image(sCloudObj, {:name => sImage_name}, hParams)
|
|
320
|
-
# No creation possible.
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def search_the_image(sCloudObj, sQuery, hParams)
|
|
324
|
-
image_name = hParams[:image_name]
|
|
325
|
-
images = forj_query_image(sCloudObj, sQuery, hParams)
|
|
326
|
-
case images.length()
|
|
327
|
-
when 0
|
|
328
|
-
PrcLib.info("No image '%s' found" % [ image_name ] )
|
|
329
|
-
nil
|
|
330
|
-
when 1
|
|
331
|
-
PrcLib.info("Found image '%s'." % [ image_name ])
|
|
332
|
-
images[0, :ssh_user] = ssh_user(images[0, :name])
|
|
333
|
-
images[0]
|
|
334
|
-
else
|
|
335
|
-
PrcLib.info("Found several images '%s'. Selecting the first one '%s'" % [ image_name, images[0, :name] ])
|
|
336
|
-
images[0, :ssh_user] = ssh_user(images[0, :name])
|
|
337
|
-
images[0]
|
|
338
|
-
end
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
def forj_query_image(sCloudObj, sQuery, hParams)
|
|
342
|
-
oSSLError = SSLErrorMgt.new
|
|
343
|
-
begin
|
|
344
|
-
images = controller_query(sCloudObj, sQuery)
|
|
345
|
-
rescue => e
|
|
346
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
347
|
-
retry
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
images.each { |image|
|
|
351
|
-
image[:ssh_user] = ssh_user(image[:name])
|
|
352
|
-
}
|
|
353
|
-
images
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
def ssh_user(image_name)
|
|
357
|
-
return "fedora" if image_name =~ /fedora/i
|
|
358
|
-
return "centos" if image_name =~ /centos/i
|
|
359
|
-
return "ubuntu"
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
# ---------------------------------------------------------------------------
|
|
364
|
-
# Server management
|
|
365
|
-
# ---------------------------------------------------------------------------
|
|
366
|
-
class CloudProcess
|
|
367
|
-
# Process Handler functions
|
|
368
|
-
def forj_get_or_create_server(sCloudObj, hParams)
|
|
369
|
-
sServer_name = hParams[:server_name]
|
|
370
|
-
PrcLib.state("Searching for server '%s'" % [sServer_name] )
|
|
371
|
-
servers = forj_query_server(sCloudObj, {:name => sServer_name}, hParams)
|
|
372
|
-
if servers.length > 0
|
|
373
|
-
# Get server details
|
|
374
|
-
forj_get_server(sCloudObj, servers[0][:attrs][:id], hParams)
|
|
375
|
-
else
|
|
376
|
-
create_server(sCloudObj, hParams)
|
|
377
|
-
end
|
|
378
|
-
end
|
|
379
|
-
|
|
380
|
-
def forj_delete_server(sCloudObj, hParams)
|
|
381
|
-
oSSLError = SSLErrorMgt.new
|
|
382
|
-
begin
|
|
383
|
-
controller_delete(sCloudObj)
|
|
384
|
-
PrcLib.info("Server %s was destroyed " % hParams[:server][:name] )
|
|
385
|
-
rescue => e
|
|
386
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
387
|
-
retry
|
|
388
|
-
end
|
|
389
|
-
end
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
def forj_query_server(sCloudObj, sQuery, hParams)
|
|
393
|
-
oSSLError = SSLErrorMgt.new
|
|
394
|
-
begin
|
|
395
|
-
controller_query(sCloudObj, sQuery)
|
|
396
|
-
rescue => e
|
|
397
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
398
|
-
retry
|
|
399
|
-
end
|
|
400
|
-
end
|
|
401
|
-
end
|
|
402
|
-
|
|
403
|
-
def forj_get_server(sCloudObj, sId, hParams)
|
|
404
|
-
oSSLError = SSLErrorMgt.new
|
|
405
|
-
begin
|
|
406
|
-
controller_get(sCloudObj, sId)
|
|
407
|
-
rescue => e
|
|
408
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
409
|
-
retry
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
end
|
|
413
|
-
|
|
414
|
-
# Internal Process function
|
|
415
|
-
def create_server(sCloudObj, hParams)
|
|
416
|
-
name = hParams[:server_name]
|
|
417
|
-
begin
|
|
418
|
-
PrcLib.info("boot: meta-data provided.") if hParams[:meta_data]
|
|
419
|
-
PrcLib.info("boot: user-data provided.") if hParams[:user_data]
|
|
420
|
-
PrcLib.state('creating server %s' % [name])
|
|
421
|
-
server = controller_create(sCloudObj)
|
|
422
|
-
PrcLib.info("%s '%s' created." % [sCloudObj, name])
|
|
423
|
-
rescue => e
|
|
424
|
-
PrcLib.fatal(1, "Unable to create server '%s'" % name, e)
|
|
425
|
-
end
|
|
426
|
-
server
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
def forj_get_server_log(sCloudObj, sId, hParams)
|
|
430
|
-
oSSLError = SSLErrorMgt.new
|
|
431
|
-
begin
|
|
432
|
-
controller_get(sCloudObj, sId)
|
|
433
|
-
rescue => e
|
|
434
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
435
|
-
retry
|
|
436
|
-
end
|
|
437
|
-
end
|
|
438
|
-
end
|
|
439
|
-
end
|
|
440
|
-
# ---------------------------------------------------------------------------
|
|
441
|
-
# Addresses management
|
|
442
|
-
# ---------------------------------------------------------------------------
|
|
443
|
-
class CloudProcess
|
|
444
|
-
# Process Handler functions
|
|
445
|
-
def forj_get_or_assign_public_address(sCloudObj, hParams)
|
|
446
|
-
# Function which to assign a public IP address to a server.
|
|
447
|
-
sServer_name = hParams[:server, :name]
|
|
448
|
-
|
|
449
|
-
PrcLib.state("Searching public IP for server '%s'" % [sServer_name] )
|
|
450
|
-
addresses = controller_query(sCloudObj, {:server_id => hParams[:server, :id]})
|
|
451
|
-
if addresses.length == 0
|
|
452
|
-
assign_address(sCloudObj, hParams)
|
|
453
|
-
else
|
|
454
|
-
addresses[0]
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
def forj_query_public_address(sCloudObj, sQuery, hParams)
|
|
459
|
-
server_name = hParams[:server, :name]
|
|
460
|
-
oSSLError = SSLErrorMgt.new
|
|
461
|
-
begin
|
|
462
|
-
sInfo = {
|
|
463
|
-
:notfound => "No %s for '%s' found",
|
|
464
|
-
:checkmatch => "Found 1 %s. checking exact match for server '%s'.",
|
|
465
|
-
:nomatch => "No %s for '%s' match",
|
|
466
|
-
:found => "Found %s '%s' for #{server_name}.",
|
|
467
|
-
:more => "Found several %s. Searching for '%s'.",
|
|
468
|
-
:items => :public_ip
|
|
469
|
-
}
|
|
470
|
-
oList = controller_query(sCloudObj, sQuery)
|
|
471
|
-
query_single(sCloudObj, oList, sQuery, server_name, sInfo)
|
|
472
|
-
rescue => e
|
|
473
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
474
|
-
retry
|
|
475
|
-
end
|
|
476
|
-
end
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
def forj_get_public_address(sCloudObj, sId, hParams)
|
|
480
|
-
oSSLError = SSLErrorMgt.new
|
|
481
|
-
begin
|
|
482
|
-
controller_get(sCloudObj, sId)
|
|
483
|
-
rescue => e
|
|
484
|
-
if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
|
|
485
|
-
retry
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
# Internal Process function
|
|
491
|
-
def assign_address(sCloudObj, hParams)
|
|
492
|
-
name = hParams[:server, :name]
|
|
493
|
-
begin
|
|
494
|
-
PrcLib.state('Getting public IP for server %s' % [name])
|
|
495
|
-
ip_address = controller_create(sCloudObj)
|
|
496
|
-
PrcLib.info("Public IP '%s' for server '%s' assigned." % [ip_address[:public_ip], name])
|
|
497
|
-
rescue => e
|
|
498
|
-
PrcLib.fatal(1, "Unable to assign a public IP to server '%s'" % name, e)
|
|
499
|
-
end
|
|
500
|
-
ip_address
|
|
501
|
-
end
|
|
502
|
-
end
|