lorj 1.0.4 → 1.0.5
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/lib/core/core_process_setup.rb +4 -0
- data/lib/core/core_setup_ask.rb +34 -6
- data/lib/core/core_setup_init.rb +1 -1
- data/lib/core/core_setup_list.rb +14 -13
- data/lib/lorj/version.rb +1 -1
- data/lib/providers/openstack/openstack.rb +12 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36d83ea9cfd8bf5813827bf81787e5d4be58571c
|
4
|
+
data.tar.gz: f78ae355e208f298649ea3cd523fb163553948a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e84cd61cdb98437b233c724c56df7dd6bf1b388e6e9e521defc20c6295346c221d75388eeaf3af1963a830736aea13e762bcca313094a860472248f897eddd7c
|
7
|
+
data.tar.gz: 5a4f65aab04941d2107f20ba7f7f0152104f4977ef3203c8418c5ef45e1448d0c1bf4038ca4de7a74bdab3556323176b2349f9f5c10a42d4163e4dc64bb21d38
|
@@ -231,11 +231,15 @@ module Lorj
|
|
231
231
|
# * *Args* :
|
232
232
|
# - +order_array+ : Array of data classified per level/order
|
233
233
|
# - +data_to_check+ : data to check
|
234
|
+
#
|
235
|
+
# * *returns* :
|
236
|
+
# - true if found. false otherwise.
|
234
237
|
def _setup_attr_already_added?(order_array, data_to_check)
|
235
238
|
order_array.each_index do |order_index|
|
236
239
|
attributes = order_array[order_index]
|
237
240
|
return true unless attributes.index(data_to_check).nil?
|
238
241
|
end
|
242
|
+
false
|
239
243
|
end
|
240
244
|
|
241
245
|
# Add the attribute parameter to setup list
|
data/lib/core/core_setup_ask.rb
CHANGED
@@ -96,15 +96,19 @@ module Lorj
|
|
96
96
|
#
|
97
97
|
# * *Raises* :
|
98
98
|
#
|
99
|
-
def _setup_choose_list_process(obj_to_load, list_options
|
99
|
+
def _setup_choose_list_process(obj_to_load, list_options,
|
100
|
+
default_value = nil)
|
100
101
|
result = { :list => [], :default_value => nil }
|
101
102
|
case list_options[:query_type]
|
102
103
|
when :controller_call
|
103
|
-
result = _setup_list_from_controller_call(obj_to_load, list_options
|
104
|
+
result = _setup_list_from_controller_call(obj_to_load, list_options,
|
105
|
+
default_value)
|
104
106
|
when :query_call
|
105
|
-
result = _setup_list_from_query_call(obj_to_load, list_options
|
107
|
+
result = _setup_list_from_query_call(obj_to_load, list_options,
|
108
|
+
default_value)
|
106
109
|
when :process_call
|
107
|
-
result = _setup_list_from_process_call(obj_to_load, list_options
|
110
|
+
result = _setup_list_from_process_call(obj_to_load, list_options,
|
111
|
+
default_value)
|
108
112
|
else
|
109
113
|
PrcLib.runtime_fail "%s: '%s' invalid query type. valid is: '%s'.",
|
110
114
|
obj_to_load, list_options[:values_type],
|
@@ -130,7 +134,8 @@ module Lorj
|
|
130
134
|
def _setup_ask_data_from_list(data, list_options, desc, options)
|
131
135
|
obj_to_load = list_options[:object]
|
132
136
|
|
133
|
-
result = _setup_choose_list_process(obj_to_load, list_options
|
137
|
+
result = _setup_choose_list_process(obj_to_load, list_options,
|
138
|
+
options[:default_value])
|
134
139
|
|
135
140
|
list = result[:list]
|
136
141
|
|
@@ -191,6 +196,22 @@ module Lorj
|
|
191
196
|
# - +options+: list and validation options
|
192
197
|
# - :ask_function: Replace the _ask default call by a process function
|
193
198
|
# This function should return a string or nil, if no value.
|
199
|
+
# - +default+: Default value.
|
200
|
+
#
|
201
|
+
# setup will present a default value. This value can come from several
|
202
|
+
# places, as follow in that order:
|
203
|
+
# 1. if a value is found from config layers => choose it as default
|
204
|
+
# 2. if default parameter is not nil => choose it as default
|
205
|
+
# 3. if data model defines :default_value. => choose it
|
206
|
+
# In this last case, the :default_value is interpreted by ERB.
|
207
|
+
# ERB context contains:
|
208
|
+
# - config : data config layer.
|
209
|
+
#
|
210
|
+
# Ex: So you can set :default_value like:
|
211
|
+
#
|
212
|
+
# :default_value: "~/.ssh/<%= config[:keypair_name] %>-id_rsa"
|
213
|
+
# This may assume that keypair_name is setup before abd would need:
|
214
|
+
# - :after: <datas>
|
194
215
|
#
|
195
216
|
# * *Returns*:
|
196
217
|
# - value : value entered by the end user or nil if no value.
|
@@ -204,7 +225,14 @@ module Lorj
|
|
204
225
|
is_required = (options[:required] == true)
|
205
226
|
is_encrypted = options[:encrypted]
|
206
227
|
|
207
|
-
default
|
228
|
+
if default.nil? && !options[:default_value].nil?
|
229
|
+
begin
|
230
|
+
default = erb(options[:default_value])
|
231
|
+
rescue => e
|
232
|
+
PrcLib.warning("ERB error with :%s/:default_value '%s'.\n%s",
|
233
|
+
data, options[:default_value], e.message)
|
234
|
+
end
|
235
|
+
end
|
208
236
|
default = @config.get(data, default)
|
209
237
|
|
210
238
|
# validate_proc = options[:validate_function]
|
data/lib/core/core_setup_init.rb
CHANGED
data/lib/core/core_setup_list.rb
CHANGED
@@ -39,7 +39,7 @@ module Lorj
|
|
39
39
|
#
|
40
40
|
# * *Raises* :
|
41
41
|
#
|
42
|
-
def _setup_list_from_controller_call(obj_to_load, list_options)
|
42
|
+
def _setup_list_from_controller_call(obj_to_load, list_options, default)
|
43
43
|
PrcLib.message("Loading #{obj_to_load}.")
|
44
44
|
|
45
45
|
object = @object_data[obj_to_load, :ObjectData]
|
@@ -61,7 +61,7 @@ module Lorj
|
|
61
61
|
rescue => e
|
62
62
|
PrcLib.runtime_fail "Error during call of '%s':\n%s", proc, e.message
|
63
63
|
end
|
64
|
-
{ :list => list, :default_value =>
|
64
|
+
{ :list => list, :default_value => default }
|
65
65
|
end
|
66
66
|
|
67
67
|
# Internal setup function to build the list from a query call.
|
@@ -77,7 +77,7 @@ module Lorj
|
|
77
77
|
#
|
78
78
|
# * *Raises* :
|
79
79
|
#
|
80
|
-
def _setup_list_from_query_call(obj_to_load, list_options)
|
80
|
+
def _setup_list_from_query_call(obj_to_load, list_options, default)
|
81
81
|
PrcLib.message("Querying #{obj_to_load}.")
|
82
82
|
|
83
83
|
query_hash = list_options[:query_params]
|
@@ -88,21 +88,21 @@ module Lorj
|
|
88
88
|
list = []
|
89
89
|
object_list.each { |oElem| list << oElem[list_options[:value]] }
|
90
90
|
|
91
|
-
{ :list => list.sort!, :default_value =>
|
91
|
+
{ :list => list.sort!, :default_value => default }
|
92
92
|
end
|
93
93
|
|
94
94
|
def _setup_build_process_params(option_params, params)
|
95
95
|
return if option_params.nil?
|
96
96
|
|
97
97
|
option_params.each do |key, value|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
params << { key => value }
|
98
|
+
next if value.nil?
|
99
|
+
begin
|
100
|
+
value = erb(value)
|
101
|
+
rescue => e
|
102
|
+
Prclib.warning("ERB:process parameter failed to set '%s' with '%s'."\
|
103
|
+
"\n%s", key, value, e.message)
|
105
104
|
end
|
105
|
+
params << { key => value }
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -119,17 +119,18 @@ module Lorj
|
|
119
119
|
#
|
120
120
|
# * *Raises* :
|
121
121
|
#
|
122
|
-
def _setup_list_from_process_call(obj_to_load, list_options)
|
122
|
+
def _setup_list_from_process_call(obj_to_load, list_options, default)
|
123
123
|
PrcLib.runtime_fail '%s: query_type => :process_call'\
|
124
124
|
' requires missing :query_call declaration'\
|
125
125
|
' (Provider function)',
|
126
126
|
data if list_options[:query_call].nil?
|
127
127
|
proc = list_options[:query_call]
|
128
128
|
obj_to_load = list_options[:object]
|
129
|
-
|
129
|
+
Lorj.debug(2, "Running process '#{proc}' on '#{obj_to_load}'.")
|
130
130
|
|
131
131
|
# Building Process function attr_params parameter
|
132
132
|
params = ObjectData.new
|
133
|
+
|
133
134
|
params << { :default_value => default }
|
134
135
|
|
135
136
|
_setup_build_process_params(list_options[:query_params], params)
|
data/lib/lorj/version.rb
CHANGED
@@ -131,19 +131,27 @@ class Openstack
|
|
131
131
|
|
132
132
|
define_data(:compute,
|
133
133
|
:account => true,
|
134
|
+
:default_value => '<%= config[:network] %>',
|
134
135
|
:explanation => 'Depending on your installation, you may need to'\
|
135
|
-
' provide a Region name. This information shown under your '\
|
136
|
+
' provide a Region name. This information is shown under your '\
|
136
137
|
'horizon UI - close right to the project name (top left).'\
|
138
|
+
"\nYou can also get it from Project-Compute-Access & Security-"\
|
139
|
+
'API, then download the Openstack RC file. The Region name is '\
|
140
|
+
'set as OS_REGION_NAME.'\
|
137
141
|
"\nIf there is no region shown, you can ignore it.",
|
138
|
-
:desc => 'Openstack Compute Region (Ex:
|
142
|
+
:desc => 'Openstack Compute Region (Ex: RegionOne)'
|
139
143
|
)
|
140
144
|
|
141
145
|
define_data(:network,
|
142
146
|
:account => true,
|
143
|
-
:
|
147
|
+
:default_value => '<%= config[:compute] %>',
|
148
|
+
:desc => 'Openstack Network Region (Ex: RegionOne)',
|
144
149
|
:explanation => 'Depending on your installation, you may need to'\
|
145
|
-
' provide a Region name. This information shown under your '\
|
150
|
+
' provide a Region name. This information is shown under your '\
|
146
151
|
'horizon UI - close right to the project name (top left).'\
|
152
|
+
"\nYou can also get it from Project-Compute-Access & Security-"\
|
153
|
+
'API, then download the Openstack RC file. The Region name is '\
|
154
|
+
'set as OS_REGION_NAME.'\
|
147
155
|
"\nIf there is no region shown, you can ignore it."
|
148
156
|
)
|
149
157
|
|