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
@@ -1,605 +0,0 @@
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
- # This file describe generic process to create/query/get/delete Cloud objects.
18
- # forj_* function are handler, predefined by cloud_data_pref.rb
19
- # The process functions communicates with config, object or controler(provider controler)
20
- #
21
- # 'config' is the configuration system which implements:
22
- # - get(key): Get the value to the associated key
23
- # [key] is the 'set' equivalent
24
- # - set(key, value): Set a value to a key.
25
- # [key] = value Is the 'set' equivalent
26
- #
27
- # 'object' contains Object definition, Object manipulation. It implements:
28
- # - query_map(sCloudObj, sQuery): transform Forj Object query request to
29
- # a Provider controler query request
30
- # The result of this function is usually sent to
31
- # the controler query function.
32
- #
33
- # - get_attr(oObject, key): Read the object key from the object.
34
- #
35
- # Providers can redefine any kind of handler if needed.
36
-
37
- # ---------------------------------------------------------------------------
38
- # Network/Subnetwork Management
39
- # ---------------------------------------------------------------------------
40
- class CloudProcess
41
- # Process Query handler
42
- def forj_query_network(sCloudObj, sQuery, hParams)
43
-
44
-
45
- # Call Provider query function
46
- controller_query(sObjectType, sControlerQuery)
47
- end
48
-
49
- # Process Create handler
50
- def forj_get_or_create_network(sCloudObj, hParams)
51
-
52
- PrcLib.state("Searching for network '%s'" % [hParams[:network_name]])
53
- networks = find_network(sCloudObj, hParams)
54
- if networks.length == 0
55
- network = create_network(sCloudObj, hParams)
56
- else
57
- network = networks[0]
58
- end
59
- register(network)
60
-
61
- # Attaching if missing the subnet.
62
- # Creates an object subnet, attached to the network.
63
- if not hParams[:subnetwork_name]
64
- hParams[:subnetwork_name] = 'sub-' + hParams[:network_name]
65
- config[:subnetwork_name] = hParams[:subnetwork_name]
66
- end
67
-
68
- #object.Create(:subnetwork)
69
- Create(:subnetwork)
70
-
71
- network
72
-
73
- end
74
-
75
- # Process Delete handler
76
- def forj_delete_network(sCloudObj, hParams)
77
- begin
78
- oProvider.delete(sCloudObj, hParams)
79
- rescue => e
80
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
81
- end
82
- end
83
-
84
- def forj_get_network(sCloudObj, sID, hParams)
85
- begin
86
- oProvider.get(sCloudObj, sID, hParams)
87
- rescue => e
88
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
89
- end
90
- end
91
-
92
- # Network Process internal functions #
93
- #------------------------------------#
94
-
95
- # Network creation
96
- # It returns:
97
- # nil or Provider Object
98
- def create_network(sCloudObj, hParams)
99
- name = hParams[:network_name]
100
- begin
101
- PrcLib.state("Creating network '%s'" % [name])
102
- network = controller_create(sCloudObj)
103
- PrcLib.info("Network '%s' created" % [network[:name]])
104
- rescue => e
105
- PrcLib.fatal(1, "Unable to create network '%s'" % [name, e])
106
- end
107
- network
108
- end
109
-
110
- # Search for a network from his name.
111
- # Name may be unique in project context, but not in the cloud system
112
- # It returns:
113
- # nil or Provider Object
114
- def find_network(sCloudObj, hParams)
115
- begin
116
- # retrieve the Provider collection object.
117
- sQuery = {:name => hParams[:network_name]}
118
- oList = controller_query(sCloudObj, sQuery)
119
- query_single(sCloudObj, oList, sQuery, hParams[:network_name])
120
- rescue => e
121
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
122
- end
123
- end
124
-
125
- def forj_get_or_create_subnetwork(sCloudObj, hParams)
126
-
127
- PrcLib.state("Searching for sub-network attached to network '%s'" % [hParams[:network, :name]])
128
- #######################
129
- begin
130
- sQuery = { :network_id => hParams[:network, :id] }
131
- subnets = controller_query(:subnetwork, sQuery)
132
- rescue => e
133
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
134
- end
135
- if subnets
136
- case subnets.length()
137
- when 0
138
- PrcLib.info("No subnet found from '%s' network" % [hParams[:network, :name]])
139
- subnet = ForjLib::Data.new
140
- when 1
141
- PrcLib.info("Found '%s' subnet from '%s' network" % [subnets[0, :name], hParams[:network, :name]])
142
- subnet = subnets[0]
143
- else
144
- PrcLib.warning("Several subnet was found on '%s'. Choosing the first one = '%s'" % [hParams[:network, :name], subnets[0, :name]])
145
- subnet = subnets[0]
146
- end
147
- end
148
- if not subnet or subnets.length == 0
149
- # Create the subnet
150
- begin
151
- subnet = create_subnet(sCloudObj, hParams)
152
- rescue => e
153
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
154
- end
155
- end
156
- register(subnet)
157
- subnet
158
- end
159
-
160
- def create_subnet(sCloudObj, hParams)
161
- name = hParams[:subnetwork_name]
162
- PrcLib.state("Creating subnet '%s'" % [name])
163
- begin
164
- subnet = controller_create(sCloudObj)
165
- PrcLib.info("Subnet '%s' created." % [subnet[:name]])
166
- rescue => e
167
- PrcLib.fatal(1, "Unable to create '%s' subnet." % name, e)
168
- end
169
- subnet
170
- end
171
-
172
- def delete_subnet()
173
-
174
- oNetworkConnect = get_cloudObj(:network_connection)
175
- oSubNetwork = get_cloudObj(:subnetwork)
176
-
177
- PrcLib.state("Deleting subnet '%s'" % [oSubNetwork.name])
178
- begin
179
- provider_delete_subnetwork(oNetworkConnect, oSubNetwork)
180
- oNetworkConnect.subnets.get(oSubNetwork.id).destroy
181
- rescue => e
182
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
183
- end
184
- end
185
- end
186
-
187
- # ---------------------------------------------------------------------------
188
- # Router management
189
- # ---------------------------------------------------------------------------
190
- class CloudProcess
191
- # Process Create handler
192
- def forj_get_or_create_router(sCloudObj, hParams)
193
- oSubNetwork = hParams[:subnetwork]
194
-
195
- if not hParams[:router_name]
196
- config[:router_name] = 'router-%s' % hParams[:network, :name]
197
- hParams[:router_name] = config[:router_name]
198
- end
199
-
200
- router_name = hParams[:router_name]
201
- router_port = get_router_interface_attached(:port, hParams)
202
-
203
- if not router_port or router_port.empty?
204
- # Trying to get router
205
- router = get_router(router_name)
206
- router = create_router(router_name) if not router or router.empty?
207
- create_router_interface(oSubNetwork, router) if router and not router.empty?
208
- else
209
- sQuery = {:id => router_port[:device_id]}
210
- routers = controller_query(:router, sQuery)
211
- case routers.length()
212
- when 1
213
- PrcLib.info("Found router '%s' attached to the network '%s'." % [
214
- routers[0, :name],
215
- hParams[:network, :name]
216
- ])
217
- router = routers[0]
218
- else
219
- PrcLib.warning("Unable to find the router id '%s'" % [ router_port[:device_id]])
220
- router = ForjLib::Data.new
221
-
222
- end
223
- end
224
- router
225
- end
226
-
227
- def forj_update_router(sCloudObj, hParams)
228
- controller_update(sCloudObj)
229
- ################################
230
- #routers[0].external_gateway_info = { 'network_id' => external_network.id }
231
- #routers[0].save
232
-
233
- end
234
-
235
- # Router Process internal functions #
236
- #------------------------------------#
237
-
238
- def get_router(name)
239
- PrcLib.state("Searching for router '%s'" % [name] )
240
- begin
241
- routers = controller_query(:router, {:name => name})
242
- case routers.length()
243
- when 1
244
- routers[0]
245
- else
246
- PrcLib.info("Router '%s' not found." % [ name ] )
247
- ForjLib::Data.new
248
- end
249
- rescue => e
250
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
251
- end
252
- end
253
-
254
- def create_router(router_name, oExternalNetwork = nil)
255
- begin
256
- if oExternalNetwork
257
- sExtNet = get_data(oExternalNetwork, :name)
258
- PrcLib.state("Creating router '%s' attached to the external Network '%s'" % [router_name, sExtNet])
259
- config[:external_gateway_id] = get_data(oExternalNetwork, :id)
260
- else
261
- PrcLib.state("Creating router '%s' without external Network" % [router_name])
262
- end
263
-
264
- router = controller_create(:router)
265
- if oExternalNetwork
266
- PrcLib.info("Router '%s' created and attached to the external Network '%s'." % [router_name, sExtNet])
267
- else
268
- PrcLib.info("Router '%s' created without external Network." % [router_name])
269
- end
270
- rescue => e
271
- raise ForjError.new(), "Unable to create '%s' router\n%s" % [router_name, e.message]
272
- end
273
- router
274
- end
275
-
276
- def delete_router(oNetworkConnect, oRouter)
277
- PrcLib.state("Deleting router '%s'" % [router.name])
278
- begin
279
- #################
280
- provider_delete_router(oNetworkConnect, oRouter)
281
- # oNetworkConnect.routers.get(router.id).destroy
282
- rescue => e
283
- PrcLib.error("Unable to delete '%s' router ID" % router_id, e)
284
- end
285
- end
286
-
287
- # TODO: Move router interface management to hpcloud controller.
288
- # Router interface to connect to the network
289
- def create_router_interface(oSubnet, oRouter)
290
-
291
- PrcLib.state("Attaching subnet '%s' to router '%s'" % [oSubnet[:name], oRouter[:name]])
292
- begin
293
- controller_create(:router_interface)
294
-
295
- #################
296
- #provider_add_interface()
297
- # oRouter.add_interface(oSubnet.id, nil)
298
- rescue => e
299
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
300
- end
301
- end
302
-
303
- def delete_router_interface(oSubnet, oRouter)
304
- PrcLib.state("Removing subnet '%s' from router '%s'" % [oSubnet.name, oRouter.name])
305
- subnet_id = oSubnet.id
306
- begin
307
- #################
308
- oRouter.remove_interface(subnet_id)
309
- rescue => e
310
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
311
- end
312
- end
313
-
314
- def get_router_interface_attached(sCloudObj, hParams)
315
-
316
- oNetwork = hParams[:network]
317
- PrcLib.state("Searching for router port attached to the network '%s'" % [hParams[:network, :name]] )
318
- begin
319
- # Searching for router port attached
320
- #################
321
- sQuery = {:network_id => hParams[:network, :id], :device_owner => 'network:router_interface'}
322
-
323
- ports = controller_query(sCloudObj, sQuery)
324
- case ports.length()
325
- when 0
326
- PrcLib.info("No router port attached to the network '%s'" % [hParams[:network, :name] ])
327
- ForjLib::Data.new
328
- else
329
- PrcLib.info("Found a router port attached to the network '%s' " % [hParams[:network, :name] ] )
330
- ports[0]
331
- end
332
- rescue => e
333
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
334
- end
335
- end
336
-
337
- # Gateway management
338
- def get_gateway(oNetworkConnect, name)
339
-
340
- return nil if not name or not oNetworkConnect
341
-
342
- PrcLib.state("Getting gateway '%s'" % [name])
343
- networks = oNetworkConnect
344
- begin
345
- netty = networks.get(name)
346
- rescue => e
347
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
348
- end
349
- PrcLib.state("Found gateway '%s'" % [name]) if netty
350
- PrcLib.state("Unable to find gateway '%s'" % [name]) if not netty
351
- return netty
352
- end
353
-
354
- def query_external_network(hParams)
355
- PrcLib.state("Identifying External gateway")
356
- begin
357
- # Searching for router port attached
358
- #################
359
- sQuery = { :router_external => true }
360
- networks = controller_query(:network, sQuery)
361
- case networks.length()
362
- when 0
363
- PrcLib.info("No external network")
364
- ForjLib::Data.new
365
- when 1
366
- PrcLib.info("Found external network '%s'." % [networks[0, :name] ] )
367
- networks[0]
368
- else
369
- PrcLib.warn("Found several external networks. Selecting the first one '%s'" % [networks[0, :name]] )
370
- networks[0]
371
- end
372
- rescue => e
373
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
374
- end
375
- end
376
-
377
- end
378
-
379
- # ---------------------------------------------------------------------------
380
- # SecurityGroups management
381
- # ---------------------------------------------------------------------------
382
-
383
- class CloudProcess
384
-
385
- # Process Create handler
386
- def forj_get_or_create_sg(sCloudObj, hParams)
387
- sSGName = hParams[:security_group]
388
- PrcLib.state("Searching for security group '%s'" % [sSGName] )
389
-
390
- security_group = forj_query_sg(sCloudObj, {:name => sSGName}, hParams)
391
- security_group = create_security_group(sCloudObj, hParams) if not security_group
392
- register(security_group)
393
-
394
- PrcLib.info('Configuring Security Group \'%s\'' % [sSGName])
395
- ports = config.get(:ports)
396
-
397
- ports.each do |port|
398
- port = port.to_s if port.class != String
399
- if not (/^\d+(-\d+)?$/ =~ port)
400
- PrcLib.error("Port '%s' is not valid. Must be <Port> or <PortMin>-<PortMax>" % [port])
401
- else
402
- mPortFound = /^(\d+)(-(\d+))?$/.match(port)
403
- portmin = mPortFound[1]
404
- portmax = (mPortFound[3]) ? (mPortFound[3]) : (portmin)
405
- # Need to set runtime data to get or if missing create the required rule.
406
- config[:dir] = :IN
407
- config[:proto] = 'tcp'
408
- config[:port_min] = portmin.to_i
409
- config[:port_max] = portmax.to_i
410
- config[:addr_map] = '0.0.0.0/0'
411
-
412
- #object.Create(:rule)
413
- Create(:rule)
414
- end
415
- end
416
- security_group
417
- end
418
-
419
- # Process Delete handler
420
- def forj_delete_sg(oFC, security_group)
421
- oSSLError=SSLErrorMgt.new
422
- begin
423
- sec_group = get_security_group(oFC, security_group)
424
- oFC.oNetwork.security_groups.get(sec_group.id).destroy
425
- rescue => e
426
- if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
427
- retry
428
- end
429
- end
430
- end
431
-
432
- # Process Query handler
433
- def forj_query_sg(sCloudObj, sQuery, hParams)
434
- oSSLError=SSLErrorMgt.new
435
-
436
- begin
437
- sgroups = controller_query(sCloudObj, sQuery)
438
- rescue => e
439
- if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
440
- retry
441
- end
442
- PrcLib.fatal(1, "Unable to get list of security groups.", e)
443
- end
444
- case sgroups.length()
445
- when 0
446
- PrcLib.info("No security group '%s' found" % [ hParams[:security_group] ] )
447
- nil
448
- when 1
449
- PrcLib.info("Found security group '%s'" % [sgroups[0, :name]])
450
- sgroups[0]
451
- end
452
- end
453
-
454
- # SecurityGroups Process internal functions #
455
- #-------------------------------------------#
456
- def create_security_group(sCloudObj, hParams)
457
- PrcLib.state("Creating security group '%s'" % hParams[:security_group])
458
- begin
459
- sg = controller_create(sCloudObj)
460
- PrcLib.info("Security group '%s' created." % sg[:name])
461
- rescue => e
462
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
463
- end
464
- sg
465
- end
466
-
467
- # Rules handler #
468
- #---------------#
469
-
470
- # Process Delete handler
471
- def forj_delete_security_group_rule(sCloudObj, hParams)
472
-
473
- oSSLError=SSLErrorMgt.new
474
- begin
475
- controller_delete(sCloudObj)
476
- rescue => e
477
- if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
478
- retry
479
- end
480
- end
481
- end
482
-
483
- # Process Query handler
484
- def forj_query_rule(sCloudObj, sQuery, hParams)
485
- sRule = '%s %s:%s - %s to %s' % [ hParams[:dir], hParams[:rule_proto], hParams[:port_min], hParams[:port_max], hParams[:addr_map] ]
486
- PrcLib.state("Searching for rule '%s'" % [ sRule ])
487
- oSSLError = SSLErrorMgt.new
488
- begin
489
- sInfo = {
490
- :items => [:dir, :rule_proto, :port_min, :port_max, :addr_map],
491
- :items_form => '%s %s:%s - %s to %s'
492
- }
493
- oList = controller_query(sCloudObj, sQuery)
494
- query_single(sCloudObj, oList, sQuery, sRule, sInfo)
495
- rescue => e
496
- if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
497
- retry
498
- end
499
- end
500
- end
501
-
502
- # Process Create handler
503
- def forj_get_or_create_rule(sCloudObj, hParams)
504
-
505
- sQuery = {
506
- :dir => hParams[:dir],
507
- :proto => hParams[:proto],
508
- :port_min => hParams[:port_min],
509
- :port_max => hParams[:port_max],
510
- :addr_map => hParams[:addr_map],
511
- :sg_id => hParams[:sg_id]
512
- }
513
-
514
- rules = forj_query_rule(sCloudObj, sQuery, hParams)
515
- if rules.length == 0
516
- create_rule(sCloudObj, hParams)
517
- else
518
- rules[0]
519
- end
520
- end
521
-
522
- # Rules internal #
523
- #----------------#
524
- def create_rule(sCloudObj, hParams)
525
-
526
- sRule = '%s %s:%s - %s to %s' % [ hParams[:dir], hParams[:rule_proto], hParams[:port_min], hParams[:port_max], hParams[:addr_map] ]
527
- PrcLib.state("Creating rule '%s'" % [sRule])
528
- oSSLError=SSLErrorMgt.new
529
- begin
530
- rule = controller_create(sCloudObj)
531
- PrcLib.info("Rule '%s' created." % [sRule])
532
- rescue StandardError => e
533
- if not oSSLError.ErrorDetected(e.message,e.backtrace, e)
534
- retry
535
- end
536
- PrcLib.error 'error creating the rule for port %s' % [sRule]
537
- end
538
- rule
539
- end
540
-
541
- end
542
-
543
- # ---------------------------------------------------------------------------
544
- # External network process attached to a network
545
- # ---------------------------------------------------------------------------
546
- class CloudProcess
547
- def forj_get_or_create_ext_net(sCloudObj, hParams)
548
-
549
- PrcLib.state("Checking router '%s' gateway" % hParams[:router, :name])
550
-
551
- oRouter = hParams[:router]
552
- sRouterName = hParams[:router, :name]
553
- sNetworkId = hParams[:router, :gateway_network_id]
554
- if sNetworkId
555
- external_network = forj_query_external_network(sCloudObj, {:id => sNetworkId}, hParams)
556
- PrcLib.info("Router '%s' is attached to the external gateway '%s'." % [ sRouterName, external_network[:name] ] )
557
- else
558
- PrcLib.info("Router '%s' needs to be attached to an external gateway." % [ sRouterName ] )
559
- PrcLib.state("Attaching")
560
- external_network = forj_query_external_network(:network, {}, hParams)
561
- if not external_network.empty?
562
- oRouter[:gateway_network_id] = external_network[:id]
563
- forj_update_router(:router, hParams)
564
- PrcLib.info("Router '%s' attached to the external network '%s'." % [ sRouterName, external_network[:name] ])
565
- else
566
- PrcLib.fatal(1, "Unable to attach router '%s' to an external gateway. Required for boxes to get internet access. " % [ get_data(:router, :name) ] )
567
- end
568
- end
569
-
570
- # Need to keep the :network object as :external_network object type.
571
- external_network.type = sCloudObj
572
- external_network
573
- end
574
-
575
- def forj_query_external_network(sCloudObj, sQuery, hParams)
576
- PrcLib.state("Identifying External gateway")
577
- begin
578
- # Searching for external network
579
- networks = controller_query(:network, sQuery.merge({ :external => true }))
580
-
581
- case networks.length()
582
- when 0
583
- PrcLib.info("No external network")
584
- nil
585
- when 1
586
- PrcLib.info("Found external network '%s'." % [networks[0, :name] ])
587
- networks[0]
588
- else
589
- PrcLib.warning("Found several external networks. Selecting the first one '%s'" % [networks[0, :name]])
590
- networks[0]
591
- end
592
- rescue => e
593
- PrcLib.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
594
- end
595
- end
596
-
597
- end
598
-
599
- # ---------------------------------------------------------------------------
600
- # Internet network process
601
- # ---------------------------------------------------------------------------
602
- class CloudProcess
603
-
604
-
605
- end