forj 0.0.40 → 0.0.41
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/README.md +28 -9
- data/bin/forj +263 -59
- data/lib/boot.rb +42 -37
- data/lib/compute.rb +4 -1
- data/lib/connection.rb +1 -1
- data/lib/defaults.yaml +93 -31
- data/lib/down.rb +10 -8
- data/lib/forj-account.rb +84 -20
- data/lib/forj-config.rb +105 -31
- data/lib/network.rb +28 -28
- data/lib/repositories.rb +1 -1
- data/lib/security.rb +8 -8
- data/lib/setup.rb +1 -1
- data/lib/ssh.rb +13 -9
- data/lib/ssh.sh +7 -6
- data/spec/forj-config_spec.rb +43 -29
- metadata +2 -2
data/lib/forj-config.rb
CHANGED
@@ -37,19 +37,22 @@ class ForjDefault
|
|
37
37
|
Logging.fatal(1, 'Internal $LIB_PATH was not set.')
|
38
38
|
end
|
39
39
|
|
40
|
-
Logging.info
|
40
|
+
Logging.info('Reading default configuration...')
|
41
41
|
|
42
42
|
@sDefaultsName=File.join($LIB_PATH,'defaults.yaml')
|
43
43
|
|
44
44
|
@yDefaults=YAML.load_file(@sDefaultsName)
|
45
45
|
end
|
46
46
|
|
47
|
-
def exist?(key, section =
|
47
|
+
def exist?(key, section = :default)
|
48
|
+
key = key.to_sym if key.class == String
|
48
49
|
(rhExist?(@yDefaults, section, key) == 2)
|
49
50
|
end
|
50
51
|
|
51
|
-
def get(key, section =
|
52
|
-
|
52
|
+
def get(key, section = :default)
|
53
|
+
key = key.to_sym if key.class == String
|
54
|
+
return(rhGet(@yDefaults, section, key)) if key
|
55
|
+
rhGet(@yDefaults, section) if not key
|
53
56
|
end
|
54
57
|
|
55
58
|
def dump()
|
@@ -73,13 +76,14 @@ class ForjConfig
|
|
73
76
|
|
74
77
|
def default_dump(interms = nil)
|
75
78
|
# Build a config hash.
|
79
|
+
|
76
80
|
res = {}
|
77
|
-
@oDefaults.dump[
|
81
|
+
@oDefaults.dump[:default].each_key { |key|
|
78
82
|
dump_key = exist?(key)
|
79
83
|
rhSet(res, get(key), dump_key, key)
|
80
84
|
}
|
81
|
-
if rhExist?(@yLocal,
|
82
|
-
@yLocal[
|
85
|
+
if rhExist?(@yLocal, :default) == 1
|
86
|
+
@yLocal[:default].each_key { |key|
|
83
87
|
dump_key = exist?(key)
|
84
88
|
rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
|
85
89
|
}
|
@@ -90,8 +94,7 @@ class ForjConfig
|
|
90
94
|
dump_key = exist?(key)
|
91
95
|
rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
|
92
96
|
}
|
93
|
-
elsif interms.instance_of? Array # Array of hash
|
94
|
-
iCount=0
|
97
|
+
elsif interms.instance_of? Array # Array of hash of hash
|
95
98
|
interms.each { | elem |
|
96
99
|
elem.each_key { | key|
|
97
100
|
dump_key = exist?(key)
|
@@ -104,7 +107,7 @@ class ForjConfig
|
|
104
107
|
dump_key = exist?(key)
|
105
108
|
rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
|
106
109
|
}
|
107
|
-
|
110
|
+
|
108
111
|
res
|
109
112
|
end
|
110
113
|
|
@@ -135,8 +138,13 @@ class ForjConfig
|
|
135
138
|
|
136
139
|
if File.exists?(@sConfigName)
|
137
140
|
@yLocal = YAML.load_file(@sConfigName)
|
141
|
+
if rhKeyToSymbol?(@yLocal, 2)
|
142
|
+
@yLocal = rhKeyToSymbol(@yLocal, 2)
|
143
|
+
self.SaveConfig()
|
144
|
+
end
|
145
|
+
|
138
146
|
else
|
139
|
-
@yLocal = {
|
147
|
+
@yLocal = { :default => nil }
|
140
148
|
# Write the empty file
|
141
149
|
Logging.info('Creating your default configuration file ...')
|
142
150
|
self.SaveConfig()
|
@@ -155,7 +163,7 @@ class ForjConfig
|
|
155
163
|
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
156
164
|
return false
|
157
165
|
end
|
158
|
-
Logging.info
|
166
|
+
Logging.info('Configuration file "%s" updated.' % @sConfigName)
|
159
167
|
return true
|
160
168
|
end
|
161
169
|
|
@@ -170,7 +178,7 @@ class ForjConfig
|
|
170
178
|
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
171
179
|
return false
|
172
180
|
end
|
173
|
-
Logging.info
|
181
|
+
Logging.info('Configuration file "%s" updated.' % sFile)
|
174
182
|
return true
|
175
183
|
end
|
176
184
|
end
|
@@ -186,6 +194,8 @@ class ForjConfig
|
|
186
194
|
def ExtraExist?(section, name, key = nil)
|
187
195
|
return nil if not section or not name
|
188
196
|
|
197
|
+
key = key.to_sym if key.class == String
|
198
|
+
|
189
199
|
return(rhExist?(@yObjConfig, section, name) == 2) if not key
|
190
200
|
return(rhExist?(@yObjConfig, section, name, key) == 3)
|
191
201
|
end
|
@@ -193,13 +203,15 @@ class ForjConfig
|
|
193
203
|
def ExtraGet(section, name, key = nil, default = nil)
|
194
204
|
return nil if not section or not name
|
195
205
|
|
206
|
+
key = key.to_sym if key.class == String
|
196
207
|
return default unless ExtraExist?(section, name, key)
|
197
208
|
return rhGet(@yObjConfig, section, name, key) if key
|
198
209
|
rhGet(@yObjConfig, section, name)
|
199
210
|
end
|
200
211
|
|
201
|
-
def ExtraSet(section, name, key
|
202
|
-
|
212
|
+
def ExtraSet(section, name, key, value)
|
213
|
+
key = key.to_sym if key.class == String
|
214
|
+
if key
|
203
215
|
rhSet(@yObjConfig, value, section, name, key)
|
204
216
|
else
|
205
217
|
rhSet(@yObjConfig, value, section, name)
|
@@ -210,9 +222,10 @@ class ForjConfig
|
|
210
222
|
# Function to set a runtime key/value, but remove it if value is nil.
|
211
223
|
# To set in config.yaml, use LocalSet
|
212
224
|
# To set on extra data, like account information, use ExtraSet
|
213
|
-
|
214
|
-
|
215
|
-
|
225
|
+
|
226
|
+
key = key.to_sym if key.class == String
|
227
|
+
return false if key.class != Symbol
|
228
|
+
|
216
229
|
if value
|
217
230
|
rhSet(@yRuntime, value, key)
|
218
231
|
else
|
@@ -222,21 +235,28 @@ class ForjConfig
|
|
222
235
|
end
|
223
236
|
|
224
237
|
def get(key, interms = nil, default = nil)
|
238
|
+
|
239
|
+
key = key.to_sym if key.class == String
|
240
|
+
return nil if key.class != Symbol
|
225
241
|
# If key is in runtime
|
226
242
|
return rhGet(@yRuntime, key) if rhExist?(@yRuntime, key) == 1
|
227
243
|
# Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
|
228
244
|
if interms
|
229
245
|
if interms.instance_of? Hash
|
230
246
|
return rhGet(interms, key) if rhExist?(interms, key) == 1
|
231
|
-
elsif interms.instance_of? Array # Array of
|
247
|
+
elsif interms.instance_of? Array # Array of hashes
|
232
248
|
iCount=0
|
249
|
+
oVal = nil
|
233
250
|
interms.each { | elem |
|
234
251
|
if elem.class == Hash
|
235
|
-
oVal = nil
|
236
252
|
elem.each { | hashkey, value |
|
237
|
-
if value.class == Hash and rhExist?(elem, hashkey, key) == 2
|
238
|
-
oVal = rhGet
|
253
|
+
if value.class == Hash and rhExist?(elem, hashkey, key) == 2 # hash of hash
|
254
|
+
oVal = rhGet(elem, hashkey, key)
|
255
|
+
break
|
256
|
+
elsif value.class != Hash and rhExist?(elem, hashkey) == 1 # single hash: key = value.
|
257
|
+
oVal = rhGet(elem, hashkey)
|
239
258
|
break
|
259
|
+
|
240
260
|
end
|
241
261
|
}
|
242
262
|
break if oVal
|
@@ -254,11 +274,16 @@ class ForjConfig
|
|
254
274
|
default
|
255
275
|
end
|
256
276
|
|
257
|
-
def getAppDefault(section, key)
|
277
|
+
def getAppDefault(section, key = nil)
|
278
|
+
|
279
|
+
key = key.to_sym if key.class == String
|
280
|
+
|
258
281
|
@oDefaults.get(key, section)
|
259
282
|
end
|
260
283
|
|
261
284
|
def exist?(key, interms = nil)
|
285
|
+
key = key.to_sym if key.class == String
|
286
|
+
|
262
287
|
# Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
|
263
288
|
return "runtime" if rhExist?(@yRuntime, key) == 1
|
264
289
|
if interms
|
@@ -266,10 +291,11 @@ class ForjConfig
|
|
266
291
|
return 'hash' if rhExist?(interms, key) == 1
|
267
292
|
elsif interms.instance_of? Array # Array of hash
|
268
293
|
iCount = 0
|
269
|
-
|
294
|
+
interms.each { | elem |
|
270
295
|
if elem.class == Hash
|
271
296
|
elem.each { | hashkey, value |
|
272
297
|
return ("%s" % hashkey) if value.class == Hash and rhExist?(elem, hashkey, key) == 2
|
298
|
+
return ("hash[%s]" % iCount) if value.class != Hash and rhExist?(elem, hashkey) == 1
|
273
299
|
}
|
274
300
|
end
|
275
301
|
iCount += 1
|
@@ -286,12 +312,15 @@ class ForjConfig
|
|
286
312
|
LocalExist?(key)
|
287
313
|
end
|
288
314
|
|
289
|
-
def LocalExist?(key, section =
|
315
|
+
def LocalExist?(key, section = :default)
|
316
|
+
|
317
|
+
key = key.to_sym if key.class == String
|
290
318
|
return true if rhExist?(@yLocal, section, key) == 2
|
291
319
|
false
|
292
320
|
end
|
293
321
|
|
294
|
-
def LocalSet(key, value, section =
|
322
|
+
def LocalSet(key, value, section = :default)
|
323
|
+
key = key.to_sym if key.class == String
|
295
324
|
if not key or not value
|
296
325
|
return false
|
297
326
|
end
|
@@ -306,12 +335,15 @@ class ForjConfig
|
|
306
335
|
return true
|
307
336
|
end
|
308
337
|
|
309
|
-
def LocalGet(key, section =
|
338
|
+
def LocalGet(key, section = :default, default = nil)
|
339
|
+
key = key.to_sym if key.class == String
|
340
|
+
|
310
341
|
return default if rhExist?(@yLocal, section, key) != 2
|
311
342
|
rhGet(@yLocal, section, key)
|
312
343
|
end
|
313
344
|
|
314
|
-
def LocalDel(key, section =
|
345
|
+
def LocalDel(key, section = :default)
|
346
|
+
key = key.to_sym if key.class == String
|
315
347
|
if not key
|
316
348
|
return false
|
317
349
|
end
|
@@ -342,7 +374,6 @@ def rhExist?(yVal, *p)
|
|
342
374
|
return 0 if not yVal or not yVal[p[0]]
|
343
375
|
ret = rhExist?(yVal[p[0]], p.drop(1)) if yVal[p[0]]
|
344
376
|
return 1 + ret
|
345
|
-
0
|
346
377
|
end
|
347
378
|
|
348
379
|
def rhGet(yVal, *p)
|
@@ -367,10 +398,18 @@ def rhSet(yVal, value, *p)
|
|
367
398
|
p=p.flatten
|
368
399
|
if p.length() == 1
|
369
400
|
if yVal
|
370
|
-
|
401
|
+
if value
|
402
|
+
yVal[p[0]] = value
|
403
|
+
else
|
404
|
+
yVal.delete(p[0])
|
405
|
+
end
|
371
406
|
return yVal
|
372
407
|
end
|
373
|
-
|
408
|
+
if value
|
409
|
+
ret = { p[0] => value }
|
410
|
+
else
|
411
|
+
ret = {}
|
412
|
+
end
|
374
413
|
return ret
|
375
414
|
end
|
376
415
|
if yVal
|
@@ -382,3 +421,38 @@ def rhSet(yVal, value, *p)
|
|
382
421
|
return { p[0] => ret }
|
383
422
|
end
|
384
423
|
end
|
424
|
+
|
425
|
+
def rhKeyToSymbol(yVal, levels = 1)
|
426
|
+
return nil if not yVal
|
427
|
+
yRes = {}
|
428
|
+
yVal.each { | key, value |
|
429
|
+
if key.class == String
|
430
|
+
if levels <= 1
|
431
|
+
yRes[key.to_sym] = value
|
432
|
+
else
|
433
|
+
yRes[key.to_sym] = rhKeyToSymbol(value, levels - 1)
|
434
|
+
end
|
435
|
+
else
|
436
|
+
if levels <= 1
|
437
|
+
yRes[key] = value
|
438
|
+
else
|
439
|
+
yRes[key] = rhKeyToSymbol(value, levels - 1)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
}
|
443
|
+
yRes
|
444
|
+
end
|
445
|
+
|
446
|
+
def rhKeyToSymbol?(yVal, levels = 1)
|
447
|
+
return false if not yVal
|
448
|
+
yVal.each { | key, value |
|
449
|
+
if key.class == String
|
450
|
+
return true
|
451
|
+
end
|
452
|
+
if levels >1
|
453
|
+
res = rhKeyToSymbol?(value, levels - 1)
|
454
|
+
return true if res
|
455
|
+
end
|
456
|
+
}
|
457
|
+
false
|
458
|
+
end
|
data/lib/network.rb
CHANGED
@@ -49,7 +49,7 @@ module Network
|
|
49
49
|
else
|
50
50
|
Logging.warning("Several network was found with '%s'. Selecting the first one '%s'." % [name, networks[0].name])
|
51
51
|
networks[0]
|
52
|
-
|
52
|
+
end
|
53
53
|
rescue => e
|
54
54
|
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
55
55
|
end
|
@@ -75,36 +75,36 @@ module Network
|
|
75
75
|
|
76
76
|
|
77
77
|
# Subnet management
|
78
|
-
|
79
|
-
|
80
|
-
begin
|
81
|
-
subnets = oFC.oNetwork.subnets.all(:network_id => network_id)
|
82
|
-
rescue => e
|
83
|
-
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
84
|
-
end
|
85
|
-
if subnets
|
86
|
-
case subnets.length()
|
87
|
-
when 0
|
88
|
-
Logging.debug("No subnet found from '%s' network" % [name])
|
89
|
-
subnet = nil
|
90
|
-
when 1
|
91
|
-
Logging.debug("Found '%s' subnet from '%s' network" % [subnets[0].name, name])
|
92
|
-
subnet = subnets[0]
|
93
|
-
else
|
94
|
-
Logging.warning("Several subnet was found on '%s'. Choosing the first one = '%s'" % [name, subnets[0].name])
|
95
|
-
subnet = subnets[0]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
if not subnet
|
99
|
-
# Create the subnet with 'sub-' prefixing the network name.
|
78
|
+
def get_or_create_subnet(oFC, network_id, name)
|
79
|
+
Logging.state("Searching for sub-network attached '%s'." % [name])
|
100
80
|
begin
|
101
|
-
|
81
|
+
subnets = oFC.oNetwork.subnets.all(:network_id => network_id)
|
102
82
|
rescue => e
|
103
|
-
|
83
|
+
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
104
84
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
85
|
+
if subnets
|
86
|
+
case subnets.length()
|
87
|
+
when 0
|
88
|
+
Logging.debug("No subnet found from '%s' network" % [name])
|
89
|
+
subnet = nil
|
90
|
+
when 1
|
91
|
+
Logging.debug("Found '%s' subnet from '%s' network" % [subnets[0].name, name])
|
92
|
+
subnet = subnets[0]
|
93
|
+
else
|
94
|
+
Logging.warning("Several subnet was found on '%s'. Choosing the first one = '%s'" % [name, subnets[0].name])
|
95
|
+
subnet = subnets[0]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
if not subnet
|
99
|
+
# Create the subnet with 'sub-' prefixing the network name.
|
100
|
+
begin
|
101
|
+
subnet = create_subnet(oFC, network_id, 'sub-%s' % [name])
|
102
|
+
rescue => e
|
103
|
+
Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
return subnet
|
107
|
+
end
|
108
108
|
|
109
109
|
def create_subnet(oFC, network_id, name)
|
110
110
|
Logging.debug("Creating subnet '%s'" % [name])
|
data/lib/repositories.rb
CHANGED
@@ -125,7 +125,7 @@ module Repositories
|
|
125
125
|
|
126
126
|
# SET_DOMAIN="{SET_DOMAIN!}" => Setting for Maestro (required) and DNS if enabled.
|
127
127
|
# ==> :forj_accounts, sAccountName, :dns, :domain_name
|
128
|
-
sAccountName = oConfig.get(
|
128
|
+
sAccountName = oConfig.get(:account_name)
|
129
129
|
|
130
130
|
yDns = {}
|
131
131
|
yDns = oConfig.ExtraGet(:forj_accounts, sAccountName, :dns) if oConfig.ExtraExist?(:forj_accounts, sAccountName, :dns)
|
data/lib/security.rb
CHANGED
@@ -138,7 +138,7 @@ module SecurityGroup
|
|
138
138
|
rule
|
139
139
|
end
|
140
140
|
|
141
|
-
|
141
|
+
def keypair_detect(keypair_name, key_fullpath)
|
142
142
|
# Build key data information structure.
|
143
143
|
# Take care of priv with or without .pem and pubkey with pub.
|
144
144
|
|
@@ -163,17 +163,17 @@ module SecurityGroup
|
|
163
163
|
public_key_name = key_basename + '.pub'
|
164
164
|
|
165
165
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
166
|
+
{:keypair_name => keypair_name,
|
167
|
+
:keypair_path => key_path, :key_basename => key_basename,
|
168
|
+
:private_key_name => private_key_name, :private_key_exist? => private_key_exist,
|
169
|
+
:public_key_name => public_key_name, :public_key_exist? => public_key_exist,
|
170
|
+
}
|
171
171
|
end
|
172
172
|
|
173
173
|
def hpc_import_key(oForjAccount)
|
174
174
|
|
175
|
-
keys = keypair_detect(oForjAccount.get(
|
176
|
-
account = oForjAccount.get(:
|
175
|
+
keys = keypair_detect(oForjAccount.get('keypair_name'), oForjAccount.get('keypair_path'))
|
176
|
+
account = oForjAccount.get(:name)
|
177
177
|
|
178
178
|
Logging.fatal(1, "'keypair_path' undefined. check your config.yaml file.") if not keys[:keypair_path]
|
179
179
|
Logging.fatal(1, "'keypair_name' undefined. check your config.yaml file.") if not keys[:keypair_name]
|
data/lib/setup.rb
CHANGED
data/lib/ssh.rb
CHANGED
@@ -16,28 +16,32 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
18
|
require 'rubygems'
|
19
|
-
require 'require_relative'
|
20
|
-
|
21
|
-
#require_relative 'log.rb'
|
22
|
-
#include Logging
|
23
19
|
|
20
|
+
require 'security.rb'
|
21
|
+
include SecurityGroup
|
24
22
|
#
|
25
23
|
# ssh module
|
26
24
|
#
|
27
25
|
module Ssh
|
28
|
-
def connect(name, server)
|
26
|
+
def connect(name, server, oConfig)
|
29
27
|
msg = 'logging into %s : %s' % [name, server]
|
30
28
|
Logging.info(msg)
|
31
|
-
current_dir = Dir.pwd
|
32
|
-
Dir.chdir(current_dir + '/lib')
|
33
29
|
|
34
|
-
|
35
|
-
|
30
|
+
oForjAccount = ForjAccount.new(oConfig)
|
31
|
+
|
32
|
+
oForjAccount.ac_load()
|
33
|
+
|
34
|
+
oKey = SecurityGroup.keypair_detect(oForjAccount.get(:keypair_name), oForjAccount.get(:keypair_path))
|
35
|
+
|
36
|
+
update = '%s/ssh.sh -u %s' % [ $LIB_PATH, oConfig.get(:account_name)]
|
37
|
+
connection = '%s/ssh.sh %s %s %s' % [$LIB_PATH, name, server, File.join(oKey[:keypair_path],oKey[:private_key_name]) ]
|
36
38
|
|
37
39
|
# update the list of servers
|
40
|
+
Logging.debug("Executing '%s'" % update)
|
38
41
|
Kernel.system(update)
|
39
42
|
|
40
43
|
# connect to the server
|
44
|
+
Logging.debug("Executing '%s'" % connection)
|
41
45
|
Kernel.system(connection)
|
42
46
|
end
|
43
47
|
end
|