forj 1.0.1 → 1.0.2

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.gitreview +4 -0
  4. data/Gemfile +21 -19
  5. data/Gemfile.lock +71 -0
  6. data/bin/forj +126 -83
  7. data/forj.gemspec +64 -0
  8. data/{lib → forj}/defaults.yaml +23 -1
  9. data/lib/appinit.rb +5 -5
  10. data/lib/build_tmpl/build-env.py +293 -0
  11. data/lib/cloud_test.rb +121 -0
  12. data/lib/forj-settings.rb +52 -39
  13. data/lib/forj/ForjCli.rb +11 -10
  14. data/lib/forj/ForjCore.rb +8 -6
  15. data/lib/forj/process/ForjProcess.rb +345 -82
  16. data/lib/ssh.rb +81 -20
  17. metadata +110 -80
  18. data/lib/compute.rb +0 -36
  19. data/lib/connection.rb +0 -144
  20. data/lib/down.rb +0 -60
  21. data/lib/forj-account.rb +0 -294
  22. data/lib/forj-config.rb +0 -522
  23. data/lib/helpers.rb +0 -56
  24. data/lib/lib-forj/lib/core/core.rb +0 -1740
  25. data/lib/lib-forj/lib/core/definition.rb +0 -441
  26. data/lib/lib-forj/lib/core/definition_internal.rb +0 -306
  27. data/lib/lib-forj/lib/core_process/CloudProcess.rb +0 -334
  28. data/lib/lib-forj/lib/core_process/global_process.rb +0 -406
  29. data/lib/lib-forj/lib/core_process/network_process.rb +0 -603
  30. data/lib/lib-forj/lib/lib-forj.rb +0 -37
  31. data/lib/lib-forj/lib/providers/hpcloud/Hpcloud.rb +0 -419
  32. data/lib/lib-forj/lib/providers/hpcloud/compute.rb +0 -108
  33. data/lib/lib-forj/lib/providers/hpcloud/network.rb +0 -117
  34. data/lib/lib-forj/lib/providers/hpcloud/security_groups.rb +0 -67
  35. data/lib/lib-forj/lib/providers/templates/compute.rb +0 -42
  36. data/lib/lib-forj/lib/providers/templates/core.rb +0 -61
  37. data/lib/lib-forj/lib/providers/templates/network.rb +0 -33
  38. data/lib/log.rb +0 -162
  39. data/lib/network.rb +0 -365
  40. data/lib/repositories.rb +0 -222
  41. data/lib/security.rb +0 -207
  42. data/lib/ssh.sh +0 -185
  43. data/spec/connection_spec.rb +0 -52
  44. data/spec/forj-config_spec.rb +0 -237
  45. data/spec/repositories_spec.rb +0 -50
