lorj 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -3
- data/lib/core/core.rb +9 -10
- data/lib/core/definition.rb +9 -2
- data/lib/core/lorj-basedefinition.rb +69 -9
- data/lib/core/lorj-baseprocess.rb +6 -1
- data/lib/core_process/CloudProcess.rb +9 -6
- data/lib/core_process/global_process.rb +184 -88
- data/lib/core_process/network_process.rb +96 -94
- data/lib/lorj/version.rb +1 -1
- data/lib/lorj.rb +2 -5
- data/lib/prc-config.rb +12 -5
- data/lib/prc-logging.rb +80 -2
- data/lib/prc.rb +23 -0
- data/lib/providers/hpcloud/Hpcloud.rb +28 -21
- data/lib/providers/hpcloud/compute.rb +5 -0
- data/lorj.gemspec +29 -26
- metadata +36 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ea57c85015a879c6ae4a17ae32cc568d7c1559
|
4
|
+
data.tar.gz: 88617061e04fc13f17454c770dc41ad87a19c2b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d8214f417ae51f763015aa0836d30365ca34b3313c0bafd002cbae137e8a75478261aeb80d9d2d6ccc3575dfc13483501a5fb80aefb11e4ec6d1da2369958d3
|
7
|
+
data.tar.gz: 4262c71516afea78b39dc03482e972d4465347bec1062d9198648c0dfd7c934b3957c48f46c2b61bcac2e68477433efc9359737143f8b0dfd92962b8a3b1cf67
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lorj (0.
|
4
|
+
lorj (0.2.0)
|
5
5
|
ansi (>= 1.4.3)
|
6
|
-
|
6
|
+
encryptor (= 1.3.0)
|
7
|
+
highline (~> 1.6.21)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
12
|
ansi (1.4.3)
|
12
13
|
diff-lcs (1.2.5)
|
14
|
+
encryptor (1.3.0)
|
15
|
+
highline (1.6.21)
|
13
16
|
rake (10.4.2)
|
14
17
|
rspec (3.1.0)
|
15
18
|
rspec-core (~> 3.1.0)
|
@@ -28,7 +31,7 @@ PLATFORMS
|
|
28
31
|
ruby
|
29
32
|
|
30
33
|
DEPENDENCIES
|
31
|
-
bundler
|
34
|
+
bundler
|
32
35
|
lorj!
|
33
36
|
rake (~> 10.0)
|
34
37
|
rspec (~> 3.1.0)
|
data/lib/core/core.rb
CHANGED
@@ -142,8 +142,6 @@ module Lorj
|
|
142
142
|
# Loading ProcessClass
|
143
143
|
# Create Process derived from respectively BaseProcess
|
144
144
|
|
145
|
-
# TODO: Replace Global variables by equivalent to PrcLib.<var>
|
146
|
-
|
147
145
|
PrcLib.core_level = 0 if PrcLib.core_level.nil?
|
148
146
|
|
149
147
|
if oForjConfig.nil?
|
@@ -172,8 +170,9 @@ module Lorj
|
|
172
170
|
# And load the content from the <sProcessClass>.rb
|
173
171
|
if sProcessClass.is_a?(Symbol)
|
174
172
|
# Ensure file and processName is capitalized
|
175
|
-
sProcessClass = sProcessClass.to_s
|
176
|
-
|
173
|
+
sProcessClass = sProcessClass.to_s
|
174
|
+
sProcessClass = sProcessClass.capitalize if (/[A-Z]/ =~ sProcessClass.to_s) != 0
|
175
|
+
sFile = File.join(PrcLib.process_path, sProcessClass + '.rb')
|
177
176
|
else
|
178
177
|
if sProcessClass.include?('/')
|
179
178
|
# Consider a path to the process file. File name is the name of the class.
|
@@ -191,7 +190,7 @@ module Lorj
|
|
191
190
|
}
|
192
191
|
end
|
193
192
|
else
|
194
|
-
sPath =
|
193
|
+
sPath = PrcLib.process_path
|
195
194
|
sProcessClass = sProcessClass.capitalize if (/[A-Z]/ =~ sProcessClass) != 0
|
196
195
|
sFile = sProcessClass + '.rb'
|
197
196
|
end
|
@@ -215,7 +214,7 @@ module Lorj
|
|
215
214
|
Lorj.debug(1, "Loading Controller/definition '%s'" % sControllerClass)
|
216
215
|
# Add Provider Object -------------
|
217
216
|
if sControllerClass.is_a?(Symbol)
|
218
|
-
sPath = File.join(
|
217
|
+
sPath = File.join(PrcLib.controller_path, sControllerClass.to_s)
|
219
218
|
sControllerClass = sControllerClass.to_s.capitalize if (/[A-Z]/ =~ sControllerClass.to_s) != 0
|
220
219
|
sFile = sControllerClass.to_s + '.rb'
|
221
220
|
else
|
@@ -235,7 +234,7 @@ module Lorj
|
|
235
234
|
}
|
236
235
|
end
|
237
236
|
else
|
238
|
-
sPath = File.join(
|
237
|
+
sPath = File.join(PrcLib.controller_path, sControllerClass)
|
239
238
|
sControllerClass = sControllerClass.capitalize if (/[A-Z]/ =~ sControllerClass) != 0
|
240
239
|
sFile = sControllerClass + '.rb'
|
241
240
|
end
|
@@ -487,7 +486,7 @@ module Lorj
|
|
487
486
|
class CloudCore < Core
|
488
487
|
def initialize(oConfig, sAccount = nil, aProcesses = [])
|
489
488
|
|
490
|
-
unless oConfig.is_a?(
|
489
|
+
unless oConfig.is_a?(Lorj::Account)
|
491
490
|
oForjAccount = Lorj::Account.new(oConfig)
|
492
491
|
unless sAccount.nil?
|
493
492
|
oForjAccount.ac_load(sAccount)
|
@@ -500,7 +499,7 @@ module Lorj
|
|
500
499
|
sControllerMod = oForjAccount.get(:provider_name)
|
501
500
|
raise Lorj::PrcError.new(), "Provider_name not set. Unable to create instance CloudCore." if sControllerMod.nil?
|
502
501
|
|
503
|
-
sControllerProcessMod = File.join(
|
502
|
+
sControllerProcessMod = File.join(PrcLib.controller_path, sControllerMod, sControllerMod.capitalize + "Process.rb")
|
504
503
|
if File.exist?(sControllerProcessMod)
|
505
504
|
aProcessList << sControllerProcessMod
|
506
505
|
else
|
@@ -662,7 +661,7 @@ module Lorj
|
|
662
661
|
# * *Raises* :
|
663
662
|
# nothing
|
664
663
|
def << (hHash)
|
665
|
-
@hParams.merge!(hHash)
|
664
|
+
@hParams.merge!(hHash) unless hHash.nil?
|
666
665
|
end
|
667
666
|
|
668
667
|
# check Lorj::Data attributes or object exists. Or check key/value pair existence.
|
data/lib/core/definition.rb
CHANGED
@@ -67,6 +67,8 @@ module Lorj
|
|
67
67
|
# => Data name. This symbol must be unique, across sections.
|
68
68
|
# :desc: Required. String. default: nil
|
69
69
|
# => Description
|
70
|
+
# :explanation: |- Print a multiline explanation before ask the key value.
|
71
|
+
# ERB template enable. To get config data, type <%= config[...] %>
|
70
72
|
# :readonly: Optional. true/false. Default: false
|
71
73
|
# => oForjConfig.set() will fail if readonly is true.
|
72
74
|
# Can be set, only thanks to oForjConfig.setup()
|
@@ -105,8 +107,9 @@ module Lorj
|
|
105
107
|
#
|
106
108
|
# :setup: This section describes group of fields to ask, step by step.
|
107
109
|
# :ask_step: Define an Array of setup steps to ask to the end user. The step order is respected, and start at 0
|
108
|
-
# - :desc: Define the step description
|
110
|
+
# - :desc: Define the step description. ERB template enable. To get config data, type config[...]
|
109
111
|
# :explanation: |- Define a multiline explanation. This is printed out in brown color.
|
112
|
+
# ERB template enable. To get config data, type <%= config[...] %>
|
110
113
|
# :add: Define a list of additionnal fields to ask.
|
111
114
|
# - <Data> Data to ask.
|
112
115
|
#
|
@@ -500,6 +503,10 @@ module Lorj
|
|
500
503
|
Lorj::rhSet(@@predefine_data_value, value, oKeyPath.sFullPath, :values)
|
501
504
|
end
|
502
505
|
|
503
|
-
|
506
|
+
# function to interpret a template data, and use ERBConfig as data context.
|
507
|
+
# ERBConfig contains config object only.
|
508
|
+
def erb(str)
|
509
|
+
ERB.new(str).result(@oERBConfig.get_binding())
|
510
|
+
end
|
504
511
|
end
|
505
512
|
end
|
@@ -22,7 +22,24 @@
|
|
22
22
|
# - definition(BaseDefinition): Functions to declare objects, query/data mapping and setup
|
23
23
|
# this task to make it to work.
|
24
24
|
|
25
|
+
require 'highline/import'
|
26
|
+
require 'erb'
|
27
|
+
|
25
28
|
module Lorj
|
29
|
+
# This class limits ERC template to access only to config object data.
|
30
|
+
class ERBConfig
|
31
|
+
attr_reader :config
|
32
|
+
|
33
|
+
def initialize(config)
|
34
|
+
@config = config
|
35
|
+
end
|
36
|
+
|
37
|
+
# Bind this limited class with ERB templates
|
38
|
+
def get_binding()
|
39
|
+
binding()
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
26
43
|
# Following class defines class levels function to
|
27
44
|
# declare framework objects.
|
28
45
|
# As each process needs to define new object to deal with
|
@@ -229,7 +246,7 @@ module Lorj
|
|
229
246
|
|
230
247
|
return nil if not sCloudObj
|
231
248
|
|
232
|
-
raise Lorj::PrcError.new(), "
|
249
|
+
raise Lorj::PrcError.new(), "%s.Get: '%s' is not a known object type." % [self.class, sCloudObj] if Lorj::rhExist?(@@meta_obj, sCloudObj) != 1
|
233
250
|
|
234
251
|
if hConfig.length > 0
|
235
252
|
# cleanup runtime data to avoid conflicts between multiple calls
|
@@ -585,7 +602,11 @@ module Lorj
|
|
585
602
|
aSetup.each_index { | iStep |
|
586
603
|
Lorj.debug(2, "Ask step %s:" % iStep)
|
587
604
|
puts "%s%s%s" % [ANSI.bold, aSetup[iStep][:desc], ANSI.clear] unless aSetup[iStep][:desc].nil?
|
588
|
-
|
605
|
+
begin
|
606
|
+
puts "%s\n\n" % ANSI.yellow(erb(aSetup[iStep][:explanation])) unless aSetup[iStep][:explanation].nil?
|
607
|
+
rescue => e
|
608
|
+
PrcLib.Error "setup step '%d/:explanation' : %s" % [iStep, e.message]
|
609
|
+
end
|
589
610
|
aOrder = aSetup[iStep][:order]
|
590
611
|
aOrder.each_index { | iIndex |
|
591
612
|
Lorj.debug(2, "Ask order %s:" % iIndex)
|
@@ -602,8 +623,16 @@ module Lorj
|
|
602
623
|
|
603
624
|
|
604
625
|
sDesc = "'%s' value" % sKey
|
605
|
-
|
606
|
-
|
626
|
+
begin
|
627
|
+
puts "#{sKey}: %s" % [erb(hParam[:explanation])] unless hParam[:explanation].nil?
|
628
|
+
rescue => e
|
629
|
+
PrcLib.Error "setup key '%s/:explanation' : %s" % [sKey, e.message]
|
630
|
+
end
|
631
|
+
begin
|
632
|
+
sDesc = erb(hParam[:desc]) unless hParam[:desc].nil?
|
633
|
+
rescue => e
|
634
|
+
PrcLib.Error "setup key '%s/:desc' : %s" % [sKey, e.message]
|
635
|
+
end
|
607
636
|
sDefault = @oForjConfig.get(sKey, hParam[:default_value])
|
608
637
|
rValidate = nil
|
609
638
|
|
@@ -647,14 +676,40 @@ module Lorj
|
|
647
676
|
raise Lorj::PrcError.new(), "#{sKey}: query_type => :process_call requires missing :query_call declaration (Provider function)" if hValues[:query_call].nil?
|
648
677
|
pProc = hValues[:query_call]
|
649
678
|
sObjectToLoad = hValues[:object]
|
679
|
+
|
680
|
+
# Building Process function hParams parameter
|
650
681
|
oParams = ObjectData.new
|
651
|
-
oParams
|
652
|
-
|
682
|
+
oParams << { default_value: sDefault }
|
683
|
+
|
684
|
+
unless hValues[:query_params].nil?
|
685
|
+
hValues[:query_params].each { | key, value |
|
686
|
+
if mRes = value.match(/lorj::config\[(.*)\]/)
|
687
|
+
aExtract = mRes[1].split(', ')
|
688
|
+
aExtract.map! { | v | v = v[1..-1].to_sym if v[0] == ':' }
|
689
|
+
oParams << { key => config[aExtract] }
|
690
|
+
else
|
691
|
+
oParams << { key => value }
|
692
|
+
end
|
693
|
+
}
|
694
|
+
end
|
695
|
+
|
653
696
|
begin
|
654
|
-
|
697
|
+
hProcResult = @oForjProcess.method(pProc).call(sObjectToLoad, oParams)
|
655
698
|
rescue => e
|
656
699
|
raise Lorj::PrcError.new(), "Error during call of '%s':\n%s" % [pProc, e.message]
|
657
700
|
end
|
701
|
+
|
702
|
+
if hProcResult.is_a?(Hash)
|
703
|
+
sDefault = hProcResult[:default_value].nil? ? sDefault : hProcResult[:default_value]
|
704
|
+
if hProcResult[:list].nil? or ! hProcResult[:list].is_a?(Array)
|
705
|
+
PrcLib.debug("Process function '%s' did not return an :list => Array of values." % [ hValues[:query_call] ])
|
706
|
+
else
|
707
|
+
aList = hProcResult[:list]
|
708
|
+
end
|
709
|
+
else
|
710
|
+
PrcLib.debug("Process function '%s' did not return an Hash with :list and :default_value")
|
711
|
+
aList = []
|
712
|
+
end
|
658
713
|
else
|
659
714
|
raise Lorj::PrcError.new, "'%s' invalid. %s/list_values/values_type supports %s. " % [hValues[:values_type], sKey, [:provider_function]]
|
660
715
|
end
|
@@ -699,7 +754,12 @@ module Lorj
|
|
699
754
|
@oForjConfig.set(sKey, value)
|
700
755
|
if hParam[:post_step_function]
|
701
756
|
pProc = hParam[:post_step_function]
|
702
|
-
|
757
|
+
bResult = @oForjProcess.method(pProc).call()
|
758
|
+
if bResult.boolean?
|
759
|
+
bOk = bResult
|
760
|
+
else
|
761
|
+
PrcLib.debug("Warning: '%s' did not return any boolean value. Ignored" % [pProc])
|
762
|
+
end
|
703
763
|
end
|
704
764
|
end
|
705
765
|
}
|
@@ -719,6 +779,7 @@ module Lorj
|
|
719
779
|
}
|
720
780
|
|
721
781
|
@oForjConfig = oForjConfig
|
782
|
+
@oERBConfig = ERBConfig.new(oForjConfig)
|
722
783
|
raise Lorj::PrcError.new(), "'%s' is not a valid ForjAccount or ForjConfig Object." % [oForjConfig.class] if not oForjConfig.is_a?(Lorj::Account) and not oForjConfig.is_a?(Lorj::Config)
|
723
784
|
|
724
785
|
@oProvider = oForjProvider
|
@@ -1014,7 +1075,6 @@ module Lorj
|
|
1014
1075
|
bDone
|
1015
1076
|
end
|
1016
1077
|
|
1017
|
-
|
1018
1078
|
private
|
1019
1079
|
|
1020
1080
|
# -------------------------------------------------------------------------
|
@@ -35,6 +35,11 @@ module Lorj
|
|
35
35
|
@oDefinition = oDefinition
|
36
36
|
end
|
37
37
|
|
38
|
+
def controller_connect(sObjectType, hParams = {})
|
39
|
+
raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
|
40
|
+
@oDefinition.connect(sObjectType)
|
41
|
+
end
|
42
|
+
|
38
43
|
def controller_create(sObjectType, hParams = {})
|
39
44
|
raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
|
40
45
|
@oDefinition.create(sObjectType)
|
@@ -146,7 +151,7 @@ module Lorj
|
|
146
151
|
end
|
147
152
|
|
148
153
|
def query_single(sCloudObj, oList, sQuery, name, sInfoMsg = {})
|
149
|
-
oList =
|
154
|
+
oList = controller_query(sCloudObj, sQuery)
|
150
155
|
sInfo = {
|
151
156
|
:notfound => "No %s '%s' found",
|
152
157
|
:checkmatch => "Found 1 %s. checking exact match for '%s'.",
|
@@ -17,11 +17,11 @@
|
|
17
17
|
|
18
18
|
# It requires Core objects to be defined + default ForjProcess functions.
|
19
19
|
|
20
|
-
require File.join(
|
21
|
-
require File.join(
|
20
|
+
require File.join(PrcLib.process_path, "global_process.rb")
|
21
|
+
require File.join(PrcLib.process_path, "network_process.rb")
|
22
22
|
|
23
23
|
# Define framework object on BaseDefinition
|
24
|
-
class BaseDefinition
|
24
|
+
class Lorj::BaseDefinition
|
25
25
|
|
26
26
|
# All objects used by this process are built from a Controller
|
27
27
|
process_default :use_controller => true
|
@@ -197,7 +197,8 @@ class BaseDefinition
|
|
197
197
|
define_obj(:keypairs,
|
198
198
|
{
|
199
199
|
:create_e => :forj_get_or_create_keypair,
|
200
|
-
:query_e => :forj_query_keypair
|
200
|
+
:query_e => :forj_query_keypair,
|
201
|
+
:get_e => :forj_get_keypair
|
201
202
|
# :delete_e => :forj_delete_keypair
|
202
203
|
})
|
203
204
|
|
@@ -267,9 +268,9 @@ class BaseDefinition
|
|
267
268
|
{
|
268
269
|
:create_e => :forj_get_or_create_server,
|
269
270
|
:query_e => :forj_query_server,
|
270
|
-
:get_e => :forj_get_server
|
271
|
+
:get_e => :forj_get_server,
|
271
272
|
# :update_e => :forj_update_server,
|
272
|
-
|
273
|
+
:delete_e => :forj_delete_server
|
273
274
|
})
|
274
275
|
|
275
276
|
obj_needs :CloudObject, :compute_connection
|
@@ -291,6 +292,8 @@ class BaseDefinition
|
|
291
292
|
def_attribute :private_ip_address
|
292
293
|
def_attribute :public_ip_address
|
293
294
|
|
295
|
+
def_attribute :image_id
|
296
|
+
def_attribute :key_name
|
294
297
|
# ************************************ SERVER Addresses Object
|
295
298
|
# Object representing the list of IP addresses attached to a server.
|
296
299
|
define_obj(:public_ip,
|