lorj 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.gitreview +4 -0
  4. data/Gemfile +25 -0
  5. data/Gemfile.lock +34 -0
  6. data/LICENSE.txt +14 -0
  7. data/README.md +652 -0
  8. data/Rakefile +24 -0
  9. data/bin/cloud_test.rb +81 -0
  10. data/example/students_1/process/Students.rb +20 -0
  11. data/example/students_1/students.rb +16 -0
  12. data/example/students_2/process/Students.rb +27 -0
  13. data/example/students_2/students.rb +36 -0
  14. data/example/students_3/controller/yaml_students.rb +94 -0
  15. data/example/students_3/controller/yaml_students_controller.rb +123 -0
  16. data/example/students_3/process/students.rb +118 -0
  17. data/example/students_3/students.rb +93 -0
  18. data/example/students_4/controller/yaml_students.rb +82 -0
  19. data/example/students_4/controller/yaml_students_controller.rb +141 -0
  20. data/example/students_4/process/students.rb +112 -0
  21. data/example/students_4/students.rb +103 -0
  22. data/example/yaml_students/students.rb +78 -0
  23. data/example/yaml_students/yaml_students.rb +115 -0
  24. data/lib/concept.md +111 -0
  25. data/lib/core/core.rb +723 -0
  26. data/lib/core/definition.rb +505 -0
  27. data/lib/core/definition_internal.rb +338 -0
  28. data/lib/core/lorj-basecontroller.rb +90 -0
  29. data/lib/core/lorj-basedefinition.rb +1079 -0
  30. data/lib/core/lorj-baseprocess.rb +231 -0
  31. data/lib/core/lorj-data.rb +567 -0
  32. data/lib/core/lorj-keypath.rb +115 -0
  33. data/lib/core_process/CloudProcess.rb +334 -0
  34. data/lib/core_process/global_process.rb +406 -0
  35. data/lib/core_process/network_process.rb +603 -0
  36. data/lib/img/.directory +4 -0
  37. data/lib/img/account_data_access.png +0 -0
  38. data/lib/img/config_data_access.png +0 -0
  39. data/lib/img/forj-lib-concept.png +0 -0
  40. data/lib/lorj/version.rb +3 -0
  41. data/lib/lorj.rb +51 -0
  42. data/lib/prc-account.rb +339 -0
  43. data/lib/prc-config.rb +1023 -0
  44. data/lib/prc-logging.rb +183 -0
  45. data/lib/prc.rb +108 -0
  46. data/lib/providers/hpcloud/Hpcloud.rb +419 -0
  47. data/lib/providers/hpcloud/compute.rb +108 -0
  48. data/lib/providers/hpcloud/network.rb +117 -0
  49. data/lib/providers/hpcloud/security_groups.rb +67 -0
  50. data/lib/providers/mock/Mock.rb +141 -0
  51. data/lib/providers/openstack/Openstack.rb +47 -0
  52. data/lib/providers/templates/compute.rb +42 -0
  53. data/lib/providers/templates/core.rb +61 -0
  54. data/lib/providers/templates/network.rb +33 -0
  55. data/lorj-spec/defaults.yaml +26 -0
  56. data/lorj.gemspec +39 -0
  57. data/spec/forj-account_spec.rb +75 -0
  58. data/spec/forj-config_spec.rb +196 -0
  59. metadata +164 -0