data/lib/forj-config.rb DELETED
@@ -1,522 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
-
19
- # puts "test_library included"
20
-
21
- require 'rubygems'
22
- require 'yaml'
23
-
24
- #require_relative 'log.rb'
25
- #include Logging
26
-
27
- def rhExist?(yVal, *p)
28
-
29
- if p.length() == 0
30
- return 0
31
- end
32
- return 0 if yVal.class != Hash
33
- p=p.flatten
34
- if p.length() == 1
35
- return 1 if yVal.key?(p[0])
36
- return 0
37
- end
38
- return 0 if yVal.nil? or not yVal.key?(p[0])
39
- ret = 0
40
- ret = rhExist?(yVal[p[0]], p.drop(1)) if yVal[p[0]].class == Hash
41
- return 1 + ret
42
- end
43
-
44
- def rhGet(yVal, *p)
45
-
46
- return nil if yVal.class != Hash
47
- p=p.flatten
48
- if p.length() == 0 or not yVal
49
- return yVal
50
- end
51
- if p.length() == 1
52
- return yVal[p[0]] if yVal.key?(p[0])
53
- return nil
54
- end
55
- return nil if not yVal
56
- return rhGet(yVal[p[0]], p.drop(1)) if yVal.key?(p[0])
57
- nil
58
- end
59
-
60
- def rhSet(yVal, value, *p)
61
- if p.length() == 0
62
- return yVal
63
- end
64
- p=p.flatten
65
- if p.length() == 1
66
- if not yVal.nil?
67
- if not value.nil?
68
- yVal[p[0]] = value
69
- else
70
- yVal.delete(p[0])
71
- end
72
- return yVal
73
- end
74
- #~ if value
75
- ret = { p[0] => value }
76
- #~ else
77
- #~ ret = {}
78
- #~ end
79
- return ret
80
- end
81
- if not yVal.nil?
82
- yVal[p[0]] = {} if not yVal[p[0]] or yVal[p[0]].class != Hash
83
- ret=rhSet(yVal[p[0]], value, p.drop(1))
84
- return yVal
85
- else
86
- ret = rhSet(nil, value, p.drop(1))
87
- return { p[0] => ret }
88
- end
89
- end
90
-
91
- def rhKeyToSymbol(yVal, levels = 1)
92
- return nil if yVal.nil? or yVal.class != Hash
93
- yRes = {}
94
- yVal.each { | key, value |
95
- if key.class == String
96
- if levels <= 1
97
- yRes[key.to_sym] = value
98
- else
99
- yRes[key.to_sym] = rhKeyToSymbol(value, levels - 1)
100
- end
101
- else
102
- if levels <= 1
103
- yRes[key] = value
104
- else
105
- yRes[key] = rhKeyToSymbol(value, levels - 1)
106
- end
107
- end
108
- }
109
- yRes
110
- end
111
-
112
- def rhKeyToSymbol?(yVal, levels = 1)
113
- return false if yVal.nil? or yVal.class != Hash
114
- yVal.each { | key, value |
115
- if key.class == String
116
- return true
117
- end
118
- if levels >1
119
- res = rhKeyToSymbol?(value, levels - 1)
120
- return true if res
121
- end
122
- }
123
- false
124
- end
125
-
126
- class ForjDefault
127
-
128
- # @sDefaultsName='defaults.yaml'
129
- # @yDefaults = defaults.yaml file data hash
130
-
131
- # Load yaml documents (defaults)
132
- # If config doesn't exist, it will be created, empty with 'defaults:' only
133
-
134
-
135
- def self.exist?(key, section = :default)
136
- key = key.to_sym if key.class == String
137
- (rhExist?(@@yDefaults, section, key) == 2)
138
- end
139
-
140
- def self.get(key, section = :default)
141
- key = key.to_sym if key.class == String
142
- return(rhGet(@@yDefaults, section, key)) if key
143
- rhGet(@@yDefaults, section) if not key
144
- end
145
-
146
- def self.dump()
147
- @@yDefaults
148
- end
149
- # Loop on Config metadata
150
- def self.meta_each
151
- rhGet(@@yDefaults, :sections).each { | section, hValue |
152
- hValue.each { | key, value |
153
- yield section, key, value
154
- }
155
- }
156
- end
157
-
158
- def self.meta_exist?(key)
159
- return nil if not key
160
-
161
- key = key.to_sym if key.class == String
162
- section = rhGet(@@account_section_mapping, key)
163
- rhExist?(@@yDefaults, :sections, section, key) == 3
164
- end
165
-
166
- def self.get_meta(key)
167
- return nil if not key
168
-
169
- key = key.to_sym if key.class == String
170
- section = rhGet(@@account_section_mapping, key)
171
- rhGet(@@yDefaults, :sections, section, key)
172
- end
173
-
174
- def self.build_section_mapping
175
- @@account_section_mapping = {}
176
- rhGet(@@yDefaults, :sections).each { | section, hValue |
177
- next if section == :default
178
- hValue.each_key { | map_key |
179
- Logging.fatal(1, "defaults.yaml: Duplicate entry between sections. '%s' defined in section '%s' already exists in section '%s'" % [map_key, section, rhGet(@account_section_mapping, map_key) ])if rhExist?(@account_section_mapping, map_key) != 0
180
- rhSet(@@account_section_mapping, section, map_key)
181
- }
182
- }
183
- end
184
-
185
- def self.get_meta_section(key)
186
- key = key.to_sym if key.class == String
187
- rhGet(@@account_section_mapping, key)
188
- end
189
-
190
- if not $LIB_PATH
191
- Logging.fatal(1, 'Internal $LIB_PATH was not set.')
192
- end
193
-
194
- Logging.info('Reading default configuration...')
195
-
196
- @@sDefaultsName=File.join($LIB_PATH,'defaults.yaml')
197
-
198
- @@yDefaults=YAML.load_file(@@sDefaultsName)
199
-
200
- self.build_section_mapping
201
- end
202
-
203
- class ForjConfig
204
-
205
- # Internal Object variables:
206
- # @sConfigName= 'config.yaml'
207
- # @yRuntime = data in memory.
208
- # @yLocal = config.yaml file data hash.
209
- # @yObjConfig = Extra loaded data
210
- # ForjDefault = Application defaults class
211
-
212
- attr_reader :sConfigName
213
-
214
- # Load yaml documents (defaults + config)
215
- # If config doesn't exist, it will be created, empty with 'defaults:' only
216
-
217
- def default_dump(interms = nil)
218
- # Build a config hash.
219
-
220
- res = {}
221
- ForjDefault.dump[:default].each_key { |key|
222
- dump_key = exist?(key)
223
- rhSet(res, get(key), dump_key, key)
224
- }
225
- if rhExist?(@yLocal, :default) == 1
226
- @yLocal[:default].each_key { |key|
227
- dump_key = exist?(key)
228
- rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
229
- }
230
- end
231
- if interms
232
- if interms.instance_of? Hash
233
- @interms.each_key { | key|
234
- dump_key = exist?(key)
235
- rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
236
- }
237
- elsif interms.instance_of? Array # Array of hash of hash
238
- interms.each { | elem |
239
- elem.each_key { | key|
240
- dump_key = exist?(key)
241
- rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
242
- }
243
- }
244
- end
245
- end
246
- @yRuntime.each_key { |key|
247
- dump_key = exist?(key)
248
- rhSet(res, get(key), dump_key, key) if rhExist?(res, dump_key, key) != 2
249
- }
250
-
251
- res
252
- end
253
-
254
- def initialize(sConfigName=nil)
255
-
256
- if not $FORJ_DATA_PATH
257
- Logging.fatal(1, 'Internal $FORJ_DATA_PATH was not set.')
258
- end
259
-
260
- sConfigDefaultName='config.yaml'
261
-
262
- if sConfigName
263
- if File.dirname(sConfigName) == '.'
264
- sConfigName = File.join($FORJ_DATA_PATH,sConfigName)
265
- end
266
- sConfigName = File.expand_path(sConfigName)
267
- if not File.exists?(sConfigName)
268
- Logging.warning("Config file '%s' doesn't exists. Using default one." % [sConfigName] )
269
- @sConfigName = File.join($FORJ_DATA_PATH,sConfigDefaultName)
270
- else
271
- @sConfigName = sConfigName
272
- end
273
- else
274
- @sConfigName = File.join($FORJ_DATA_PATH,sConfigDefaultName)
275
- end
276
-
277
- if File.exists?(@sConfigName)
278
- @yLocal = YAML.load_file(@sConfigName)
279
- if rhKeyToSymbol?(@yLocal, 2)
280
- @yLocal = rhKeyToSymbol(@yLocal, 2)
281
- self.SaveConfig()
282
- end
283
-
284
- else
285
- @yLocal = { :default => nil }
286
- # Write the empty file
287
- Logging.info('Creating your default configuration file ...')
288
- self.SaveConfig()
289
- end
290
-
291
- @yRuntime = {}
292
- @yObjConfig = {}
293
- end
294
-
295
- def SaveConfig()
296
- begin
297
- File.open(@sConfigName, 'w') do |out|
298
- YAML.dump(@yLocal, out)
299
- end
300
- rescue => e
301
- Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
302
- return false
303
- end
304
- Logging.info('Configuration file "%s" updated.' % @sConfigName)
305
- return true
306
- end
307
-
308
- def ExtraSave(sFile, section, name)
309
- hVal = rhGet(@yObjConfig, section, name)
310
- if hVal
311
- begin
312
- File.open(sFile, 'w') do |out|
313
- YAML.dump(hVal, out)
314
- end
315
- rescue => e
316
- Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
317
- return false
318
- end
319
- Logging.info('Configuration file "%s" updated.' % sFile)
320
- return true
321
- end
322
- end
323
-
324
- def ExtraLoad(sFile, section, name)
325
- if File.exists?(sFile)
326
- hVal = YAML.load_file(sFile)
327
- rhSet(@yObjConfig, hVal, section, name)
328
- hVal
329
- end
330
- end
331
-
332
- def ExtraExist?(section, name, key = nil)
333
- return nil if not section or not name
334
-
335
- key = key.to_sym if key.class == String
336
-
337
- return(rhExist?(@yObjConfig, section, name) == 2) if not key
338
- return(rhExist?(@yObjConfig, section, name, key) == 3)
339
- end
340
-
341
- def ExtraGet(section, name, key = nil, default = nil)
342
- return nil if not section or not name
343
-
344
- key = key.to_sym if key.class == String
345
- return default unless ExtraExist?(section, name, key)
346
- return rhGet(@yObjConfig, section, name, key) if key
347
- rhGet(@yObjConfig, section, name)
348
- end
349
-
350
- def ExtraSet(section, name, key, value)
351
- key = key.to_sym if key.class == String
352
- if key
353
- rhSet(@yObjConfig, value, section, name, key)
354
- else
355
- rhSet(@yObjConfig, value, section, name)
356
- end
357
- end
358
-
359
- def set(key, value)
360
- # Function to set a runtime key/value, but remove it if value is nil.
361
- # To set in config.yaml, use LocalSet
362
- # To set on extra data, like account information, use ExtraSet
363
-
364
- key = key.to_sym if key.class == String
365
- return false if key.class != Symbol
366
-
367
- if value
368
- rhSet(@yRuntime, value, key)
369
- else
370
- @yRuntime.delete(key)
371
- end
372
- true
373
- end
374
-
375
- def []=(key, value)
376
- set(key, value)
377
- end
378
-
379
- def runtimeExist?(key)
380
- (rhExist?(@yRuntime, key) == 1)
381
- end
382
-
383
- def runtimeGet(key)
384
- rhGet(@yRuntime, key) if runtimeExist?(key)
385
- end
386
-
387
- def get(key, default = nil)
388
- key = key.to_sym if key.class == String
389
- return nil if key.class != Symbol
390
- # If key is in runtime
391
- return runtimeGet(key) if runtimeExist?(key)
392
- #~ # Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
393
- #~ if interms
394
- #~ if interms.instance_of? Hash
395
- #~ return rhGet(interms, key) if rhExist?(interms, key) == 1
396
- #~ elsif interms.instance_of? Array # Array of hashes
397
- #~ iCount=0
398
- #~ oVal = nil
399
- #~ interms.each { | elem |
400
- #~ if elem.class == Hash
401
- #~ elem.each { | hashkey, value |
402
- #~ if value.class == Hash and rhExist?(elem, hashkey, key) == 2 # hash of hash
403
- #~ oVal = rhGet(elem, hashkey, key)
404
- #~ break
405
- #~ elsif value.class != Hash and rhExist?(elem, hashkey) == 1 # single hash: key = value.
406
- #~ oVal = rhGet(elem, hashkey)
407
- #~ break
408
- #~
409
- #~ end
410
- #~ }
411
- #~ break if oVal
412
- #~ end
413
- #~ iCount += 1
414
- #~ }
415
- #~ return oVal
416
- #~ end
417
- #~ end
418
- # else key in local default config of default section.
419
- return LocalGet(key) if LocalDefaultExist?(key)
420
- # else key in application defaults
421
- return ForjDefault.get(key) if ForjDefault.exist?(key)
422
- # else default
423
- default
424
- end
425
-
426
- def [](key, default = nil)
427
- get(key, default)
428
- end
429
-
430
- def getAppDefault(section, key = nil)
431
-
432
- key = key.to_sym if key.class == String
433
-
434
- ForjDefault.get(key, section)
435
- end
436
-
437
- def exist?(key, interms = nil)
438
- key = key.to_sym if key.class == String
439
-
440
- # Check data in intermediate hashes or array of hash. (like account data - key have to be identical)
441
- return "runtime" if rhExist?(@yRuntime, key) == 1
442
- if interms
443
- if interms.instance_of? Hash
444
- return 'hash' if rhExist?(interms, key) == 1
445
- elsif interms.instance_of? Array # Array of hash
446
- iCount = 0
447
- interms.each { | elem |
448
- if elem.class == Hash
449
- elem.each { | hashkey, value |
450
- return ("%s" % hashkey) if value.class == Hash and rhExist?(elem, hashkey, key) == 2
451
- return ("hash[%s]" % iCount) if value.class != Hash and rhExist?(elem, hashkey) == 1
452
- }
453
- end
454
- iCount += 1
455
- }
456
- end
457
- end
458
- return 'local' if LocalDefaultExist?(key)
459
- # else key in application defaults
460
- return 'default' if ForjDefault.exist?(key)
461
- false
462
- end
463
-
464
- def LocalDefaultExist?(key)
465
- LocalExist?(key)
466
- end
467
-
468
- def LocalExist?(key, section = :default)
469
-
470
- key = key.to_sym if key.class == String
471
- return true if rhExist?(@yLocal, section, key) == 2
472
- false
473
- end
474
-
475
- def LocalSet(key, value, section = :default)
476
- key = key.to_sym if key.class == String
477
- if not key or not value
478
- return false
479
- end
480
- if @yLocal[section] == nil
481
- @yLocal[section]={}
482
- end
483
- if @yLocal.has_key?(section)
484
- @yLocal[section].merge!({key => value})
485
- else
486
- @yLocal.merge!(section => {key => value})
487
- end
488
- return true
489
- end
490
-
491
- def LocalGet(key, section = :default, default = nil)
492
- key = key.to_sym if key.class == String
493
-
494
- return default if rhExist?(@yLocal, section, key) != 2
495
- rhGet(@yLocal, section, key)
496
- end
497
-
498
- def LocalDel(key, section = :default)
499
- key = key.to_sym if key.class == String
500
- if not key
501
- return false
502
- end
503
- if not @yLocal.has_key?(section)
504
- return false
505
- end
506
- @yLocal[section].delete(key)
507
- return true
508
- end
509
-
510
- # Function to return in fatal error if a config data is nil. Help to control function requirement.
511
- def fatal_if_inexistent(key)
512
- Logging.fatal(1, "Internal error - %s: '%s' is missing" % [caller(), key]) if not self.get(key)
513
- end
514
-
515
- def meta_each
516
- ForjDefault.meta_each { |section, key, value|
517
- next if rhGet(value, :account_exclusive)
518
- yield section, key, value
519
- }
520
- end
521
-
522
- end