lorj 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,285 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'yaml'
|
18
|
+
|
19
|
+
module PRC
|
20
|
+
# This class is Base config system of lorj.
|
21
|
+
#
|
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
|
+
# behave
|
32
|
+
#
|
33
|
+
# Config Data are managed as Hash of Hashes.
|
34
|
+
# It uses actively Hash.rh_* functions. See rh.rb.
|
35
|
+
class BaseConfig
|
36
|
+
attr_reader :data
|
37
|
+
attr_reader :filename
|
38
|
+
|
39
|
+
# initialize BaseConfig
|
40
|
+
#
|
41
|
+
# * *Args*
|
42
|
+
# - +keys+ : Array of key path to found
|
43
|
+
#
|
44
|
+
# * *Returns*
|
45
|
+
# - boolean : true if the key path was found
|
46
|
+
#
|
47
|
+
# ex:
|
48
|
+
# value = CoreConfig.New({ :test => {:titi => 'found'}})
|
49
|
+
# # => creates a CoreConfig with this Hash of Hash
|
50
|
+
def initialize(value = nil)
|
51
|
+
@data = {}
|
52
|
+
@data = value if value.is_a?(Hash)
|
53
|
+
@data_options = {} # Options for exist?/set/get/load/save
|
54
|
+
end
|
55
|
+
|
56
|
+
# data_options set data options used by exist?, get, set, load and save
|
57
|
+
# functions.
|
58
|
+
#
|
59
|
+
# CoreConfig class type, call data_options to set options, before calling
|
60
|
+
# functions: exist?, get, set, load and save.
|
61
|
+
#
|
62
|
+
# Currently, data_options implements:
|
63
|
+
# - :data_readonly : The data cannot be updated. set will not update
|
64
|
+
# the value.
|
65
|
+
# - :file_readonly : The file used to load data cannot be updated.
|
66
|
+
# save will not update the file.
|
67
|
+
#
|
68
|
+
# The child class can superseed or replace data options with their own
|
69
|
+
# options.
|
70
|
+
# Ex: If your child class want to introduce notion of sections,
|
71
|
+
# 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
|
+
#
|
77
|
+
# def [](*keys)
|
78
|
+
# _get(@data_options[:section], *keys)
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# def []=(*keys, value)
|
82
|
+
# _set(@data_options[:section], *keys, value)
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# * *Args*
|
88
|
+
# - +keys+ : Array of key path to found
|
89
|
+
#
|
90
|
+
# * *Returns*
|
91
|
+
# - boolean : true if the key path was found
|
92
|
+
#
|
93
|
+
# ex:
|
94
|
+
# { :test => {:titi => 'found'}}
|
95
|
+
def data_options(options = nil)
|
96
|
+
_data_options options
|
97
|
+
end
|
98
|
+
|
99
|
+
# exist?
|
100
|
+
#
|
101
|
+
# * *Args*
|
102
|
+
# - +keys+ : Array of key path to found
|
103
|
+
#
|
104
|
+
# * *Returns*
|
105
|
+
# - boolean : true if the key path was found
|
106
|
+
#
|
107
|
+
# ex:
|
108
|
+
# { :test => {:titi => 'found'}}
|
109
|
+
def exist?(*keys)
|
110
|
+
_exist?(*keys)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Erase function
|
114
|
+
#
|
115
|
+
# * *Args*
|
116
|
+
#
|
117
|
+
# * *Returns*
|
118
|
+
# -
|
119
|
+
#
|
120
|
+
def erase
|
121
|
+
@data = {}
|
122
|
+
end
|
123
|
+
|
124
|
+
# Get function
|
125
|
+
#
|
126
|
+
# * *Args*
|
127
|
+
# - +keys+ : Array of key path to found
|
128
|
+
#
|
129
|
+
# * *Returns*
|
130
|
+
# -
|
131
|
+
#
|
132
|
+
def [](*keys)
|
133
|
+
_get(*keys)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Set function
|
137
|
+
#
|
138
|
+
# * *Args*
|
139
|
+
# - +keys+ : set a value in the Array of key path.
|
140
|
+
#
|
141
|
+
# * *Returns*
|
142
|
+
# - The value set or nil
|
143
|
+
#
|
144
|
+
# ex:
|
145
|
+
# value = CoreConfig.New
|
146
|
+
#
|
147
|
+
# value[:level1, :level2] = 'value'
|
148
|
+
# # => {:level1 => {:level2 => 'value'}}
|
149
|
+
|
150
|
+
def del(*keys)
|
151
|
+
_del(*keys)
|
152
|
+
end
|
153
|
+
# Set function
|
154
|
+
#
|
155
|
+
# * *Args*
|
156
|
+
# - +keys+ : set a value in the Array of key path.
|
157
|
+
#
|
158
|
+
# * *Returns*
|
159
|
+
# - The value set or nil
|
160
|
+
#
|
161
|
+
# ex:
|
162
|
+
# value = CoreConfig.New
|
163
|
+
#
|
164
|
+
# value[:level1, :level2] = 'value'
|
165
|
+
# # => {:level1 => {:level2 => 'value'}}
|
166
|
+
def []=(*keys, value)
|
167
|
+
_set(*keys, value)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Load from a file
|
171
|
+
#
|
172
|
+
# * *Args* :
|
173
|
+
# - +filename+ : file name to load. This file name will become the default
|
174
|
+
# file name to use next time.
|
175
|
+
# * *Returns* :
|
176
|
+
# - true if loaded.
|
177
|
+
# * *Raises* :
|
178
|
+
# - ++ ->
|
179
|
+
def load(filename = nil)
|
180
|
+
_load(filename)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Save to a file
|
184
|
+
#
|
185
|
+
# * *Args* :
|
186
|
+
# - +filename+ : file name to save. This file name will become the default
|
187
|
+
# file name to use next time.
|
188
|
+
# * *Returns* :
|
189
|
+
# - boolean if saved or not. true = saved.
|
190
|
+
def save(filename = nil)
|
191
|
+
_save(filename)
|
192
|
+
end
|
193
|
+
|
194
|
+
# transform keys from string to symbol until deep level. Default is 1.
|
195
|
+
#
|
196
|
+
# * *Args* :
|
197
|
+
# - +level+ : Default 1. level to transform
|
198
|
+
#
|
199
|
+
# * *Returns* :
|
200
|
+
# - it self, with config updated.
|
201
|
+
def rh_key_to_symbol(level = 1)
|
202
|
+
data.rh_key_to_symbol level
|
203
|
+
end
|
204
|
+
|
205
|
+
# Check the need to transform keys from string to symbol until deep level.
|
206
|
+
# Default is 1.
|
207
|
+
#
|
208
|
+
# * *Args* :
|
209
|
+
# - +level+ : Default 1: levels to verify
|
210
|
+
#
|
211
|
+
# * *Returns* :
|
212
|
+
# - true if need to be updated.
|
213
|
+
#
|
214
|
+
def rh_key_to_symbol?(level = 1)
|
215
|
+
data.rh_key_to_symbol? level
|
216
|
+
end
|
217
|
+
|
218
|
+
# Update default filename.
|
219
|
+
#
|
220
|
+
# * *Args* :
|
221
|
+
# - +filename+ : default file name to use.
|
222
|
+
# * *Returns* :
|
223
|
+
# - filename
|
224
|
+
def filename=(filename)
|
225
|
+
@filename = File.expand_path(filename) unless filename.nil?
|
226
|
+
end
|
227
|
+
|
228
|
+
def to_s
|
229
|
+
msg = format("File : %s\n", @filename)
|
230
|
+
msg += data.to_yaml
|
231
|
+
msg
|
232
|
+
end
|
233
|
+
|
234
|
+
private
|
235
|
+
|
236
|
+
def _data_options(options = nil)
|
237
|
+
@data_options = options unless options.nil?
|
238
|
+
@data_options
|
239
|
+
end
|
240
|
+
|
241
|
+
def _exist?(*keys)
|
242
|
+
return nil if keys.length == 0
|
243
|
+
|
244
|
+
(@data.rh_exist?(*keys))
|
245
|
+
end
|
246
|
+
|
247
|
+
def _get(*keys)
|
248
|
+
return nil if keys.length == 0
|
249
|
+
|
250
|
+
@data.rh_get(*keys)
|
251
|
+
end
|
252
|
+
|
253
|
+
def _del(*keys)
|
254
|
+
return nil if keys.length == 0
|
255
|
+
|
256
|
+
@data.rh_del(*keys)
|
257
|
+
end
|
258
|
+
|
259
|
+
def _set(*keys, value)
|
260
|
+
return nil if keys.length == 0
|
261
|
+
return _get(*keys) if @data_options[:data_readonly]
|
262
|
+
|
263
|
+
@data.rh_set(value, keys)
|
264
|
+
end
|
265
|
+
|
266
|
+
def _load(file = nil)
|
267
|
+
self.filename = file unless file.nil?
|
268
|
+
|
269
|
+
fail 'Config filename not set.' if @filename.nil?
|
270
|
+
|
271
|
+
@data = YAML.load_file(File.expand_path(@filename))
|
272
|
+
true
|
273
|
+
end
|
274
|
+
|
275
|
+
def _save(file = nil)
|
276
|
+
return false if @data_options[:file_readonly]
|
277
|
+
self.filename = file unless file.nil?
|
278
|
+
|
279
|
+
fail 'Config filename not set.' if @filename.nil?
|
280
|
+
|
281
|
+
File.open(@filename, 'w+') { |out| YAML.dump(@data, out) }
|
282
|
+
true
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|