lorj 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/prc-account.rb DELETED
@@ -1,339 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'rubygems'
19
-
20
- module Lorj
21
-
22
- class Accounts
23
- # Class to query FORJ Accounts list.
24
- def initialize()
25
- end
26
-
27
- def dump()
28
- aAccounts=[]
29
- Dir.foreach($FORJ_ACCOUNTS_PATH) { |x| aAccounts << x if not x.match(/^\..?$/) }
30
- aAccounts
31
- end
32
- end
33
-
34
- # Lorj::Account manage a list of key/value grouped by section.
35
- # The intent of Lorj::Account is to attach some keys/values to
36
- # an account to help end users to switch between each of them.
37
- #
38
- # Lorj::Account based on ForjConfig (see forj-config.rb)
39
- # ensure ForjConfig and Lorj::Account defines following common functions
40
- # - set (key, value)
41
- # - get (key)
42
- #
43
- # This means that key HAVE to be unique across sections
44
- # By default, keys maps with the same key name in ForjConfig.
45
- # But we can redefine the ForjConfig mapping of any key on need.
46
- #
47
- # ForjConfig, loads Account meta structure from defaults.yaml, sections
48
- #
49
- # defaults.yaml structure is:
50
- # sections:
51
- # default: => defines key/values recognized by Lorj::Account to be only managed by ForjConfig.
52
- # <key> :
53
- # :desc : <value> => defines the ForjConfig key description.
54
- # <section>: Define a section name. For each keys on this section, the account file will kept those data under this section.
55
- # <key>:
56
- # :desc: defines the key description.
57
- # :readonly: true if this key cannot be updated by Lorj::Account.set
58
- # :account_exclusive: true if this key cannot be predefined on ForjConfig keys list
59
- # :default: <ForjConfig real key name> Used to map the Lorj::Account key to a different ForjConfig key name.
60
-
61
- class Account
62
-
63
- attr_reader :sAccountName
64
- attr_reader :hAccountData
65
- attr_reader :oConfig
66
-
67
- # This object manage data located in oConfig[:hpc_accounts/AccountName]
68
-
69
- def initialize(oConfig = nil)
70
- # Initialize object
71
- if oConfig.nil?
72
- @oConfig = Lorj::Config.new()
73
- elsif oConfig.is_a?(String)
74
- @oConfig = Lorj::Config.new()
75
- @oConfig[:account_name] = oConfig
76
- else
77
- @oConfig = oConfig
78
- end
79
-
80
- if @oConfig.exist?(:account_name)
81
- @sAccountName = @oConfig[:account_name]
82
- else
83
- @sAccountName = 'lorj'
84
- end
85
- @sAccountFile = File.join(PrcLib.data_path, 'accounts', @sAccountName)
86
-
87
- sProvider = 'lorj'
88
- sProvider = @oConfig.get(:provider) if @oConfig.get(:provider)
89
-
90
- @hAccountData = {}
91
- _set(:account, :name, @sAccountName) if exist?(:name) != 'hash'
92
- _set(:account, :provider, sProvider) if exist?(:provider) != 'hash'
93
-
94
- PrcLib.ensure_dir_exists(File.join(PrcLib.data_path, 'accounts'))
95
- end
96
-
97
- # oForjAccount data get at several levels:
98
- # - runtime : get the data from runtime (runtimeSet/runtimeGet)
99
- # - Account : otherwise, get data from account file under section described in defaults.yaml (:account_section_mapping), as soon as this mapping exists.
100
- # - local : otherwise, get the data from the local configuration file. Usually ~/.forj/config.yaml
101
- # - application: otherwise, get the data from defaults.yaml (class Default)
102
- # - default : otherwise, use the get default parameter as value. Default is nil.
103
- #
104
- # * *Args* :
105
- # - +key+ : key name. It do not support it to be a key tree (Arrays of keys).
106
- # - +default+ : default value, if not found.
107
- # * *Returns* :
108
- # - key value.
109
- # * *Raises* :
110
- # Nothing
111
- def get(key, default = nil)
112
- return nil if not key
113
-
114
- key = key.to_sym if key.class == String
115
-
116
- return @oConfig.runtimeGet(key) if @oConfig.runtimeExist?(key)
117
-
118
- section = Lorj::Default.get_meta_section(key)
119
- default_key = key
120
-
121
- if not section
122
- PrcLib.debug("Lorj::Account.get: Unable to get account data '%s'. No section found. check defaults.yaml." % [key])
123
- else
124
- return Lorj::rhGet(@hAccountData, section, key) if Lorj::rhExist?(@hAccountData, section, key) == 2
125
-
126
- hMeta = @oConfig.getAppDefault(:sections)
127
- if Lorj::rhExist?(hMeta, section, key, :default) == 3
128
- default_key = Lorj::rhGet(hMeta, section, key, :default)
129
- PrcLib.debug("Lorj::Account.get: Reading default key '%s' instead of '%s'" % [default_key, key])
130
- end
131
- return default if Lorj::rhExist?(hMeta, section, key, :account_exclusive) == 3
132
- end
133
-
134
- @oConfig.get(default_key , default )
135
- end
136
-
137
- def [](key, default = nil)
138
- get(key, default)
139
- end
140
-
141
- # check key/value existence in the following order:
142
- # - runtime : get the data from runtime (runtimeSet/runtimeGet)
143
- # - Account : otherwise, get data from account file under section described in defaults.yaml (:account_section_mapping), as soon as this mapping exists.
144
- # - local : otherwise, get the data from the local configuration file. Usually ~/.forj/config.yaml
145
- # - application: otherwise, get the data from defaults.yaml (class Default)
146
- #
147
- # * *Args* :
148
- # - +key+ : key name. It do not support it to be a key tree (Arrays of keys).
149
- # - +default+ : default value, if not found.
150
- # * *Returns* :
151
- # - 'runtime' : if found in runtime.
152
- # - '<AccountName>' : if found in the Account data structure.
153
- # - 'local' : if found in the local configuration file. Usually ~/.forj/config.yaml
154
- # - 'default' : if found in the Application default (File 'defaults.yaml') (class Default)
155
- # * *Raises* :
156
- # Nothing
157
-
158
- def exist?(key)
159
- return nil if not key
160
-
161
- key = key.to_sym if key.class == String
162
- section = Lorj::Default.get_meta_section(key)
163
- if not section
164
- PrcLib.debug("Lorj::Account.exist?: No section found for key '%s'." % [key])
165
- return nil
166
- end
167
-
168
- return 'runtime' if @oConfig.runtimeExist?(key)
169
-
170
- return @sAccountName if Lorj::rhExist?(@hAccountData, section, key) == 2
171
-
172
- hMeta = @oConfig.getAppDefault(:sections)
173
- if Lorj::rhExist?(hMeta, section, key, :default) == 3
174
- default_key = Lorj::rhGet(hMeta, section, key, :default)
175
- PrcLib.debug("Lorj::Account.exist?: Reading default key '%s' instead of '%s'" % [default_key, key])
176
- else
177
- default_key = key
178
- end
179
- return nil if Lorj::rhExist?(hMeta, section, key, :account_exclusive) == 3
180
-
181
- @oConfig.exist?(default_key)
182
-
183
- end
184
-
185
- # Return true if readonly. set won't be able to update this value.
186
- # Only _set (private function) is able.
187
- #
188
- # * *Args* :
189
- # - +key+ : key name. It can support it to be a key tree (Arrays of keys).
190
- # * *Returns* :
191
- def readonly?(key)
192
- return nil if not key
193
-
194
- key = key.to_sym if key.class == String
195
- section = Lorj::Default.get_meta_section(key)
196
-
197
- Lorj::rhGet(@oConfig.getAppDefault(:sections, section), key, :readonly)
198
-
199
- end
200
-
201
- def meta_set(key, hMeta)
202
- key = key.to_sym if key.class == String
203
- section = Lorj::Default.get_meta_section(key)
204
- hCurMeta = Lorj::rhGet(@oConfig.getAppDefault(:sections, section), key)
205
- hMeta.each { | mykey, myvalue |
206
- Lorj::rhSet(hCurMeta, myvalue, mykey)
207
- }
208
- end
209
-
210
- def meta_exist?(key)
211
- return nil if not key
212
-
213
- key = key.to_sym if key.class == String
214
- section = Lorj::Default.get_meta_section(key)
215
- Lorj::rhExist?(@oConfig.getAppDefault(:sections, section), key) == 1
216
- end
217
-
218
- def get_meta_section(key)
219
- key = key.to_sym if key.class == String
220
- Lorj::rhGet(@account_section_mapping, key)
221
- end
222
-
223
- def meta_type?(key)
224
- return nil if not key
225
-
226
- section = Lorj::Default.get_meta_section(key)
227
-
228
- return section if section == :default
229
- @sAccountName
230
- end
231
-
232
- # Loop on account metadata
233
- def metadata_each
234
- Lorj::rhGet(Lorj::Default.dump(), :sections).each { | section, hValue |
235
- next if section == :default
236
- hValue.each { | key, value |
237
- yield section, key, value
238
- }
239
- }
240
- end
241
-
242
- # Return true if exclusive
243
- def exclusive?(key)
244
- return nil if not key
245
-
246
- key = key.to_sym if key.class == String
247
- section = Lorj::Default.get_meta_section(key)
248
-
249
- Lorj::rhGet(@oConfig.getAppDefault(:sections, section), key, :account_exclusive)
250
- end
251
-
252
- # This function update a section/key=value if the account structure is defined.
253
- # If no section is defined, set it in runtime config.
254
- def set(key, value)
255
- return nil if not key
256
-
257
- key = key.to_sym if key.class == String
258
- section = Lorj::Default.get_meta_section(key)
259
-
260
- return @oConfig.set(key, value) if not section
261
- return nil if readonly?(key)
262
- _set(section, key, value)
263
- end
264
-
265
- def []=(key, value)
266
- set(key, value)
267
- end
268
-
269
- def del(key)
270
- return nil if not key
271
-
272
- key = key.to_sym if key.class == String
273
- section = Lorj::Default.get_meta_section(key)
274
- return nil if not section
275
- Lorj::rhSet(@hAccountData, nil, section, key)
276
- end
277
-
278
- def getAccountData(section, key, default=nil)
279
- return Lorj::rhGet(@hAccountData, section, key) if Lorj::rhExist?(@hAccountData, section, key) == 2
280
- default
281
- end
282
-
283
- def ac_new(sAccountName)
284
- return nil if sAccountName.nil?
285
- @sAccountName = sAccountName
286
- @sAccountFile = File.join($FORJ_ACCOUNTS_PATH, @sAccountName)
287
-
288
- @hAccountData = {:account => {:name => sAccountName, :provider => @oConfig.get(:provider_name)}}
289
- end
290
-
291
- # Load Account Information
292
- def ac_load(sAccountName = @sAccountName)
293
-
294
- if sAccountName != @sAccountName
295
- ac_new(sAccountName)
296
- end
297
-
298
- if File.exists?(@sAccountFile)
299
- @hAccountData = @oConfig.extraLoad(@sAccountFile, :forj_accounts, @sAccountName)
300
- # Check if hAccountData are using symbol or needs to be updated.
301
- sProvider = @oConfig.get(:provider, 'hpcloud')
302
- Lorj::rhSet(@hAccountData, @sAccountName, :account, :name) if Lorj::rhExist?(@hAccountData, :account, :name) != 2
303
- Lorj::rhSet(@hAccountData, sProvider, :account, :provider) if Lorj::rhExist?(@hAccountData, :account, :provider) != 2
304
-
305
- if Lorj::rhKeyToSymbol?(@hAccountData, 2)
306
- @hAccountData = Lorj::rhKeyToSymbol(@hAccountData, 2)
307
- self.ac_save()
308
- end
309
- return @hAccountData
310
- end
311
- nil
312
- end
313
-
314
- def dump()
315
- { :forj_account => @hAccountData }
316
- end
317
-
318
- # Account save function.
319
- # Use set/get to manage those data that you will be able to save in an account file.
320
- def ac_save()
321
- @oConfig.extraSet(:forj_accounts, @sAccountName, nil, @hAccountData)
322
- @oConfig.extraSave(@sAccountFile, :forj_accounts, @sAccountName)
323
-
324
- if not @oConfig.localDefaultExist?('account_name')
325
- @oConfig.localSet('account_name',@sAccountName)
326
- @oConfig.saveConfig
327
- end
328
- end
329
-
330
- # private functions
331
- private
332
- def _set(section, key, value)
333
- return nil if not key or not section
334
-
335
- Lorj::rhSet(@hAccountData, value, section, key)
336
- end
337
-
338
- end
339
- end