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
@@ -0,0 +1,260 @@
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
+ # It requires Core objects to be defined + default ForjProcess functions.
18
+ # ---------------------------------------------------------------------------
19
+ # Router management
20
+ # ---------------------------------------------------------------------------
21
+ class CloudProcess
22
+ # Process Create handler
23
+ def forj_get_or_create_router(_sCloudObj, hParams)
24
+ sub_net_obj = hParams[:subnetwork]
25
+
26
+ unless hParams[:router_name]
27
+ config[:router_name] = 'router-%s', hParams[:network, :name]
28
+ hParams[:router_name] = config[:router_name]
29
+ end
30
+
31
+ router_name = hParams[:router_name]
32
+ router_port = get_router_interface_attached(:port, hParams)
33
+
34
+ if !router_port
35
+ # Trying to get router
36
+ router = get_router(router_name)
37
+ router = create_router(router_name) unless router
38
+ create_router_interface(sub_net_obj, router) if router
39
+ else
40
+ router = query_router_from_port(router_port, hParams)
41
+ end
42
+ router
43
+ end
44
+ end
45
+
46
+ # Define framework object on BaseDefinition
47
+ module Lorj
48
+ # ************************************ Router Object
49
+ # Identify the router of a network.
50
+ class BaseDefinition
51
+ define_obj(:router,
52
+
53
+ :create_e => :forj_get_or_create_router,
54
+ # :query_e => :forj_query_router,
55
+ # :get_e => :forj_get_router,
56
+ :update_e => :controller_update
57
+ # :delete_e => :forj_delete_router
58
+ )
59
+ obj_needs :CloudObject, :network_connection
60
+ obj_needs :CloudObject, :network, :for => [:create_e]
61
+ obj_needs :CloudObject, :subnetwork, :for => [:create_e]
62
+ obj_needs_optional
63
+ obj_needs :data, :router_name, :for => [:create_e]
64
+
65
+ def_attribute :gateway_network_id
66
+ end
67
+
68
+ # ************************************ Port Object
69
+ # Identify port attached to network
70
+ class BaseDefinition
71
+ define_obj :port, :nohandler => true
72
+
73
+ obj_needs :CloudObject, :network_connection
74
+ def_attribute :device_id
75
+
76
+ def_query_attribute :network_id
77
+ def_query_attribute :device_owner
78
+ end
79
+
80
+ # ************************************ Router interface Object
81
+ # Identify interface attached to a router
82
+ # This object will probably be moved to controller task
83
+ # To keep the network model more generic.
84
+ class BaseDefinition
85
+ # No process handler defined. Just Controller object
86
+ define_obj :router_interface, :nohandler => true
87
+
88
+ obj_needs :CloudObject, :network_connection
89
+ obj_needs :CloudObject, :router, :for => [:create_e]
90
+ obj_needs :CloudObject, :subnetwork, :for => [:create_e]
91
+
92
+ undefine_attribute :name
93
+ undefine_attribute :id
94
+ end
95
+ end
96
+
97
+ # Router Process internal functions
98
+ class CloudProcess
99
+ def get_router(name)
100
+ PrcLib.state("Searching for router '%s'", name)
101
+ begin
102
+ routers = controller_query(:router, :name => name)
103
+ case routers.length
104
+ when 1
105
+ routers[0]
106
+ else
107
+ PrcLib.info("Router '%s' not found.", name)
108
+ nil
109
+ end
110
+ rescue => e
111
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
112
+ end
113
+ end
114
+
115
+ def create_router(router_name, oExternalNetwork = nil)
116
+ begin
117
+ if oExternalNetwork
118
+ ext_net = get_data(oExternalNetwork, :name)
119
+ PrcLib.state("Creating router '%s' attached to the external "\
120
+ "Network '%s'", router_name, ext_net)
121
+ config[:external_gateway_id] = get_data(oExternalNetwork, :id)
122
+ else
123
+ PrcLib.state("Creating router '%s' without external Network",
124
+ router_name)
125
+ end
126
+
127
+ router = controller_create(:router)
128
+ if oExternalNetwork
129
+ PrcLib.info("Router '%s' created and attached to the external "\
130
+ "Network '%s'.", router_name, ext_net)
131
+ else
132
+ PrcLib.info("Router '%s' created without external Network.",
133
+ router_name)
134
+ end
135
+ rescue => e
136
+ raise ForjError.new, "Unable to create '%s' router\n%s",
137
+ router_name, e.message
138
+ end
139
+ router
140
+ end
141
+
142
+ def delete_router(net_conn_obj, router_obj)
143
+ PrcLib.state("Deleting router '%s'", router.name)
144
+ begin
145
+ #################
146
+ provider_delete_router(net_conn_obj, router_obj)
147
+ # net_conn_obj.routers.get(router.id).destroy
148
+ rescue => e
149
+ PrcLib.error("Unable to delete '%s' router ID", router_id, e)
150
+ end
151
+ end
152
+
153
+ def query_router_from_port(router_port, hParams)
154
+ query = { :id => router_port[:device_id] }
155
+ routers = controller_query(:router, query)
156
+ case routers.length
157
+ when 1
158
+ PrcLib.info("Found router '%s' attached to the network '%s'.",
159
+ routers[0, :name], hParams[:network, :name])
160
+ routers[0]
161
+ else
162
+ PrcLib.warning('Unable to find the router '\
163
+ "id '%s'", router_port[:device_id])
164
+ ForjLib::Data.new
165
+ end
166
+ end
167
+ # TODO: Move router interface management to hpcloud controller.
168
+ # Router interface to connect to the network
169
+ def create_router_interface(oSubnet, router_obj)
170
+ PrcLib.state("Attaching subnet '%s' to router '%s'",
171
+ oSubnet[:name], router_obj[:name])
172
+ begin
173
+ controller_create(:router_interface)
174
+
175
+ #################
176
+ # provider_add_interface()
177
+ # router_obj.add_interface(oSubnet.id, nil)
178
+ rescue => e
179
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
180
+ end
181
+ end
182
+
183
+ def delete_router_interface(oSubnet, router_obj)
184
+ PrcLib.state("Removing subnet '%s' from router '%s'",
185
+ oSubnet.name, router_obj.name)
186
+ subnet_id = oSubnet.id
187
+ begin
188
+ #################
189
+ router_obj.remove_interface(subnet_id)
190
+ rescue => e
191
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
192
+ end
193
+ end
194
+
195
+ def get_router_interface_attached(sCloudObj, hParams)
196
+ PrcLib.state("Searching for router port attached to the network '%s'",
197
+ hParams[:network, :name])
198
+ begin
199
+ # Searching for router port attached
200
+ #################
201
+ query = { :network_id => hParams[
202
+ :network, :id],
203
+ :device_owner => 'network:router_interface' }
204
+
205
+ ports = controller_query(sCloudObj, query)
206
+ case ports.length
207
+ when 0
208
+ PrcLib.info("No router port attached to the network '%s'",
209
+ hParams[:network, :name])
210
+ nil
211
+ else
212
+ PrcLib.info("Found a router port attached to the network '%s' ",
213
+ hParams[:network, :name])
214
+ ports[0]
215
+ end
216
+ rescue => e
217
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
218
+ end
219
+ end
220
+
221
+ # Gateway management
222
+ def get_gateway(net_conn_obj, name)
223
+ return nil if !name || !net_conn_obj
224
+
225
+ PrcLib.state("Getting gateway '%s'", name)
226
+ networks = net_conn_obj
227
+ begin
228
+ netty = networks.get(name)
229
+ rescue => e
230
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
231
+ end
232
+ PrcLib.state("Found gateway '%s'", name) if netty
233
+ PrcLib.state("Unable to find gateway '%s'", name) unless netty
234
+ netty
235
+ end
236
+
237
+ def query_external_network(_hParams)
238
+ PrcLib.state('Identifying External gateway')
239
+ begin
240
+ # Searching for router port attached
241
+ #################
242
+ query = { :router_external => true }
243
+ networks = controller_query(:network, query)
244
+ case networks.length
245
+ when 0
246
+ PrcLib.info('No external network')
247
+ ForjLib::Data.new
248
+ when 1
249
+ PrcLib.info("Found external network '%s'.", networks[0, :name])
250
+ networks[0]
251
+ else
252
+ PrcLib.warn('Found several external networks. Selecting the '\
253
+ "first one '%s'", networks[0, :name])
254
+ networks[0]
255
+ end
256
+ rescue => e
257
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,120 @@
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
+ # It requires Core objects to be defined + default ForjProcess functions.
18
+
19
+ # SecurityGroups rules management
20
+ class CloudProcess
21
+ # Process Delete handler
22
+ def forj_delete_rule(sCloudObj, _hParams)
23
+ ssl_error_obj = SSLErrorMgt.new
24
+ begin
25
+ controller_delete(sCloudObj)
26
+ rescue => e
27
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
28
+ end
29
+ end
30
+
31
+ # Process Query handler
32
+ def forj_query_rule(sCloudObj, sQuery, hParams)
33
+ rule = '%s %s:%s - %s to %s', hParams[:dir], hParams[:rule_proto],
34
+ hParams[:port_min], hParams[:port_max],
35
+ hParams[:addr_map]
36
+ PrcLib.state("Searching for rule '%s'", rule)
37
+ ssl_error_obj = SSLErrorMgt.new
38
+ begin
39
+ info = {
40
+ :items => [:dir, :rule_proto, :port_min, :port_max, :addr_map],
41
+ :items_form => '%s %s:%s - %s to %s'
42
+ }
43
+ list = controller_query(sCloudObj, sQuery)
44
+ query_single(sCloudObj, list, sQuery, rule, info)
45
+ rescue => e
46
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
47
+ end
48
+ end
49
+
50
+ # Process Create handler
51
+ def forj_get_or_create_rule(sCloudObj, hParams)
52
+ query = {
53
+ :dir => hParams[:dir],
54
+ :proto => hParams[:proto],
55
+ :port_min => hParams[:port_min],
56
+ :port_max => hParams[:port_max],
57
+ :addr_map => hParams[:addr_map],
58
+ :sg_id => hParams[:sg_id]
59
+ }
60
+
61
+ rules = forj_query_rule(sCloudObj, query, hParams)
62
+ if rules.length == 0
63
+ create_rule(sCloudObj, hParams)
64
+ else
65
+ rules[0]
66
+ end
67
+ end
68
+ end
69
+
70
+ # Define framework object on BaseDefinition
71
+ module Lorj
72
+ # ************************************ Security group rules Object
73
+ # Identify Rules attached to the security group
74
+ class BaseDefinition
75
+ define_obj(:rule,
76
+
77
+ :create_e => :forj_get_or_create_rule,
78
+ :query_e => :forj_query_rule
79
+ # :delete_e => :forj_delete_rule
80
+ )
81
+
82
+ undefine_attribute :name # Do not return any predefined name attribute
83
+
84
+ obj_needs :CloudObject, :network_connection
85
+ obj_needs :CloudObject, :security_groups, :for => [:create_e]
86
+ obj_needs :data, :sg_id, :for => [:create_e],
87
+ :extract_from => [:security_groups,
88
+ :attrs, :id]
89
+
90
+ obj_needs :data, :dir, :for => [:create_e]
91
+ predefine_data_value :IN, :desc => 'Input NAT/firewall rule map type'
92
+ predefine_data_value :OUT, :desc => 'Output NAT/firewall rule map type'
93
+
94
+ obj_needs :data, :proto, :for => [:create_e]
95
+ obj_needs :data, :port_min, :for => [:create_e]
96
+ obj_needs :data, :port_max, :for => [:create_e]
97
+ obj_needs :data, :addr_map, :for => [:create_e]
98
+ end
99
+ end
100
+
101
+ # SecurityGroups rules management
102
+ class CloudProcess
103
+ # Rules internal #
104
+ #----------------#
105
+ def create_rule(sCloudObj, hParams)
106
+ rule = '%s %s:%s - %s to %s', hParams[:dir], hParams[:rule_proto],
107
+ hParams[:port_min], hParams[:port_max],
108
+ hParams[:addr_map]
109
+ PrcLib.state("Creating rule '%s'", rule)
110
+ ssl_error_obj = SSLErrorMgt.new
111
+ begin
112
+ rule = controller_create(sCloudObj)
113
+ PrcLib.info("Rule '%s' created.", rule)
114
+ rescue StandardError => e
115
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
116
+ PrcLib.error 'error creating the rule for port %s', rule
117
+ end
118
+ rule
119
+ end
120
+ end
@@ -0,0 +1,121 @@
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
+ # It requires Core objects to be defined + default ForjProcess functions.
18
+
19
+ # SecurityGroups management
20
+ class CloudProcess
21
+ # Process Create handler
22
+ def forj_get_or_create_sg(sCloudObj, hParams)
23
+ sg_name = hParams[:security_group]
24
+ PrcLib.state("Searching for security group '%s'", sg_name)
25
+
26
+ security_group = forj_query_sg(sCloudObj, { :name => sg_name }, hParams)
27
+ security_group = create_security_group(sCloudObj,
28
+ hParams) unless security_group
29
+ register(security_group)
30
+
31
+ PrcLib.info('Configuring Security Group \'%s\'', sg_name)
32
+ ports = config.get(:ports)
33
+
34
+ ports.each do |port|
35
+ port = port.to_s if port.class != String
36
+ if !(/^\d+(-\d+)?$/ =~ port)
37
+ PrcLib.error("Port '%s' is not valid. Must be <Port> or "\
38
+ '<PortMin>-<PortMax>', port)
39
+ else
40
+ port_found_match = /^(\d+)(-(\d+))?$/.match(port)
41
+ portmin = port_found_match[1]
42
+ portmax = (port_found_match[3]) ? (port_found_match[3]) : (portmin)
43
+ # Need to set runtime data to get or if missing
44
+ # create the required rule.
45
+ config[:dir] = :IN
46
+ config[:proto] = 'tcp'
47
+ config[:port_min] = portmin.to_i
48
+ config[:port_max] = portmax.to_i
49
+ config[:addr_map] = '0.0.0.0/0'
50
+
51
+ # object.Create(:rule)
52
+ Create(:rule)
53
+ end
54
+ end
55
+ security_group
56
+ end
57
+
58
+ # Process Delete handler
59
+ def forj_delete_sg(sCloudObj, _hParams)
60
+ ssl_error_obj = SSLErrorMgt.new
61
+ begin
62
+ controller_delete(sCloudObj)
63
+ rescue => e
64
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
65
+ end
66
+ end
67
+
68
+ # Process Query handler
69
+ def forj_query_sg(sCloudObj, sQuery, hParams)
70
+ ssl_error_obj = SSLErrorMgt.new
71
+
72
+ begin
73
+ sgroups = controller_query(sCloudObj, sQuery)
74
+ rescue => e
75
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
76
+ PrcLib.fatal(1, 'Unable to get list of security groups.', e)
77
+ end
78
+ case sgroups.length
79
+ when 0
80
+ PrcLib.info("No security group '%s' found",
81
+ hParams[:security_group])
82
+ nil
83
+ when 1
84
+ PrcLib.info("Found security group '%s'", sgroups[0, :name])
85
+ sgroups[0]
86
+ end
87
+ end
88
+ end
89
+
90
+ # Define framework object on BaseDefinition
91
+ module Lorj
92
+ # ************************************ Security groups Object
93
+ # Identify security_groups
94
+ class BaseDefinition
95
+ define_obj(:security_groups,
96
+
97
+ :create_e => :forj_get_or_create_sg,
98
+ :query_e => :forj_query_sg,
99
+ :delete_e => :forj_delete_sg
100
+ )
101
+
102
+ obj_needs :CloudObject, :network_connection
103
+ obj_needs :data, :security_group, :for => [:create_e]
104
+ obj_needs_optional
105
+ obj_needs :data, :sg_desc, :for => [:create_e]
106
+ end
107
+ end
108
+
109
+ # SecurityGroups Process internal functions #
110
+ class CloudProcess
111
+ def create_security_group(sCloudObj, hParams)
112
+ PrcLib.state("Creating security group '%s'", hParams[:security_group])
113
+ begin
114
+ sg = controller_create(sCloudObj)
115
+ PrcLib.info("Security group '%s' created.", sg[:name])
116
+ rescue => e
117
+ PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
118
+ end
119
+ sg
120
+ end
121
+ end
@@ -0,0 +1,127 @@
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
+ # It requires Core objects to be defined + default ForjProcess functions.
18
+
19
+ # ---------------------------------------------------------------------------
20
+ # Server management
21
+ # ---------------------------------------------------------------------------
22
+ class CloudProcess
23
+ # Process Handler functions
24
+ def forj_get_or_create_server(sCloudObj, hParams)
25
+ server_name = hParams[:server_name]
26
+ PrcLib.state("Searching for server '%s'", server_name)
27
+ servers = forj_query_server(sCloudObj, { :name => server_name }, hParams)
28
+ if servers.length > 0
29
+ # Get server details
30
+ forj_get_server(sCloudObj, servers[0][:attrs][:id], hParams)
31
+ else
32
+ create_server(sCloudObj, hParams)
33
+ end
34
+ end
35
+
36
+ def forj_delete_server(sCloudObj, hParams)
37
+ ssl_error_obj = SSLErrorMgt.new
38
+ begin
39
+ controller_delete(sCloudObj)
40
+ PrcLib.info('Server %s was destroyed ', hParams[:server][:name])
41
+ rescue => e
42
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
43
+ end
44
+ end
45
+
46
+ def forj_query_server(sCloudObj, sQuery, _hParams)
47
+ ssl_error_obj = SSLErrorMgt.new
48
+ begin
49
+ controller_query(sCloudObj, sQuery)
50
+ rescue => e
51
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
52
+ end
53
+ end
54
+
55
+ def forj_get_server(sCloudObj, sId, _hParams)
56
+ ssl_error_obj = SSLErrorMgt.new
57
+ begin
58
+ controller_get(sCloudObj, sId)
59
+ rescue => e
60
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
61
+ end
62
+ end
63
+ end
64
+
65
+ # Define framework object on BaseDefinition
66
+ class Lorj
67
+ # ************************************ SERVER Object
68
+ # Identify the server to use/build on the network/...
69
+ class BaseDefinition
70
+ define_obj(:server,
71
+
72
+ :create_e => :forj_get_or_create_server,
73
+ :query_e => :forj_query_server,
74
+ :get_e => :forj_get_server,
75
+ # :update_e => :forj_update_server,
76
+ :delete_e => :forj_delete_server
77
+ )
78
+
79
+ obj_needs :CloudObject, :compute_connection
80
+ obj_needs :CloudObject, :flavor, :for => [:create_e]
81
+ obj_needs :CloudObject, :network, :for => [:create_e]
82
+ obj_needs :CloudObject, :security_groups, :for => [:create_e]
83
+ obj_needs :CloudObject, :keypairs, :for => [:create_e]
84
+ obj_needs :CloudObject, :image, :for => [:create_e]
85
+ obj_needs :data, :server_name, :for => [:create_e]
86
+
87
+ obj_needs_optional
88
+ obj_needs :data, :user_data, :for => [:create_e]
89
+ obj_needs :data, :meta_data, :for => [:create_e]
90
+
91
+ def_attribute :status
92
+ predefine_data_value :create, :desc => 'Server is creating.'
93
+ predefine_data_value :boot, :desc => 'Server is booting.'
94
+ predefine_data_value :active, :desc => 'Server is started.'
95
+ def_attribute :private_ip_address
96
+ def_attribute :public_ip_address
97
+
98
+ def_attribute :image_id
99
+ def_attribute :key_name
100
+ end
101
+ end
102
+
103
+ # Internal Process function
104
+ class CloudProcess
105
+ def create_server(sCloudObj, hParams)
106
+ name = hParams[:server_name]
107
+ begin
108
+ PrcLib.info('boot: meta-data provided.') if hParams[:meta_data]
109
+ PrcLib.info('boot: user-data provided.') if hParams[:user_data]
110
+ PrcLib.state('creating server %s', name)
111
+ server = controller_create(sCloudObj)
112
+ PrcLib.info("%s '%s' created.", sCloudObj, name)
113
+ rescue => e
114
+ PrcLib.fatal(1, "Unable to create server '%s'", name, e)
115
+ end
116
+ server
117
+ end
118
+
119
+ def forj_get_server_log(sCloudObj, sId, _hParams)
120
+ ssl_error_obj = SSLErrorMgt.new
121
+ begin
122
+ controller_get(sCloudObj, sId)
123
+ rescue => e
124
+ retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,35 @@
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
+ # It requires Core objects to be defined + default ForjProcess functions.
18
+
19
+ # Define framework object on BaseDefinition
20
+ class Lorj
21
+ # ************************************ SERVER Console Object
22
+ # Object representing the console log attached to a server
23
+ class BaseDefinition
24
+ define_obj(:server_log,
25
+
26
+ :get_e => :forj_get_server_log
27
+ )
28
+
29
+ obj_needs :CloudObject, :server
30
+ obj_needs :data, :log_lines
31
+ undefine_attribute :name
32
+ undefine_attribute :id
33
+ def_attribute :output
34
+ end
35
+ end