lorj 1.0.3 → 1.0.4
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/example/students_1/students.rb +5 -6
- data/example/students_2/students.rb +4 -5
- data/example/students_3/students.rb +4 -5
- data/example/students_4/students.rb +4 -5
- data/example/students_5/students.rb +5 -5
- data/lib/core/core.rb +6 -1
- data/lib/core/core_controller.rb +1 -9
- data/lib/core/core_internal.rb +2 -1
- data/lib/core/core_model.rb +2 -10
- data/lib/core/core_object_data.rb +18 -0
- data/lib/core/core_object_params.rb +43 -4
- data/lib/core/core_process.rb +1 -9
- data/lib/core/core_process_setup.rb +32 -6
- data/lib/core/core_setup_ask.rb +41 -33
- data/lib/core/core_setup_encrypt.rb +29 -6
- data/lib/core/core_setup_init.rb +2 -2
- data/lib/core/definition.rb +33 -10
- data/lib/core/definition_internal.rb +10 -14
- data/lib/core/lorj_basedefinition.rb +16 -24
- data/lib/core/lorj_baseprocess.rb +113 -44
- data/lib/core/lorj_data.rb +2 -9
- data/lib/core/lorj_keypath.rb +5 -2
- data/lib/core_process/cloud/process/common.rb +4 -7
- data/lib/core_process/cloud/process/connection.rb +44 -45
- data/lib/core_process/cloud/process/external_network.rb +24 -28
- data/lib/core_process/cloud/process/flavor.rb +31 -34
- data/lib/core_process/cloud/process/images.rb +12 -15
- data/lib/core_process/cloud/process/internet_network.rb +13 -14
- data/lib/core_process/cloud/process/internet_server.rb +9 -10
- data/lib/core_process/cloud/process/keypairs.rb +34 -27
- data/lib/core_process/cloud/process/network.rb +21 -23
- data/lib/core_process/cloud/process/public_ip.rb +17 -18
- data/lib/core_process/cloud/process/router.rb +86 -92
- data/lib/core_process/cloud/process/rules.rb +30 -31
- data/lib/core_process/cloud/process/security_groups.rb +21 -22
- data/lib/core_process/cloud/process/server.rb +30 -31
- data/lib/core_process/cloud/process/server_log.rb +13 -14
- data/lib/core_process/cloud/process/subnetwork.rb +25 -40
- data/lib/logging.rb +4 -17
- data/lib/lorj/version.rb +1 -1
- data/lib/lorj.rb +2 -1
- data/lib/lorj_account.rb +137 -90
- data/lib/lorj_config.rb +13 -19
- data/lib/lorj_defaults.rb +46 -292
- data/lib/lorj_meta.rb +729 -0
- data/lib/prc.rb +119 -30
- data/lib/prc_base_config.rb +53 -47
- data/lib/prc_core_config.rb +837 -565
- data/lib/prc_section_config.rb +44 -16
- data/lib/providers/hpcloud/hpcloud.rb +1 -1
- data/lib/providers/openstack/openstack.rb +278 -21
- data/lib/providers/openstack/openstack_create.rb +205 -0
- data/lib/providers/openstack/openstack_delete.rb +28 -0
- data/lib/providers/openstack/openstack_get.rb +39 -0
- data/lib/providers/openstack/openstack_process.rb +26 -0
- data/lib/providers/openstack/openstack_query.rb +96 -0
- data/lib/providers/openstack/openstack_update.rb +35 -0
- data/lib/rh.rb +91 -6
- data/lorj-spec/defaults.yaml +18 -12
- data/lorj.gemspec +1 -0
- data/spec/01_hash_rh_spec.rb +41 -2
- data/spec/02_prc_base_config_spec.rb +1 -1
- data/spec/03_prc_section_config_spec.rb +1 -1
- data/spec/04_prc_core_config_spec.rb +148 -4
- data/spec/09_prc_spec.rb +104 -0
- data/spec/{00_lorj_log_spec.rb → 10_lorj_log_spec.rb} +23 -2
- data/spec/11_lorj_config_spec.rb +9 -27
- data/spec/12_lorj_account_spec.rb +36 -20
- data/spec/20_lorj_meta_spec.rb +271 -0
- data/spec/21_lorj_defaults_spec.rb +85 -0
- metadata +31 -4
data/lib/prc.rb
CHANGED
@@ -26,7 +26,16 @@ require 'logger'
|
|
26
26
|
# List of possible library settings:
|
27
27
|
# - PrcLib.log
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# Set a logger object.
|
30
|
+
# By default, Lorj creates a Lorj::Logging object which enhance a double
|
31
|
+
# logging system (output and file at the same time)
|
32
|
+
#
|
33
|
+
# You can set your own logger system.
|
34
|
+
# This logger instance requires to have following features:
|
35
|
+
# * functions : unknown/warn/fatal/error/debug/info(message)
|
36
|
+
# * Is level functions: info?/debug?/warn?/error?/fatal?
|
37
|
+
# NOTE: Those functions are currently not used but may be used in the future
|
38
|
+
# * attribute : level
|
30
39
|
#
|
31
40
|
# This object is automatically created as soon as a message is printed out
|
32
41
|
# - PrcLib.core_level
|
@@ -49,6 +58,8 @@ require 'logger'
|
|
49
58
|
# - PrcLib.data_path
|
50
59
|
#
|
51
60
|
# Define the data local directory.
|
61
|
+
# This setting influences default settings for:
|
62
|
+
# PrcLib.log_file
|
52
63
|
#
|
53
64
|
# By default: ~/.<app_name>
|
54
65
|
#
|
@@ -59,8 +70,8 @@ require 'logger'
|
|
59
70
|
# - PrcLib.app_name
|
60
71
|
#
|
61
72
|
# Define the application name. By default 'lorj'.
|
62
|
-
#
|
63
|
-
#
|
73
|
+
# This setting influences default settings for:
|
74
|
+
# PrcLib.data_path, PrcLib.pdata_path and PrcLib.log_file
|
64
75
|
#
|
65
76
|
# ex:
|
66
77
|
#
|
@@ -74,28 +85,28 @@ require 'logger'
|
|
74
85
|
# Ex:
|
75
86
|
#
|
76
87
|
# puts PrcLib.app_defaults[:data] # To get value of the predefined :data key.
|
77
|
-
# - PrcLib.log_file
|
78
88
|
#
|
79
|
-
# Define the log file name used.
|
80
|
-
#
|
81
|
-
# By default, defined as ~/.<app_name>/<app_name>.log
|
82
89
|
# - PrcLib.level
|
83
90
|
# logger level used. It can be updated at runtime.
|
84
91
|
#
|
85
92
|
# Ex:
|
86
93
|
#
|
87
94
|
# PrcLib.level = Logger::FATAL
|
95
|
+
#
|
88
96
|
# - PrcLib.model
|
89
97
|
#
|
90
98
|
# Model loaded.
|
91
99
|
#
|
92
100
|
# - PrcLib.log_file
|
93
101
|
#
|
94
|
-
# Initialize a log file name instead of default
|
102
|
+
# Initialize a log file name (relative or absolute path) instead of default
|
103
|
+
# one.
|
104
|
+
# By default, defined as #{data_path}/#{app_name}.log
|
105
|
+
#
|
95
106
|
#
|
96
107
|
# Ex:
|
97
108
|
#
|
98
|
-
# PrcLib.log_file = "mylog.file.log"
|
109
|
+
# PrcLib.log_file = "mylog.file.log" # Relative path to the file
|
99
110
|
#
|
100
111
|
# - PrcLib.controller_path
|
101
112
|
#
|
@@ -141,54 +152,95 @@ module PrcLib
|
|
141
152
|
# Define module data for lorj library configuration
|
142
153
|
class << self
|
143
154
|
attr_accessor :log, :core_level
|
144
|
-
attr_reader :
|
155
|
+
attr_reader :app_defaults, :level, :lib_path
|
145
156
|
end
|
146
157
|
|
147
158
|
module_function
|
148
159
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
160
|
+
# Attribute app_name
|
161
|
+
#
|
162
|
+
# app_name is set to 'lorj' if not set.
|
163
|
+
#
|
154
164
|
def app_name
|
155
|
-
self.app_name = '
|
165
|
+
self.app_name = 'lorj' unless @app_name
|
156
166
|
@app_name
|
157
167
|
end
|
158
168
|
|
169
|
+
# Attribute app_name setting
|
170
|
+
#
|
171
|
+
# You can set the application name only one time
|
172
|
+
#
|
173
|
+
def app_name=(v)
|
174
|
+
@app_name = v unless @app_name
|
175
|
+
end
|
176
|
+
|
177
|
+
# Attribute pdata_path
|
178
|
+
#
|
179
|
+
# Path to a private data, like encrypted keys.
|
180
|
+
#
|
181
|
+
# It uses pdata_path= to set the default path if not set
|
182
|
+
# ~/.config/#{app_name}
|
183
|
+
def pdata_path
|
184
|
+
return @pdata_path unless @pdata_path.nil?
|
185
|
+
self.pdata_path = File.join('~', '.config', app_name)
|
186
|
+
@pdata_path
|
187
|
+
end
|
188
|
+
|
189
|
+
# Attribute pdata_path setting
|
190
|
+
#
|
191
|
+
# If path doesn't exist, it will be created with 700 rights (Unix).
|
192
|
+
#
|
159
193
|
def pdata_path=(v)
|
160
194
|
@pdata_path = File.expand_path(v) unless @pdata_path
|
161
|
-
PrcLib.ensure_dir_exists(@pdata_path)
|
162
195
|
begin
|
196
|
+
ensure_dir_exists(@pdata_path)
|
163
197
|
FileUtils.chmod(0700, @pdata_path) # no-op on windows
|
164
198
|
rescue => e
|
165
199
|
fatal_error(1, e.message)
|
166
200
|
end
|
167
201
|
end
|
168
202
|
|
203
|
+
# Attribute data_path
|
204
|
+
#
|
205
|
+
# Path to the application data.
|
206
|
+
#
|
207
|
+
# It uses data_path= to set the default path if not set
|
208
|
+
# ~/.#{app_name}
|
169
209
|
def data_path
|
170
210
|
return @data_path unless @data_path.nil?
|
171
211
|
|
172
|
-
|
173
|
-
@data_path
|
212
|
+
self.data_path = File.join('~', '.' + app_name)
|
213
|
+
@data_path
|
174
214
|
end
|
175
215
|
|
216
|
+
# Attribute data_path setting
|
217
|
+
#
|
218
|
+
# If path doesn't exist, it will be created.
|
219
|
+
#
|
176
220
|
def data_path=(v)
|
177
221
|
@data_path = File.expand_path(v) unless @data_path
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
222
|
+
begin
|
223
|
+
ensure_dir_exists(@data_path)
|
224
|
+
rescue => e
|
225
|
+
fatal_error(1, e.message)
|
226
|
+
end
|
183
227
|
end
|
184
228
|
|
185
229
|
# TODO: Low. Be able to support multiple model.
|
230
|
+
|
231
|
+
# Lorj::Model object access.
|
232
|
+
# If the object doesn't exist, it will be created
|
186
233
|
def model
|
187
234
|
@model = Lorj::Model.new if @model.nil?
|
188
235
|
@model
|
189
236
|
end
|
190
237
|
|
191
238
|
# TODO: Support for several defaults, depending on controllers loaded.
|
239
|
+
|
240
|
+
# Attribute app_defaults
|
241
|
+
#
|
242
|
+
# Used to define where the application defaults.yaml is located.
|
243
|
+
#
|
192
244
|
def app_defaults=(v)
|
193
245
|
return if @app_defaults
|
194
246
|
|
@@ -197,33 +249,70 @@ module PrcLib
|
|
197
249
|
@app_defaults = File.expand_path(v)
|
198
250
|
end
|
199
251
|
|
252
|
+
# log_file module attribute
|
253
|
+
#
|
254
|
+
# by default, log_file is nil.
|
255
|
+
# The user can define a log_file name or path
|
256
|
+
# The path is created (if possible) as soon a
|
257
|
+
# log_file is set.
|
258
|
+
# The file name is created by the logging class.
|
259
|
+
#
|
260
|
+
# *args*
|
261
|
+
# - +log file+ : absolute or relative path to a log file.
|
262
|
+
#
|
263
|
+
def log_file
|
264
|
+
return @log_file unless @log_file.nil?
|
265
|
+
|
266
|
+
self.log_file = File.join(data_path, app_name + '.log')
|
267
|
+
@log_file
|
268
|
+
end
|
269
|
+
|
270
|
+
# Attribute log_file setting
|
271
|
+
#
|
272
|
+
# It ensures that the path to the log file is created.
|
273
|
+
#
|
200
274
|
def log_file=(v)
|
201
275
|
file = File.basename(v)
|
202
276
|
dir = File.dirname(File.expand_path(v))
|
203
|
-
|
204
|
-
|
205
|
-
end
|
277
|
+
ensure_dir_exists(dir)
|
278
|
+
|
206
279
|
@log_file = File.join(dir, file)
|
207
280
|
end
|
208
281
|
|
282
|
+
# Attribute level setting
|
283
|
+
#
|
284
|
+
# Set the new output logging level
|
285
|
+
#
|
209
286
|
def level=(v)
|
210
287
|
@level = v
|
211
288
|
|
212
|
-
|
289
|
+
log.level = v unless log.nil?
|
213
290
|
end
|
214
291
|
|
292
|
+
# Attribute lib_path setting
|
293
|
+
#
|
294
|
+
# initialize the Lorj library path
|
295
|
+
# Used by Lorj module declaration
|
296
|
+
# See lib/lorj.rb
|
297
|
+
#
|
298
|
+
# This setting cannot be updated later.
|
299
|
+
#
|
215
300
|
def lib_path=(v)
|
216
301
|
@lib_path = v if @lib_path.nil?
|
217
302
|
end
|
218
303
|
|
219
|
-
|
304
|
+
# TODO: Support for updating the default controller path
|
305
|
+
# OR:
|
306
|
+
# TODO: Support for path search of controllers.
|
220
307
|
|
308
|
+
# Read Attribute setting for default library controller path
|
221
309
|
def controller_path
|
222
310
|
File.expand_path(File.join(@lib_path, 'providers'))
|
223
311
|
end
|
224
312
|
|
313
|
+
# Read Attribute setting for default library model/process path
|
225
314
|
def process_path
|
226
|
-
File.join(@lib_path, 'core_process')
|
315
|
+
File.expand_path(File.join(@lib_path, 'core_process'))
|
227
316
|
end
|
228
317
|
end
|
229
318
|
|
data/lib/prc_base_config.rb
CHANGED
@@ -20,21 +20,27 @@ module PRC
|
|
20
20
|
# This class is Base config system of lorj.
|
21
21
|
#
|
22
22
|
# It implements basic config features:
|
23
|
-
# * erase - To cleanup all data in self config
|
24
|
-
# * [] - To get a value for a key or tree of keys
|
25
|
-
# * []= - To set a value for a key in the tree.
|
26
|
-
# * exist? - To check the existence of a value from a key
|
27
|
-
# * del - To delete a key tree.
|
28
|
-
# * save - To save all data in a yaml file
|
29
|
-
# * load - To load data from a yaml file
|
30
|
-
# * data_options - To influence on how exist?, [], []=, load and save will
|
31
|
-
#
|
23
|
+
# * #erase - To cleanup all data in self config
|
24
|
+
# * #[] - To get a value for a key or tree of keys
|
25
|
+
# * #[]= - To set a value for a key in the tree.
|
26
|
+
# * #exist? - To check the existence of a value from a key
|
27
|
+
# * #del - To delete a key tree.
|
28
|
+
# * #save - To save all data in a yaml file
|
29
|
+
# * #load - To load data from a yaml file
|
30
|
+
# * #data_options - To influence on how exist?, [], []=, load and save will
|
31
|
+
# behave
|
32
32
|
#
|
33
33
|
# Config Data are managed as Hash of Hashes.
|
34
34
|
# It uses actively Hash.rh_* functions. See rh.rb.
|
35
35
|
class BaseConfig
|
36
|
+
# internal Hash data of this config.
|
37
|
+
# Do not use it except if you know what you are doing.
|
36
38
|
attr_reader :data
|
37
|
-
|
39
|
+
|
40
|
+
# * *set*: set the config file name. It accepts relative or absolute path to
|
41
|
+
# the file.
|
42
|
+
# * *get*: get the config file name used by #load and #save.
|
43
|
+
attr_accessor :filename
|
38
44
|
|
39
45
|
# initialize BaseConfig
|
40
46
|
#
|
@@ -61,39 +67,37 @@ module PRC
|
|
61
67
|
#
|
62
68
|
# Currently, data_options implements:
|
63
69
|
# - :data_readonly : The data cannot be updated. set will not update
|
64
|
-
#
|
70
|
+
# the value.
|
65
71
|
# - :file_readonly : The file used to load data cannot be updated.
|
66
|
-
#
|
72
|
+
# save will not update the file.
|
67
73
|
#
|
68
74
|
# The child class can superseed or replace data options with their own
|
69
75
|
# options.
|
70
76
|
# Ex: If your child class want to introduce notion of sections,
|
71
77
|
# you can define the following with get:
|
72
|
-
# # by default, section name to use by get/set is :default
|
73
|
-
# def data_options(options = {:section => :default})
|
74
|
-
# _data_options(options)
|
75
|
-
# end
|
76
78
|
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
79
|
+
# class MySection < PRC::BaseConfig
|
80
|
+
# # by default, section name to use by get/set is :default
|
81
|
+
# def data_options(options = {:section => :default})
|
82
|
+
# p_data_options(options)
|
83
|
+
# end
|
80
84
|
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
85
|
+
# def [](*keys)
|
86
|
+
# p_get(@data_options[:section], *keys)
|
87
|
+
# end
|
84
88
|
#
|
85
|
-
#
|
89
|
+
# def []=(*keys, value)
|
90
|
+
# p_set(@data_options[:section], *keys, value)
|
91
|
+
# end
|
92
|
+
# end
|
86
93
|
#
|
87
94
|
# * *Args*
|
88
95
|
# - +keys+ : Array of key path to found
|
89
96
|
#
|
90
97
|
# * *Returns*
|
91
98
|
# - boolean : true if the key path was found
|
92
|
-
#
|
93
|
-
# ex:
|
94
|
-
# { :test => {:titi => 'found'}}
|
95
99
|
def data_options(options = nil)
|
96
|
-
|
100
|
+
p_data_options options
|
97
101
|
end
|
98
102
|
|
99
103
|
# exist?
|
@@ -107,7 +111,7 @@ module PRC
|
|
107
111
|
# ex:
|
108
112
|
# { :test => {:titi => 'found'}}
|
109
113
|
def exist?(*keys)
|
110
|
-
|
114
|
+
p_exist?(*keys)
|
111
115
|
end
|
112
116
|
|
113
117
|
# Erase function
|
@@ -130,7 +134,7 @@ module PRC
|
|
130
134
|
# -
|
131
135
|
#
|
132
136
|
def [](*keys)
|
133
|
-
|
137
|
+
p_get(*keys)
|
134
138
|
end
|
135
139
|
|
136
140
|
# Set function
|
@@ -148,8 +152,9 @@ module PRC
|
|
148
152
|
# # => {:level1 => {:level2 => 'value'}}
|
149
153
|
|
150
154
|
def del(*keys)
|
151
|
-
|
155
|
+
p_del(*keys)
|
152
156
|
end
|
157
|
+
|
153
158
|
# Set function
|
154
159
|
#
|
155
160
|
# * *Args*
|
@@ -159,25 +164,25 @@ module PRC
|
|
159
164
|
# - The value set or nil
|
160
165
|
#
|
161
166
|
# ex:
|
162
|
-
#
|
167
|
+
# value = CoreConfig.New
|
163
168
|
#
|
164
|
-
#
|
165
|
-
#
|
169
|
+
# value[:level1, :level2] = 'value'
|
170
|
+
# # => {:level1 => {:level2 => 'value'}}
|
166
171
|
def []=(*keys, value)
|
167
|
-
|
172
|
+
p_set(*keys, value)
|
168
173
|
end
|
169
174
|
|
170
175
|
# Load from a file
|
171
176
|
#
|
172
177
|
# * *Args* :
|
173
178
|
# - +filename+ : file name to load. This file name will become the default
|
174
|
-
#
|
179
|
+
# file name to use next time.
|
175
180
|
# * *Returns* :
|
176
181
|
# - true if loaded.
|
177
182
|
# * *Raises* :
|
178
183
|
# - ++ ->
|
179
184
|
def load(filename = nil)
|
180
|
-
|
185
|
+
p_load(filename)
|
181
186
|
end
|
182
187
|
|
183
188
|
# Save to a file
|
@@ -188,7 +193,7 @@ module PRC
|
|
188
193
|
# * *Returns* :
|
189
194
|
# - boolean if saved or not. true = saved.
|
190
195
|
def save(filename = nil)
|
191
|
-
|
196
|
+
p_save(filename)
|
192
197
|
end
|
193
198
|
|
194
199
|
# transform keys from string to symbol until deep level. Default is 1.
|
@@ -215,16 +220,17 @@ module PRC
|
|
215
220
|
data.rh_key_to_symbol? level
|
216
221
|
end
|
217
222
|
|
218
|
-
#
|
223
|
+
# Redefine the file name attribute set.
|
219
224
|
#
|
220
225
|
# * *Args* :
|
221
226
|
# - +filename+ : default file name to use.
|
222
227
|
# * *Returns* :
|
223
228
|
# - filename
|
224
|
-
def filename=(filename)
|
229
|
+
def filename=(filename) #:nodoc:
|
225
230
|
@filename = File.expand_path(filename) unless filename.nil?
|
226
231
|
end
|
227
232
|
|
233
|
+
# Print a representation of the Layer data
|
228
234
|
def to_s
|
229
235
|
msg = format("File : %s\n", @filename)
|
230
236
|
msg += data.to_yaml
|
@@ -233,37 +239,37 @@ module PRC
|
|
233
239
|
|
234
240
|
private
|
235
241
|
|
236
|
-
def
|
242
|
+
def p_data_options(options = nil)
|
237
243
|
@data_options = options unless options.nil?
|
238
244
|
@data_options
|
239
245
|
end
|
240
246
|
|
241
|
-
def
|
247
|
+
def p_exist?(*keys)
|
242
248
|
return nil if keys.length == 0
|
243
249
|
|
244
250
|
(@data.rh_exist?(*keys))
|
245
251
|
end
|
246
252
|
|
247
|
-
def
|
253
|
+
def p_get(*keys)
|
248
254
|
return nil if keys.length == 0
|
249
255
|
|
250
256
|
@data.rh_get(*keys)
|
251
257
|
end
|
252
258
|
|
253
|
-
def
|
259
|
+
def p_del(*keys)
|
254
260
|
return nil if keys.length == 0
|
255
261
|
|
256
262
|
@data.rh_del(*keys)
|
257
263
|
end
|
258
264
|
|
259
|
-
def
|
265
|
+
def p_set(*keys, value)
|
260
266
|
return nil if keys.length == 0
|
261
|
-
return
|
267
|
+
return p_get(*keys) if @data_options[:data_readonly]
|
262
268
|
|
263
269
|
@data.rh_set(value, keys)
|
264
270
|
end
|
265
271
|
|
266
|
-
def
|
272
|
+
def p_load(file = nil)
|
267
273
|
self.filename = file unless file.nil?
|
268
274
|
|
269
275
|
fail 'Config filename not set.' if @filename.nil?
|
@@ -272,7 +278,7 @@ module PRC
|
|
272
278
|
true
|
273
279
|
end
|
274
280
|
|
275
|
-
def
|
281
|
+
def p_save(file = nil)
|
276
282
|
return false if @data_options[:file_readonly]
|
277
283
|
self.filename = file unless file.nil?
|
278
284
|
|