lorj 0.2.0 → 1.0.0
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/.gitignore +1 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +15 -15
- data/README.md +22 -17
- data/Rakefile +12 -2
- data/bin/cloud_test.rb +13 -65
- data/example/students_1/process/students.rb +39 -0
- data/example/students_1/students.rb +22 -5
- data/example/students_2/process/students.rb +48 -0
- data/example/students_2/students.rb +39 -16
- data/example/students_3/controller/yaml_students.rb +50 -43
- data/example/students_3/controller/yaml_students_controller.rb +100 -87
- data/example/students_3/process/students.rb +161 -97
- data/example/students_3/students.rb +85 -56
- data/example/yaml_students/students.rb +40 -40
- data/example/yaml_students/yaml_students.rb +103 -90
- data/lib/core/core.rb +356 -696
- data/lib/core/core_controller.rb +227 -0
- data/lib/core/core_internal.rb +339 -0
- data/lib/core/core_model.rb +328 -0
- data/lib/core/core_object_data.rb +330 -0
- data/lib/core/core_object_params.rb +230 -0
- data/lib/core/core_process.rb +391 -0
- data/lib/core/core_process_setup.rb +353 -0
- data/lib/core/core_setup_ask.rb +241 -0
- data/lib/core/core_setup_encrypt.rb +146 -0
- data/lib/core/core_setup_init.rb +229 -0
- data/lib/core/core_setup_list.rb +160 -0
- data/lib/core/definition.rb +647 -469
- data/lib/core/definition_internal.rb +264 -308
- data/lib/core/lorj_basecontroller.rb +95 -0
- data/lib/core/lorj_basedefinition.rb +307 -0
- data/lib/core/lorj_baseprocess.rb +265 -0
- data/lib/core/lorj_data.rb +583 -0
- data/lib/core/lorj_keypath.rb +119 -0
- data/lib/core_process/cloud/process/common.rb +63 -0
- data/lib/core_process/cloud/process/connection.rb +93 -0
- data/lib/core_process/cloud/process/external_network.rb +94 -0
- data/lib/core_process/cloud/process/flavor.rb +99 -0
- data/lib/core_process/cloud/process/images.rb +87 -0
- data/lib/core_process/cloud/process/internet_network.rb +34 -0
- data/lib/core_process/cloud/process/internet_server.rb +30 -0
- data/lib/core_process/cloud/process/keypairs.rb +276 -0
- data/lib/core_process/cloud/process/network.rb +108 -0
- data/lib/core_process/cloud/process/public_ip.rb +100 -0
- data/lib/core_process/cloud/process/router.rb +260 -0
- data/lib/core_process/cloud/process/rules.rb +120 -0
- data/lib/core_process/cloud/process/security_groups.rb +121 -0
- data/lib/core_process/cloud/process/server.rb +127 -0
- data/lib/core_process/cloud/process/server_log.rb +35 -0
- data/lib/core_process/cloud/process/subnetwork.rb +108 -0
- data/lib/core_process/cloud_process.rb +30 -0
- data/lib/logging.rb +298 -0
- data/lib/lorj/version.rb +18 -1
- data/lib/lorj.rb +58 -18
- data/lib/lorj_account.rb +556 -0
- data/lib/lorj_config.rb +468 -0
- data/lib/lorj_defaults.rb +278 -0
- data/lib/prc.rb +136 -104
- data/lib/prc_base_config.rb +285 -0
- data/lib/prc_core_config.rb +878 -0
- data/lib/prc_section_config.rb +57 -0
- data/lib/providers/hpcloud/compute.rb +81 -93
- data/lib/providers/hpcloud/hpcloud.rb +462 -0
- data/lib/providers/hpcloud/network.rb +96 -98
- data/lib/providers/hpcloud/security_groups.rb +41 -40
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +45 -0
- data/lib/providers/templates/compute.rb +21 -23
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +11 -12
- data/lib/rh.rb +339 -0
- data/lorj-spec/defaults.yaml +4 -0
- data/lorj.gemspec +6 -0
- data/spec/00_lorj_log_spec.rb +53 -0
- data/spec/01_hash_rh_spec.rb +243 -0
- data/spec/02_prc_base_config_spec.rb +216 -0
- data/spec/04_prc_core_config_spec.rb +83 -0
- data/spec/11_lorj_config_spec.rb +263 -0
- data/spec/12_lorj_account_spec.rb +181 -0
- metadata +76 -28
- data/Gemfile.lock +0 -37
- data/example/students_1/process/Students.rb +0 -20
- data/example/students_2/process/Students.rb +0 -27
- data/example/students_4/controller/yaml_students.rb +0 -82
- data/example/students_4/controller/yaml_students_controller.rb +0 -141
- data/example/students_4/process/students.rb +0 -112
- data/example/students_4/students.rb +0 -103
- data/lib/core/lorj-basecontroller.rb +0 -90
- data/lib/core/lorj-basedefinition.rb +0 -1139
- data/lib/core/lorj-baseprocess.rb +0 -236
- data/lib/core/lorj-data.rb +0 -567
- data/lib/core/lorj-keypath.rb +0 -115
- data/lib/core_process/CloudProcess.rb +0 -337
- data/lib/core_process/global_process.rb +0 -502
- data/lib/core_process/network_process.rb +0 -605
- data/lib/prc-account.rb +0 -339
- data/lib/prc-config.rb +0 -1030
- data/lib/prc-logging.rb +0 -261
- data/lib/providers/hpcloud/Hpcloud.rb +0 -426
- data/lib/providers/mock/Mock.rb +0 -141
- data/lib/providers/openstack/Openstack.rb +0 -47
- data/lib/providers/templates/core.rb +0 -61
- data/spec/forj-account_spec.rb +0 -75
- data/spec/forj-config_spec.rb +0 -196
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require 'highline/import'
|
|
16
|
+
|
|
17
|
+
# Module Lorj which contains several classes.
|
|
18
|
+
#
|
|
19
|
+
# Those classes describes :
|
|
20
|
+
# - processes (BaseProcess) : How to create/delete/edit/query object.
|
|
21
|
+
# - controler (BaseControler) : If a provider is defined, define how will do
|
|
22
|
+
# object creation/etc...
|
|
23
|
+
# - definition(BaseDefinition): Functions to declare objects, query/data mapping
|
|
24
|
+
# and setup
|
|
25
|
+
# this task to make it to work.
|
|
26
|
+
module Lorj
|
|
27
|
+
# Adding encrypt core functions.
|
|
28
|
+
class BaseDefinition
|
|
29
|
+
# internal runtime function for process call
|
|
30
|
+
# Get encrypted value hidden by *
|
|
31
|
+
#
|
|
32
|
+
# *parameters*:
|
|
33
|
+
# - +sDesc+ : data description
|
|
34
|
+
# - +default+ : encrypted default value
|
|
35
|
+
# - +entropy+ : Entropy Hash
|
|
36
|
+
#
|
|
37
|
+
# *return*:
|
|
38
|
+
# - value : encrypted value.
|
|
39
|
+
#
|
|
40
|
+
# *raise*:
|
|
41
|
+
#
|
|
42
|
+
def _get_encrypt_key
|
|
43
|
+
# Checking key file used to encrypt/decrypt passwords
|
|
44
|
+
key_file = File.join(PrcLib.pdata_path, '.key')
|
|
45
|
+
if !File.exist?(key_file)
|
|
46
|
+
# Need to create a random key.
|
|
47
|
+
random_iv = OpenSSL::Cipher::Cipher.new('aes-256-cbc').random_iv
|
|
48
|
+
entr = {
|
|
49
|
+
:key => rand(36**10).to_s(36),
|
|
50
|
+
:salt => Time.now.to_i.to_s,
|
|
51
|
+
:iv => Base64.strict_encode64(random_iv)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Lorj.debug(2, "Writing '%s' key file", key_file)
|
|
55
|
+
File.open(key_file, 'w') do |out|
|
|
56
|
+
out.write(Base64.encode64(entr.to_yaml))
|
|
57
|
+
end
|
|
58
|
+
else
|
|
59
|
+
Lorj.debug(2, "Loading '%s' key file", key_file)
|
|
60
|
+
encoded_key = IO.read(key_file)
|
|
61
|
+
entr = YAML.load(Base64.decode64(encoded_key))
|
|
62
|
+
end
|
|
63
|
+
entr
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# internal runtime function for process call
|
|
67
|
+
# Get encrypted value hidden by *
|
|
68
|
+
#
|
|
69
|
+
# *parameters*:
|
|
70
|
+
# - +sDesc+ : data description
|
|
71
|
+
# - +default+ : encrypted default value
|
|
72
|
+
# - +entropy+ : Entropy Hash
|
|
73
|
+
#
|
|
74
|
+
# *return*:
|
|
75
|
+
# - value : encrypted value.
|
|
76
|
+
#
|
|
77
|
+
# *raise*:
|
|
78
|
+
#
|
|
79
|
+
def _get_encrypted_value_hidden(sDesc, enc_value, entr)
|
|
80
|
+
return '' if enc_value.nil?
|
|
81
|
+
value_hidden = ''
|
|
82
|
+
begin
|
|
83
|
+
value_hidden = '*' * Encryptor.decrypt(
|
|
84
|
+
:value => Base64.strict_decode64(enc_value),
|
|
85
|
+
:key => entr[:key],
|
|
86
|
+
:iv => Base64.strict_decode64(entr[:iv]),
|
|
87
|
+
:salt => entr[:salt]
|
|
88
|
+
).length
|
|
89
|
+
rescue
|
|
90
|
+
Lorj.error('Unable to decrypt your %s. You will need to re-enter it.',
|
|
91
|
+
sDesc)
|
|
92
|
+
else
|
|
93
|
+
value_hidden = format('[%s]', value_hidden)
|
|
94
|
+
PrcLib.message("'%s' is already set. If you want to keep it,"\
|
|
95
|
+
' just press Enter', sDesc)
|
|
96
|
+
end
|
|
97
|
+
value_hidden
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# internal runtime function for process call
|
|
101
|
+
# Ask encrypted function executed by _ask
|
|
102
|
+
#
|
|
103
|
+
# *parameters*:
|
|
104
|
+
# - +sDesc+ : data description
|
|
105
|
+
# - +default+ : encrypted default value
|
|
106
|
+
#
|
|
107
|
+
# *return*:
|
|
108
|
+
# - value : encrypted value.
|
|
109
|
+
#
|
|
110
|
+
# *raise*:
|
|
111
|
+
#
|
|
112
|
+
def _ask_encrypted(sDesc, default)
|
|
113
|
+
entr = _get_encrypt_key
|
|
114
|
+
|
|
115
|
+
enc_value = default
|
|
116
|
+
|
|
117
|
+
value_hidden = _get_encrypted_value_hidden(sDesc, default, entr)
|
|
118
|
+
|
|
119
|
+
value_free = ''
|
|
120
|
+
while value_free == ''
|
|
121
|
+
# ask for encrypted data.
|
|
122
|
+
value_free = ask(format('Enter %s: [%s]', sDesc, value_hidden)) do |q|
|
|
123
|
+
q.echo = '*'
|
|
124
|
+
end
|
|
125
|
+
if value_free == '' && enc_value
|
|
126
|
+
value_free = Encryptor.decrypt(
|
|
127
|
+
:value => Base64.strict_decode64(enc_value),
|
|
128
|
+
:key => entr[:key],
|
|
129
|
+
:iv => Base64.strict_decode64(entr[:iv]),
|
|
130
|
+
:salt => entr[:salt]
|
|
131
|
+
)
|
|
132
|
+
else
|
|
133
|
+
PrcLib.message('%s cannot be empty.', sDesc) if value_free == ''
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
Base64.strict_encode64(
|
|
137
|
+
Encryptor.encrypt(
|
|
138
|
+
:value => value_free,
|
|
139
|
+
:key => entr[:key],
|
|
140
|
+
:iv => Base64.strict_decode64(entr[:iv]),
|
|
141
|
+
:salt => entr[:salt]
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require 'highline/import'
|
|
16
|
+
require 'erb'
|
|
17
|
+
|
|
18
|
+
# Module Lorj which contains several classes.
|
|
19
|
+
#
|
|
20
|
+
# Those classes describes :
|
|
21
|
+
# - processes (BaseProcess) : How to create/delete/edit/query object.
|
|
22
|
+
# - controler (BaseControler) : If a provider is defined, define how will do
|
|
23
|
+
# object creation/etc...
|
|
24
|
+
# - definition(BaseDefinition): Functions to declare objects, query/data mapping
|
|
25
|
+
# and setup
|
|
26
|
+
# this task to make it to work.
|
|
27
|
+
module Lorj
|
|
28
|
+
# Adding process core functions.
|
|
29
|
+
class BaseDefinition
|
|
30
|
+
# Load /:setup/:ask_step section of the defaults.yaml
|
|
31
|
+
#
|
|
32
|
+
# See lib/core/core_model.rb
|
|
33
|
+
#
|
|
34
|
+
# * *Returns*:
|
|
35
|
+
# - hash : setup data structure.
|
|
36
|
+
#
|
|
37
|
+
# * *Raises* :
|
|
38
|
+
#
|
|
39
|
+
def _setup_load
|
|
40
|
+
ask_steps = Lorj.defaults.get[:setup, :ask_step]
|
|
41
|
+
setup_steps = []
|
|
42
|
+
ask_steps.each do | value |
|
|
43
|
+
setup_steps << {
|
|
44
|
+
:desc => value[:desc],
|
|
45
|
+
:explanation => value[:explanation],
|
|
46
|
+
:pre_step_handler => value[:pre_step_function],
|
|
47
|
+
:order => [[]], # attributes in array of level/order
|
|
48
|
+
:post_step_handler => value[:post_step_function]
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
setup_steps
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# check for any additional data to ask to the user
|
|
55
|
+
# thanks to the /:setup/:ask_step/<steps>/:add option of each steps
|
|
56
|
+
#
|
|
57
|
+
# * *Args* :
|
|
58
|
+
# - setup_steps : Hash. setup data structure to update.
|
|
59
|
+
# It will update setup_steps:/:order 2 dimensions array
|
|
60
|
+
#
|
|
61
|
+
# * *Returns*:
|
|
62
|
+
#
|
|
63
|
+
# * *Raises* :
|
|
64
|
+
#
|
|
65
|
+
def _setup_check_additional(setup_steps)
|
|
66
|
+
setup_steps.each_index do | step |
|
|
67
|
+
value = setup_steps[step]
|
|
68
|
+
next unless value.rh_exist?(:add)
|
|
69
|
+
|
|
70
|
+
datas_to_add = value.rh_get(:add)
|
|
71
|
+
datas_to_add.each do | data_to_add |
|
|
72
|
+
order_array = setup_steps[step][:order]
|
|
73
|
+
next if _setup_attr_already_added?(order_array, data_to_add)
|
|
74
|
+
|
|
75
|
+
_setup_data_insert(setup_steps, data_to_add, step, order_array.length)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Loop on object dependencies to determine the list of attributes to setup.
|
|
81
|
+
#
|
|
82
|
+
#
|
|
83
|
+
# * *Args* :
|
|
84
|
+
# - setup_steps : Hash. setup data structure to update.
|
|
85
|
+
# It will update setup_steps:/:order 2 dimensions array
|
|
86
|
+
#
|
|
87
|
+
# * *Returns*:
|
|
88
|
+
# - Nothing. But setup_steps is updated.
|
|
89
|
+
#
|
|
90
|
+
# * *Raises* :
|
|
91
|
+
#
|
|
92
|
+
def _setup_identify(sObjectType, setup_steps)
|
|
93
|
+
objs_to_inspect = [sObjectType]
|
|
94
|
+
inspected_objects = []
|
|
95
|
+
|
|
96
|
+
while objs_to_inspect.length > 0
|
|
97
|
+
# Identify data to ask
|
|
98
|
+
# A data to ask is a data needs from an object type
|
|
99
|
+
# which is declared in section of defaults.yaml
|
|
100
|
+
# and is declared :account to true (in defaults.yaml or in process
|
|
101
|
+
# declaration - define_data)
|
|
102
|
+
|
|
103
|
+
object_type = objs_to_inspect.pop
|
|
104
|
+
|
|
105
|
+
Lorj.debug(1, "Checking '%s'", object_type)
|
|
106
|
+
attributes = PrcLib.model.meta_obj.rh_get(object_type,
|
|
107
|
+
:params, :keys)
|
|
108
|
+
if attributes.nil?
|
|
109
|
+
Lorj.debug(1, "Warning! Object '%s' has no data/object needs. Check"\
|
|
110
|
+
' the process', object_type)
|
|
111
|
+
next
|
|
112
|
+
end
|
|
113
|
+
attributes.each do |attr_path, attr_params|
|
|
114
|
+
attr_name = KeyPath.new(attr_path).key
|
|
115
|
+
_setup_identify_obj_params(setup_steps,
|
|
116
|
+
inspected_objects, objs_to_inspect,
|
|
117
|
+
attr_name, attr_params)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Internal setup function to identify data to ask
|
|
123
|
+
# Navigate through objects dependencies to determine the need.
|
|
124
|
+
def _setup_identify_obj_params(setup_steps,
|
|
125
|
+
inspected_objects, objs_to_inspect,
|
|
126
|
+
attr_name, attr_params)
|
|
127
|
+
|
|
128
|
+
attr_type = attr_params[:type]
|
|
129
|
+
|
|
130
|
+
case attr_type
|
|
131
|
+
when :data
|
|
132
|
+
return unless _setup_obj_param_is_data(setup_steps,
|
|
133
|
+
inspected_objects, attr_name)
|
|
134
|
+
inspected_objects << attr_name
|
|
135
|
+
return
|
|
136
|
+
when :CloudObject
|
|
137
|
+
return if objs_to_inspect.include?(attr_name) ||
|
|
138
|
+
inspected_objects.include?(attr_name)
|
|
139
|
+
# New object to inspect
|
|
140
|
+
objs_to_inspect << attr_name
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def _setup_display_step(setup_step, step)
|
|
145
|
+
Lorj.debug(2, 'Ask step %s:', step)
|
|
146
|
+
puts ANSI.bold(setup_step[:desc]) unless setup_step[:desc].nil?
|
|
147
|
+
begin
|
|
148
|
+
erb_msg = ANSI.yellow(erb(setup_step[:explanation]))
|
|
149
|
+
rescue => e
|
|
150
|
+
PrcLib.Error "setup step '%d/:explanation' : %s", step, e.message
|
|
151
|
+
end
|
|
152
|
+
puts format("%s\n\n", erb_msg) unless setup_step[:explanation].nil?
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# internal setup function to display step information
|
|
156
|
+
#
|
|
157
|
+
# * *Args* :
|
|
158
|
+
# - +data+ : data name to ask.
|
|
159
|
+
# - +options+ : data options
|
|
160
|
+
#
|
|
161
|
+
# * *Returns*:
|
|
162
|
+
# - +desc+ : Description of the data to ask.
|
|
163
|
+
#
|
|
164
|
+
# * *Raises* :
|
|
165
|
+
#
|
|
166
|
+
def _setup_display_data(data, options)
|
|
167
|
+
desc = format("'%s' value", data)
|
|
168
|
+
|
|
169
|
+
unless options[:explanation].nil?
|
|
170
|
+
begin
|
|
171
|
+
puts format('%s: %s',
|
|
172
|
+
data,
|
|
173
|
+
erb(options[:explanation]))
|
|
174
|
+
rescue => e
|
|
175
|
+
PrcLib.Error "setup key '%s/:explanation' : %s", data, e.message
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
begin
|
|
180
|
+
desc = erb(options[:desc]) unless options[:desc].nil?
|
|
181
|
+
rescue => e
|
|
182
|
+
PrcLib.Error "setup key '%s/:desc' : %s", data, e.message
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
desc
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# internal setup core function which ask user to enter values.
|
|
189
|
+
# looping step by step and presenting sorted data to set.
|
|
190
|
+
#
|
|
191
|
+
# It execute pre-process if defined by:
|
|
192
|
+
# /:section/<section name>/<data>/:pre_step_function
|
|
193
|
+
#
|
|
194
|
+
# If pre-process returns true, end user interaction is canceled.
|
|
195
|
+
#
|
|
196
|
+
# * *Args* :
|
|
197
|
+
# - +setup_steps+ : setup data structure.
|
|
198
|
+
#
|
|
199
|
+
# * *Returns*:
|
|
200
|
+
#
|
|
201
|
+
# * *Raises* :
|
|
202
|
+
#
|
|
203
|
+
def _setup_ask(setup_steps)
|
|
204
|
+
# Ask for user input
|
|
205
|
+
setup_steps.each_index do | iStep |
|
|
206
|
+
_setup_display_step(setup_step, iStep)
|
|
207
|
+
|
|
208
|
+
order_array = setup_steps[iStep][:order]
|
|
209
|
+
|
|
210
|
+
order_array.each_index do | iIndex |
|
|
211
|
+
Lorj.debug(2, 'Ask order %s:', iIndex)
|
|
212
|
+
order_array[iIndex].each do | data |
|
|
213
|
+
options = _get_meta_data(data)
|
|
214
|
+
options = {} if options.nil?
|
|
215
|
+
|
|
216
|
+
data_desc = _setup_display_data(data, options)
|
|
217
|
+
|
|
218
|
+
if options[:pre_step_function]
|
|
219
|
+
proc = options[:pre_step_function]
|
|
220
|
+
next unless @oForjProcess.method(proc).call(data)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
_setup_ask_data(data_desc, data, options)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require 'highline/import'
|
|
16
|
+
|
|
17
|
+
# Module Lorj which contains several classes.
|
|
18
|
+
#
|
|
19
|
+
# Those classes describes :
|
|
20
|
+
# - processes (BaseProcess) : How to create/delete/edit/query object.
|
|
21
|
+
# - controler (BaseControler) : If a provider is defined, define how will do
|
|
22
|
+
# object creation/etc...
|
|
23
|
+
# - definition(BaseDefinition): Functions to declare objects, query/data mapping
|
|
24
|
+
# and setup
|
|
25
|
+
# this task to make it to work.
|
|
26
|
+
module Lorj
|
|
27
|
+
# Adding process core functions.
|
|
28
|
+
class BaseDefinition
|
|
29
|
+
# Internal setup function to build the list from a controller call.
|
|
30
|
+
#
|
|
31
|
+
# * *Args* :
|
|
32
|
+
# - +obj_to_load+ : Object to get list from.
|
|
33
|
+
# - +list_options+: list and validation options
|
|
34
|
+
#
|
|
35
|
+
# * *Returns*:
|
|
36
|
+
# - Hash : list of possible values and default.
|
|
37
|
+
# :default_value : Value pre-selected.
|
|
38
|
+
# :list : list of possible values
|
|
39
|
+
#
|
|
40
|
+
# * *Raises* :
|
|
41
|
+
#
|
|
42
|
+
def _setup_list_from_controller_call(obj_to_load, list_options)
|
|
43
|
+
PrcLib.message("Loading #{obj_to_load}.")
|
|
44
|
+
|
|
45
|
+
object = @object_data[obj_to_load, :ObjectData]
|
|
46
|
+
object = Create(obj_to_load) if object.nil?
|
|
47
|
+
return nil if object.nil?
|
|
48
|
+
|
|
49
|
+
params = ObjectData.new
|
|
50
|
+
params.add(object)
|
|
51
|
+
params << list_options[:query_params]
|
|
52
|
+
|
|
53
|
+
runtime_fail '%s: query_type => :controller_call '\
|
|
54
|
+
'requires missing :query_call declaration'\
|
|
55
|
+
' (Controller function)',
|
|
56
|
+
data if list_options[:query_call].nil?
|
|
57
|
+
|
|
58
|
+
proc = list_options[:query_call]
|
|
59
|
+
begin
|
|
60
|
+
list = @controller.method(proc).call(obj_to_load, params)
|
|
61
|
+
rescue => e
|
|
62
|
+
runtime_fail "Error during call of '%s':\n%s", proc, e.message
|
|
63
|
+
end
|
|
64
|
+
{ :list => list, :default_value => nil }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Internal setup function to build the list from a query call.
|
|
68
|
+
#
|
|
69
|
+
# * *Args* :
|
|
70
|
+
# - +obj_to_load+ : Object to get list from.
|
|
71
|
+
# - +list_options+: list and validation options
|
|
72
|
+
#
|
|
73
|
+
# * *Returns*:
|
|
74
|
+
# - Hash : list of possible values and default.
|
|
75
|
+
# :default_value : Value pre-selected.
|
|
76
|
+
# :list : list of possible values
|
|
77
|
+
#
|
|
78
|
+
# * *Raises* :
|
|
79
|
+
#
|
|
80
|
+
def _setup_list_from_query_call(obj_to_load, list_options)
|
|
81
|
+
PrcLib.message("Querying #{obj_to_load}.")
|
|
82
|
+
|
|
83
|
+
query_hash = list_options[:query_params]
|
|
84
|
+
query_hash = {} if query_hash.nil?
|
|
85
|
+
|
|
86
|
+
object_list = query(obj_to_load, query_hash)
|
|
87
|
+
|
|
88
|
+
list = []
|
|
89
|
+
object_list.each { | oElem | list << oElem[list_options[:value]] }
|
|
90
|
+
|
|
91
|
+
{ :list => list.sort!, :default_value => nil }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def _setup_build_process_params(option_params, params)
|
|
95
|
+
return if option_params.nil?
|
|
96
|
+
|
|
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 }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Internal setup function to build the list from a process call.
|
|
110
|
+
#
|
|
111
|
+
# * *Args* :
|
|
112
|
+
# - +obj_to_load+ : Object to get list from.
|
|
113
|
+
# - +list_options+: list and validation options
|
|
114
|
+
#
|
|
115
|
+
# * *Returns*:
|
|
116
|
+
# - Hash : list of possible values and default.
|
|
117
|
+
# :default_value : Value pre-selected.
|
|
118
|
+
# :list : list of possible values
|
|
119
|
+
#
|
|
120
|
+
# * *Raises* :
|
|
121
|
+
#
|
|
122
|
+
def _setup_list_from_process_call(obj_to_load, list_options)
|
|
123
|
+
runtime_fail '%s: query_type => :process_call'\
|
|
124
|
+
' requires missing :query_call declaration'\
|
|
125
|
+
' (Provider function)',
|
|
126
|
+
data if list_options[:query_call].nil?
|
|
127
|
+
proc = list_options[:query_call]
|
|
128
|
+
obj_to_load = list_options[:object]
|
|
129
|
+
PrcLib.debug(2, "Running process '#{proc}' on '#{obj_to_load}'.")
|
|
130
|
+
|
|
131
|
+
# Building Process function attr_params parameter
|
|
132
|
+
params = ObjectData.new
|
|
133
|
+
params << { :default_value => default }
|
|
134
|
+
|
|
135
|
+
_setup_build_process_params(list_options[:query_params], params)
|
|
136
|
+
|
|
137
|
+
begin
|
|
138
|
+
proc_method = @process.method(proc)
|
|
139
|
+
result = proc_method.call(obj_to_load, params)
|
|
140
|
+
rescue => e
|
|
141
|
+
runtime_fail "Error during call of '%s':\n%s",
|
|
142
|
+
proc, e.message
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
if result.is_a?(Hash)
|
|
146
|
+
if result[:list].nil? ||
|
|
147
|
+
!result[:list].is_a?(Array)
|
|
148
|
+
PrcLib.debug("Process function '%s' did not return an"\
|
|
149
|
+
' :list => Array of list_options.',
|
|
150
|
+
list_options[:query_call])
|
|
151
|
+
end
|
|
152
|
+
else
|
|
153
|
+
PrcLib.debug("Process function '%s' did not return an"\
|
|
154
|
+
' Hash with :list and :default_value')
|
|
155
|
+
result = { :list => [], :default_value => nil }
|
|
156
|
+
end
|
|
157
|
+
result
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|