lorj 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63d7eabf0a0bfe1c20a49ea78ad77a37b6b5e521
4
- data.tar.gz: 5170b2123e123a05028cd52cad7af4d1288acc09
3
+ metadata.gz: 36d83ea9cfd8bf5813827bf81787e5d4be58571c
4
+ data.tar.gz: f78ae355e208f298649ea3cd523fb163553948a7
5
5
  SHA512:
6
- metadata.gz: 88a9a2866f706cf5183caf65cce95bbeffec6073fc47b2457c233a28bc73d4fe175aade0ae4410e42eb050ac52f5ea1da782c2e1a1404f0a673c575acb2e959e
7
- data.tar.gz: 96ec48620a59cc39ea1307fcea13e04eeb2a703d1466338cf18b74ecfac225caabe85e0ef2c1a61b4359fa1f0621bf46b2589c260ec3d2f54da277391806ea7c
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
@@ -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 = options[:default_value] if default.nil?
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]
@@ -64,7 +64,7 @@ module Lorj
64
64
  #
65
65
  def _setup_check_additional(setup_steps)
66
66
  setup_steps.each_index do |step|
67
- value = setup_steps[step]
67
+ value = Lorj.data.setup_data(:ask_step)[step]
68
68
  next unless value.rh_exist?(:add)
69
69
 
70
70
  datas_to_add = value.rh_get(:add)
@@ -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 => nil }
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 => nil }
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
- match_res = value.match(/lorj::config\[(.*)\]/)
99
- if match_res
100
- extract = match_res[1].split(', ')
101
- extract.map! { |v| v[1..-1].to_sym if v[0] == ':' }
102
- params << { key => config[extract] }
103
- else
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
- PrcLib.debug(2, "Running process '#{proc}' on '#{obj_to_load}'.")
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
@@ -16,5 +16,5 @@
16
16
 
17
17
  # Lorj version
18
18
  module Lorj
19
- VERSION = '1.0.4'
19
+ VERSION = '1.0.5'
20
20
  end
@@ -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: regionOne)'
142
+ :desc => 'Openstack Compute Region (Ex: RegionOne)'
139
143
  )
140
144
 
141
145
  define_data(:network,
142
146
  :account => true,
143
- :desc => 'Openstack Network Region (Ex: regionOne)',
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - forj team