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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. 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