@@ -0,0 +1,231 @@
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
+ # 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 object creation/etc...
23
+ # - definition(BaseDefinition): Functions to declare objects, query/data mapping and setup
24
+ # this task to make it to work.
25
+
26
+ module Lorj
27
+ # class describing generic Object Process
28
+ # Ex: How to get a Network Object (ie: get a network or create it if missing)
29
+ class BaseProcess
30
+ def initialize()
31
+ @oDefinition = nil
32
+ end
33
+
34
+ def set_BaseObject(oDefinition)
35
+ @oDefinition = oDefinition
36
+ end
37
+
38
+ def controller_create(sObjectType, hParams = {})
39
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
40
+ @oDefinition.create(sObjectType)
41
+ end
42
+
43
+ def controller_query(sObjectType, sQuery, hParams = {})
44
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
45
+ @oDefinition.query(sObjectType, sQuery)
46
+ end
47
+
48
+ def controller_update(sObjectType, hParams = {})
49
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
50
+ @oDefinition.update(sObjectType)
51
+ end
52
+
53
+ def controller_delete(sObjectType, hParams = {})
54
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
55
+ @oDefinition.delete(sObjectType)
56
+ end
57
+
58
+ def controller_get(sObjectType, sId, hParams = {})
59
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
60
+ @oDefinition.get(sObjectType, sId)
61
+ end
62
+
63
+ def Create(sObjectType)
64
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
65
+ @oDefinition.Create(sObjectType)
66
+ end
67
+
68
+ def Query(sObjectType, sQuery)
69
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
70
+ @oDefinition.Query(sObjectType, sQuery)
71
+ end
72
+
73
+ def Update(sObjectType)
74
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
75
+ @oDefinition.Update(sObjectType)
76
+ end
77
+
78
+ def Get(sObjectType, sId)
79
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
80
+ @oDefinition.Get(sObjectType, sId)
81
+ end
82
+
83
+ def Delete(sObjectType)
84
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
85
+ @oDefinition.Delete(sObjectType)
86
+ end
87
+
88
+ private
89
+
90
+ def query_cache_cleanup(sObjectType)
91
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
92
+ @oDefinition.query_cleanup(sObjectType)
93
+ end
94
+
95
+ def object_cache_cleanup(sObjectType)
96
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
97
+ @oDefinition.object_cleanup(sObjectType)
98
+ end
99
+
100
+
101
+
102
+ def controler
103
+ PrcLib::warning("controler object call is obsolete. Please update your code. Use controller_<action> instead.\n%s" % caller)
104
+ raise Lorj::PrcError.new(), "No Controler object loaded." if not @oDefinition
105
+ @oDefinition
106
+ end
107
+
108
+ def object
109
+ PrcLib::warning("object call is obsolete. Please update your code. Use <Action> instead.\n%s" % caller)
110
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
111
+ @oDefinition
112
+ end
113
+
114
+ def format_object(sObjectType, oMiscObj)
115
+
116
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
117
+ @oDefinition.format_object(sObjectType, oMiscObj)
118
+ end
119
+
120
+ def format_query(sObjectType, oMiscObj, hQuery)
121
+
122
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
123
+ @oDefinition.format_list(sObjectType, oMiscObj, hQuery)
124
+ end
125
+
126
+ def DataObjects(sObjectType, *key)
127
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
128
+ @oDefinition.DataObjects(sObjectType, *key)
129
+ end
130
+
131
+ def get_data(oObj, *key)
132
+ PrcLib::warning("get_data call is obsolete. Please update your code. Use [] instead.\n%s" % caller)
133
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
134
+ @oDefinition.get_data(oObj, :attrs, key)
135
+ end
136
+
137
+ def register(oObject, sObjectType = nil)
138
+
139
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
140
+ @oDefinition.register(oObject, sObjectType)
141
+ end
142
+
143
+ def config
144
+ raise Lorj::PrcError.new(), "No Base object loaded." if not @oDefinition
145
+ @oDefinition.config
146
+ end
147
+
148
+ def query_single(sCloudObj, oList, sQuery, name, sInfoMsg = {})
149
+ oList = controler.query(sCloudObj, sQuery)
150
+ sInfo = {
151
+ :notfound => "No %s '%s' found",
152
+ :checkmatch => "Found 1 %s. checking exact match for '%s'.",
153
+ :nomatch => "No %s '%s' match",
154
+ :found => "Found %s '%s'.",
155
+ :more => "Found several %s. Searching for '%s'.",
156
+ :items_form => "%s",
157
+ :items => [:name]
158
+ }
159
+ sInfo[:notfound] = sInfoMsg[:notfound] if sInfoMsg.key?(:notfound)
160
+ sInfo[:checkmatch] = sInfoMsg[:checkmatch] if sInfoMsg.key?(:checkmatch)
161
+ sInfo[:nomatch] = sInfoMsg[:nomatch] if sInfoMsg.key?(:nomatch)
162
+ sInfo[:found] = sInfoMsg[:found] if sInfoMsg.key?(:found)
163
+ sInfo[:more] = sInfoMsg[:more] if sInfoMsg.key?(:more)
164
+ sInfo[:items] = sInfoMsg[:items] if sInfoMsg.key?(:items)
165
+ sInfo[:items_form] = sInfoMsg[:items_form] if sInfoMsg.key?(:items_form)
166
+ case oList.length()
167
+ when 0
168
+ PrcLib.info( sInfo[:notfound] % [sCloudObj, name] )
169
+ oList
170
+ when 1
171
+ Lorj.debug(2, sInfo[:checkmatch] % [sCloudObj, name])
172
+ element = nil
173
+ oList.each { | oElem |
174
+ bFound = true
175
+ sQuery.each { | key, value |
176
+ if oElem[key] != value
177
+ bFound = false
178
+ break
179
+ end
180
+ }
181
+ :remove if not bFound
182
+ }
183
+ if oList.length == 0
184
+ PrcLib.info(sInfo[:nomatch] % [sCloudObj, name])
185
+ else
186
+ sItems = []
187
+ if sInfo[:items].is_a?(Array)
188
+ sInfo[:items].each { | key |
189
+ sItems << oList[0, key]
190
+ }
191
+ else
192
+ sItems << oList[0, sInfo[:items]]
193
+ end
194
+ sItem = sInfo[:items_form] % sItems
195
+ PrcLib.info(sInfo[:found] % [sCloudObj, sItem])
196
+ end
197
+ oList
198
+ else
199
+ Lorj.debug(2, sInfo[:more] % [sCloudObj, name])
200
+ # Looping to find the one corresponding
201
+ element = nil
202
+ oList.each { | oElem |
203
+ bFound = true
204
+ sQuery.each { | key, value |
205
+ if oElem[key] != value
206
+ bFound = false
207
+ break
208
+ end
209
+ }
210
+ :remove if not bFound
211
+ }
212
+ if oList.length == 0
213
+ PrcLib.info(sInfo[:notfound] % [sCloudObj, name])
214
+ else
215
+ sItems = []
216
+ if sInfo[:items].is_a?(Array)
217
+ sInfo[:items].each { | key |
218
+ sItems << oList[0, key]
219
+ }
220
+ else
221
+ sItems << oList[0, sInfo[:items]]
222
+ end
223
+ sItem = sInfo[:items_form] % sItems
224
+ PrcLib.info(sInfo[:found] % [sCloudObj, sItem])
225
+ end
226
+ oList
227
+ end
228
+ end
229
+
230
+ end
231
+ end