lorj 0.1.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 (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,183 @@
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
+
19
+ # create a forj.log file in ~/.hpcloud/forj.log
20
+
21
+ require 'rubygems'
22
+ require 'logger'
23
+ require 'ansi'
24
+ require 'ansi/logger'
25
+
26
+ #
27
+ # PrcLib module
28
+ #
29
+ module PrcLib
30
+
31
+ class Logging
32
+ # Class used to create 2 log object, in order to keep track of error in a log file and change log output to OUTPUT on needs (option flags).
33
+
34
+ attr_reader :level
35
+
36
+ def initialize()
37
+
38
+ if not PrcLib.app_name
39
+ PrcLib.app_name = "Lorj"
40
+ end
41
+
42
+ if not PrcLib.data_path
43
+ PrcLib.data_path = File.expand_path(File.join("~", ".%s" % PrcLib.app_name))
44
+ end
45
+
46
+ sLogFile = PrcLib.log_file
47
+ sLogFile = File.join(PrcLib.data_path, "%s.log" % PrcLib.app_name) if PrcLib.log_file.nil?
48
+
49
+ @oFileLogger = Logger.new(sLogFile, 'weekly')
50
+ @oFileLogger.level = Logger::DEBUG
51
+ @oFileLogger.formatter = proc do |severity, datetime, progname, msg|
52
+ "#{progname} : #{datetime}: #{severity}: #{msg} \n"
53
+ end
54
+
55
+ @oOutLogger = Logger.new(STDOUT)
56
+ @level = (PrcLib.level.nil? ? Logger::WARN : PrcLib.level)
57
+ @oOutLogger.level = @level
58
+ @oOutLogger.formatter = proc do |severity, datetime, progname, msg|
59
+ case severity
60
+ when 'ANY'
61
+ str = "#{msg} \n"
62
+ when "ERROR", "FATAL"
63
+ str = ANSI.bold(ANSI.red("#{severity}!!!")) + ": #{msg} \n"
64
+ when "WARN"
65
+ str = ANSI.bold(ANSI.yellow("WARNING")) + ": #{msg} \n"
66
+ else
67
+ str = "#{severity}: #{msg} \n"
68
+ end
69
+ str
70
+ end
71
+ PrcLib.log_file = sLogFile
72
+ end
73
+
74
+ def info?
75
+ return(@oOutLogger.info?)
76
+ end
77
+
78
+ def debug?
79
+ return(@oOutLogger.debug?)
80
+ end
81
+
82
+ def error?
83
+ return(@oOutLogger.error?)
84
+ end
85
+
86
+ def fatal?
87
+ return(@oOutLogger.fatal?)
88
+ end
89
+
90
+ def info(message)
91
+ @oOutLogger.info(message + ANSI.clear_line)
92
+ @oFileLogger.info(message)
93
+ end
94
+
95
+ def debug(message)
96
+ @oOutLogger.debug(message + ANSI.clear_line)
97
+ @oFileLogger.debug(message)
98
+ end
99
+
100
+ def error(message)
101
+ @oOutLogger.error(message + ANSI.clear_line)
102
+ @oFileLogger.error(message)
103
+ end
104
+
105
+ def fatal(message, e)
106
+ @oOutLogger.fatal(message + ANSI.clear_line)
107
+ @oFileLogger.fatal("%s\n%s\n%s" % [message, e.message, e.backtrace.join("\n")]) if e
108
+ @oFileLogger.fatal(message)
109
+ end
110
+
111
+ def warn(message)
112
+ @oOutLogger.warn(message + ANSI.clear_line)
113
+ @oFileLogger.warn(message)
114
+ end
115
+
116
+ def set_level(level)
117
+ @level = level
118
+ @oOutLogger.level = level
119
+ end
120
+
121
+ def unknown(message)
122
+ @oOutLogger.unknown(message + ANSI.clear_line)
123
+ end
124
+
125
+ end
126
+
127
+ module_function
128
+
129
+ def log_object()
130
+ if PrcLib.log.nil?
131
+ PrcLib.log = PrcLib::Logging.new
132
+ else
133
+ PrcLib.log
134
+ end
135
+ end
136
+
137
+ def message(message)
138
+ log_object.unknown(message)
139
+ end
140
+
141
+ def info(message)
142
+ log_object.info(message)
143
+ nil
144
+ end
145
+
146
+ def debug(message)
147
+ log_object.debug(message)
148
+ nil
149
+ end
150
+
151
+ def warning(message)
152
+ log_object.warn(message)
153
+ nil
154
+ end
155
+
156
+ def error(message)
157
+ log_object.error(message)
158
+ nil
159
+ end
160
+
161
+ def fatal(rc, message, e = nil)
162
+ log_object.fatal(message, e)
163
+ puts 'Issues found. Please fix it and retry. Process aborted.'
164
+ exit rc
165
+ end
166
+
167
+ def set_level(level)
168
+ log_object.set_level(level)
169
+ nil
170
+ end
171
+
172
+ def state(message)
173
+ print("%s ...%s\r" % [message, ANSI.clear_line]) if log_object.level <= Logger::INFO
174
+ nil
175
+ end
176
+
177
+ def high_level_msg(message)
178
+ # Not DEBUG and not INFO. Just printed to the output.
179
+ print ("%s" % [message]) if log_object.level > 1
180
+ nil
181
+ end
182
+
183
+ end
data/lib/prc.rb ADDED
@@ -0,0 +1,108 @@
1
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.module Lorj
14
+
15
+ require 'fileutils'
16
+ require 'logger'
17
+
18
+
19
+ module PrcLib
20
+
21
+ def PrcLib.dir_exists?(path)
22
+ if File.exists?(path)
23
+ if not File.directory?(path)
24
+ msg = "'%s' is not a directory. Please fix it." % path
25
+ unless log_object.nil?
26
+ log_object.fatal(1, msg)
27
+ else
28
+ raise msg
29
+ end
30
+ end
31
+ if not File.readable?(path) or not File.writable?(path) or not File.executable?(path)
32
+ msg = "%s is not a valid directory. Check permissions and fix it." % path
33
+ unless log_object.nil?
34
+ log_object.fatal(1, msg)
35
+ else
36
+ raise msg
37
+ end
38
+ end
39
+ return true
40
+ end
41
+ false
42
+ end
43
+
44
+
45
+ def PrcLib.ensure_dir_exists(path)
46
+ if not dir_exists?(path)
47
+ FileUtils.mkpath(path) if not File.directory?(path)
48
+ end
49
+ end
50
+
51
+
52
+ class << self
53
+ attr_accessor :log, :core_level
54
+ end
55
+
56
+ module_function
57
+
58
+ def data_path= v
59
+ @data_path = File.expand_path(v) if not @data_path
60
+ PrcLib.ensure_dir_exists(@data_path)
61
+ end
62
+
63
+ def data_path
64
+ @data_path
65
+ end
66
+
67
+ def app_name= v
68
+ @app_name = v if not @app_name
69
+ end
70
+
71
+ def app_name
72
+ @app_name
73
+ end
74
+
75
+ def app_defaults= v
76
+ @app_defaults = File.expand_path(v) if not @app_defaults
77
+ end
78
+
79
+ def app_defaults
80
+ @app_defaults
81
+ end
82
+
83
+ def log_file= v
84
+ sFile = File.basename(v)
85
+ sDir = File.dirname(File.expand_path(v))
86
+ if not File.exists?(sDir)
87
+ raise "'%s' doesn't exist. Unable to create file '%s'" % [sDir, sFile]
88
+ end
89
+ @log_file = File.join(sDir, sFile)
90
+ end
91
+
92
+ def log_file
93
+ @log_file
94
+ end
95
+
96
+ def level= v
97
+
98
+ @level = v
99
+ unless PrcLib.log.nil?
100
+ PrcLib.set_level(v)
101
+ end
102
+ end
103
+
104
+ def level
105
+ @level
106
+ end
107
+
108
+ end
@@ -0,0 +1,419 @@
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
+
18
+ # This class describes how to process some actions, and will do everything prior
19
+ # this task to make it to work.
20
+
21
+ require 'fog' # We use fog to access HPCloud
22
+
23
+ $HPCLOUD_PATH = File.expand_path(File.dirname(__FILE__))
24
+
25
+ require File.join($HPCLOUD_PATH, "compute.rb")
26
+ require File.join($HPCLOUD_PATH, "network.rb")
27
+ require File.join($HPCLOUD_PATH, "security_groups.rb")
28
+
29
+ # Defines Meta HPCloud object
30
+ class Hpcloud < BaseDefinition
31
+
32
+ define_obj :services
33
+ obj_needs :data, :account_id, :mapping => :hp_access_key
34
+ obj_needs :data, :account_key, :mapping => :hp_secret_key
35
+ obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
36
+ obj_needs :data, :tenant, :mapping => :hp_tenant_id
37
+ obj_needs :data, ":excon_opts/:connect_timeout", :default_value => 30
38
+ obj_needs :data, ":excon_opts/:read_timeout", :default_value => 240
39
+ obj_needs :data, ":excon_opts/:write_timeout", :default_value => 240
40
+
41
+ # Defines Object structure and function stored on the Hpcloud class object.
42
+ # Compute Object
43
+ define_obj :compute_connection
44
+ # Defines Data used by compute.
45
+
46
+ obj_needs :data, :account_id, :mapping => :hp_access_key
47
+ obj_needs :data, :account_key, :mapping => :hp_secret_key
48
+ obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
49
+ obj_needs :data, :tenant, :mapping => :hp_tenant_id
50
+ obj_needs :data, :compute, :mapping => :hp_avl_zone
51
+
52
+ define_obj :network_connection
53
+ obj_needs :data, :account_id, :mapping => :hp_access_key
54
+ obj_needs :data, :account_key, :mapping => :hp_secret_key
55
+ obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
56
+ obj_needs :data, :tenant, :mapping => :hp_tenant_id
57
+ obj_needs :data, :network, :mapping => :hp_avl_zone
58
+
59
+ # Forj predefine following query mapping, used by ForjProcess
60
+ # id => id, name => name
61
+ # If we need to add another mapping, add
62
+ # query_mapping :id => :MyID
63
+ # If the query is not push through and Hash object, the Provider
64
+ # will needs to create his own mapping function.
65
+ define_obj :network
66
+ query_mapping :external, :router_external
67
+
68
+ define_obj :rule
69
+ obj_needs :data, :dir, :mapping => :direction
70
+ attr_value_mapping :IN, 'ingress'
71
+ attr_value_mapping :OUT, 'egress'
72
+
73
+ obj_needs :data, :proto, :mapping => :protocol
74
+ obj_needs :data, :port_min, :mapping => :port_range_min
75
+ obj_needs :data, :port_max, :mapping => :port_range_max
76
+ obj_needs :data, :addr_map, :mapping => :remote_ip_prefix
77
+ obj_needs :data, :sg_id, :mapping => :security_group_id
78
+
79
+ get_attr_mapping :dir, :direction
80
+ get_attr_mapping :proto, :protocol
81
+ get_attr_mapping :port_min, :port_range_min
82
+ get_attr_mapping :port_max, :port_range_max
83
+ get_attr_mapping :addr_map, :remote_ip_prefix
84
+ get_attr_mapping :sg_id, :security_group_id
85
+
86
+ define_obj :keypairs
87
+
88
+ undefine_attribute :id # Do not return any predefined ID
89
+
90
+ # ************************************ Router Object
91
+ define_obj :router
92
+
93
+ obj_needs_optional
94
+ obj_needs :data, :router_name, :mapping => :name
95
+ # The FORJ gateway_network_id is extracted from Fog::HP::Network::Router[:external_gateway_info][:network_id]
96
+ obj_needs :data, :external_gateway_id, :mapping => [:external_gateway_info, 'network_id' ]
97
+
98
+ get_attr_mapping :gateway_network_id, [:external_gateway_info, 'network_id']
99
+
100
+ # ************************************ SERVER Object
101
+ define_obj :server
102
+ get_attr_mapping :status, :state
103
+ attr_value_mapping :create, "BUILD"
104
+ attr_value_mapping :boot, :boot
105
+ attr_value_mapping :active, "ACTIVE"
106
+
107
+ # ************************************ SERVER log Object
108
+ define_obj :server_log
109
+
110
+ # Excon::Response object type
111
+ get_attr_mapping :output, "output"
112
+
113
+ # ************************************* Public IP Object
114
+ define_obj :public_ip
115
+ get_attr_mapping :server_id, :instance_id
116
+ get_attr_mapping :public_ip, :ip
117
+
118
+ # defines setup Cloud data (:account => true for setup)
119
+ define_data(:account_id, {
120
+ :account => true,
121
+ :desc => 'HPCloud Access Key (From horizon, user drop down, manage keys)',
122
+ :validate => /^[A-Z0-9]*$/
123
+ })
124
+ define_data(:account_key, {
125
+ :account => true,
126
+ :desc => 'HPCloud secret Key (From horizon, user drop down, manage keys)',
127
+ :encrypted => false,
128
+ :validate => /^.+/
129
+ })
130
+ define_data(:auth_uri, {
131
+ :account => true,
132
+ :desc => 'HPCloud Authentication service URL (default is HP Public cloud)',
133
+ :validate => /^http(s)?:\/\/.*$/,
134
+ :default_value => "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/"
135
+ })
136
+ define_data(:tenant, {
137
+ :account => true,
138
+ :desc => 'HPCloud Tenant ID (from horizon, identity, projecs, Project ID)',
139
+ :validate => /^[0-9]+$/
140
+ })
141
+
142
+ define_data(:compute, {
143
+ :account => true,
144
+ :desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)',
145
+ :depends_on => [:account_id, :account_key, :auth_uri,:tenant ],
146
+ :list_values => {
147
+ :query_type => :controller_call,
148
+ :object => :services,
149
+ :query_call => :get_services,
150
+ :query_params => { :list_services => [:Compute, :compute] },
151
+ :validate => :list_strict
152
+ }
153
+ })
154
+
155
+ define_data(:network, {
156
+ :account => true,
157
+ :desc => 'HPCloud Network service zone (Ex: region-a.geo-1)',
158
+ :depends_on => [:account_id, :account_key, :auth_uri,:tenant ],
159
+ :list_values => {
160
+ :query_type => :controller_call,
161
+ :object => :services ,
162
+ :query_call => :get_services,
163
+ :query_params => { :list_services => [:Networking, :network] },
164
+ :validate => :list_strict
165
+ }
166
+ })
167
+
168
+ data_value_mapping 'xsmall', "standard.xsmall"
169
+ data_value_mapping 'small', "standard.small"
170
+ data_value_mapping 'medium', "standard.medium"
171
+ data_value_mapping 'large', "standard.large"
172
+ data_value_mapping 'xlarge', "standard.xlarge"
173
+
174
+
175
+ end
176
+
177
+ # Following class describe how FORJ should handle HP Cloud objects.
178
+ # Except Cloud connection, all HPCloud objects management are described/called in HP* modules.
179
+ class HpcloudController < BaseController
180
+
181
+ def connect(sObjectType, hParams)
182
+ case sObjectType
183
+ when :services
184
+ Fog::HP.authenticate_v2(hParams[:hdata], hParams[:excon_opts])
185
+ when :compute_connection
186
+ Fog::Compute.new(hParams[:hdata].merge({:provider => :hp,:version => 'v2'}))
187
+ when :network_connection
188
+ Fog::HP::Network.new(hParams[:hdata])
189
+ else
190
+ forjError "'%s' is not a valid object for 'connect'" % sObjectType
191
+ end
192
+ end
193
+
194
+ def create(sObjectType, hParams)
195
+ case sObjectType
196
+ when :public_ip
197
+ required?(hParams, :compute_connection)
198
+ required?(hParams, :server)
199
+ HPCompute.server_assign_address(hParams[:compute_connection], hParams[:server])
200
+ when :server
201
+ required?(hParams, :compute_connection)
202
+ required?(hParams, :image)
203
+ required?(hParams, :network)
204
+ required?(hParams, :flavor)
205
+ required?(hParams, :keypairs)
206
+ required?(hParams, :security_groups)
207
+ required?(hParams, :server_name)
208
+ HPCompute.create_server(
209
+ hParams[:compute_connection],
210
+ hParams[:server_name], hParams[:security_groups],
211
+ hParams[:image], hParams[:network],
212
+ hParams[:flavor], hParams[:keypairs],
213
+ hParams[:user_data], hParams[:meta_data]
214
+ )
215
+ when :image
216
+ required?(hParams, :compute_connection)
217
+ required?(hParams, :image_name)
218
+ HPCompute.get_image(hParams[:compute_connection], hParams[:image_name])
219
+ when :network
220
+ required?(hParams, :network_connection)
221
+ required?(hParams, :network_name)
222
+ HPNetwork.create_network(hParams[:network_connection], hParams[:network_name])
223
+ when :subnetwork
224
+ required?(hParams, :network_connection)
225
+ required?(hParams, :network)
226
+ required?(hParams, :subnetwork_name)
227
+ HPNetwork.create_subnetwork(hParams[:network_connection], hParams[:network], hParams[:subnetwork_name])
228
+ when :security_groups
229
+ required?(hParams, :network_connection)
230
+ required?(hParams, :security_group)
231
+ HPSecurityGroups.create_sg(hParams[:network_connection], hParams[:security_group], hParams[:sg_desc])
232
+ when :keypairs
233
+ required?(hParams, :compute_connection)
234
+ required?(hParams, :keypair_name)
235
+ required?(hParams, :public_key)
236
+ HPKeyPairs.create_keypair(hParams[:compute_connection], hParams[:keypair_name], hParams[:public_key])
237
+ when :router
238
+ required?(hParams, :network_connection)
239
+ required?(hParams, :router_name)
240
+ #~ if hParams[:external_gateway_id]
241
+ #~ hParams[:hdata][:external_gateway_info] = { 'network_id' => hParams[:external_gateway_id] }
242
+ #~ end
243
+ hParams[:hdata] = hParams[:hdata].merge(:admin_state_up => true) # Forcelly used admin_status_up to true.
244
+
245
+ HPNetwork.create_router(hParams[:network_connection], hParams[:hdata])
246
+ when :rule
247
+ required?(hParams, :network_connection)
248
+ required?(hParams, :security_groups)
249
+ HPSecurityGroups.create_rule(hParams[:network_connection], hParams[:hdata])
250
+ when :router_interface
251
+ required?(hParams, :router)
252
+ required?(hParams, :subnetwork)
253
+ HPNetwork.add_interface(hParams[:router], hParams[:subnetwork])
254
+ else
255
+ forjError "'%s' is not a valid object for 'create'" % sObjectType
256
+ end
257
+ end
258
+
259
+ # This function return a collection which have to provide:
260
+ # functions: [], length, each
261
+ # Used by network process.
262
+ def query(sObjectType, sQuery, hParams)
263
+ case sObjectType
264
+ when :public_ip
265
+ required?(hParams, :compute_connection)
266
+ required?(hParams, :server)
267
+ HPCompute.query_server_assigned_addresses(hParams[:compute_connection], hParams[:server], sQuery)
268
+ when :server
269
+ required?(hParams, :compute_connection)
270
+ HPCompute.query_server(hParams[:compute_connection], sQuery)
271
+ when :image
272
+ required?(hParams, :compute_connection)
273
+ HPCompute.query_image(hParams[:compute_connection], sQuery)
274
+ when :network
275
+ required?(hParams, :network_connection)
276
+ HPNetwork.query_network(hParams[:network_connection], sQuery)
277
+ when :subnetwork
278
+ required?(hParams, :network_connection)
279
+ HPNetwork.query_subnetwork(hParams[:network_connection], sQuery)
280
+ when :router
281
+ required?(hParams, :network_connection)
282
+ HPNetwork.query_router(hParams[:network_connection], sQuery)
283
+ when :port
284
+ required?(hParams, :network_connection)
285
+ HPNetwork.query_port(hParams[:network_connection], sQuery)
286
+ when :security_groups
287
+ required?(hParams, :network_connection)
288
+ HPSecurityGroups.query_sg(hParams[:network_connection], sQuery)
289
+ when :rule
290
+ required?(hParams, :network_connection)
291
+ HPSecurityGroups.query_rule(hParams[:network_connection], sQuery)
292
+ when :keypairs
293
+ required?(hParams, :compute_connection)
294
+ HPKeyPairs.query_keypair(hParams[:compute_connection], sQuery)
295
+ when :flavor
296
+ required?(hParams, :compute_connection)
297
+ HPCompute.query_flavor(hParams[:compute_connection], sQuery)
298
+ else
299
+ forjError "'%s' is not a valid object for 'query'" % sObjectType
300
+ end
301
+ end
302
+
303
+ def delete(sObjectType, hParams)
304
+ case sObjectType
305
+ when :network
306
+ HPNetwork.delete_network(hParams[:network_connection], hParams[:network])
307
+ when :rule
308
+ HPSecurityGroups.delete_rule(hParams[:network_connection], hParams[:id])
309
+ hParams[:network_connection].security_group_rules.get(hParams[:id]).destroy
310
+ else
311
+ nil
312
+ end
313
+ end
314
+
315
+ def get(sObjectType, sUniqId, hParams)
316
+ case sObjectType
317
+ when :server_log
318
+ required?(hParams, :server)
319
+
320
+ hParams[:server].console_output(sUniqId)
321
+ when :server
322
+ required?(hParams, :compute_connection)
323
+ HPCompute.get_server(hParams[:compute_connection], sUniqId)
324
+ when :image
325
+ required?(hParams, :compute_connection)
326
+ HPCompute.get_image(hParams[:compute_connection], sUniqId)
327
+ when :network
328
+ required?(hParams, :network_connection)
329
+ HPNetwork.get_network(hParams[:network_connection], sUniqId)
330
+ else
331
+ forjError "'%s' is not a valid object for 'get'" % sObjectType
332
+ end
333
+ end
334
+
335
+ def query_each(oFogObject)
336
+ case oFogObject.class.to_s
337
+ when "Fog::HP::Network::Networks"
338
+ oFogObject.each { | value |
339
+ yield(value)
340
+ }
341
+ else
342
+ forjError "'%s' is not a valid list for 'each'" % oFogObject.class
343
+ end
344
+ end
345
+
346
+ def get_attr(oControlerObject, key)
347
+ begin
348
+ if oControlerObject.is_a?(Excon::Response)
349
+ rhGet(oControlerObject.data, :body, key)
350
+ else
351
+ attributes = oControlerObject.attributes
352
+ raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
353
+ rhGet(attributes, key)
354
+ end
355
+ rescue => e
356
+ forjError "Unable to map '%s'. %s" % [key, e.message]
357
+ end
358
+ end
359
+
360
+ def set_attr(oControlerObject, key, value)
361
+ begin
362
+ raise "No set feature for '%s'" % oControlerObject.class if oControlerObject.is_a?(Excon::Response)
363
+ attributes = oControlerObject.attributes
364
+ raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
365
+ Lorj::rhSet(attributes, value, key)
366
+ rescue => e
367
+ forjError "Unable to map '%s' on '%s'" % [key, sObjectType]
368
+ end
369
+ end
370
+
371
+
372
+ def update(sObjectType, oObject, hParams)
373
+ case sObjectType
374
+ when :router
375
+ forjError "Object to update is nil" if oObject.nil?
376
+
377
+ HPNetwork.update_router(oObject[:object])
378
+ else
379
+ forjError "'%s' is not a valid list for 'update'" % oFogObject.class
380
+ end
381
+ end
382
+
383
+ # This function requires to return an Array of values or nil.
384
+ def get_services(sObjectType, oParams)
385
+ case sObjectType
386
+ when :services
387
+ # oParams[sObjectType] will provide the controller object.
388
+ # This one can be interpreted only by controller code,
389
+ # except if controller declares how to map with this object.
390
+ # Processes can deal only process mapped data.
391
+ # Currently there is no services process function. No need to map.
392
+ hServices = oParams[:services]
393
+ if not oParams[:list_services].is_a?(Array)
394
+ hServiceToFind = [oParams[:list_services]]
395
+ else
396
+ hServiceToFind = oParams[:list_services]
397
+ end
398
+ # Search for service. Ex: Can be :Networking or network. I currently do not know why...
399
+ hSearchServices= rhGet(hServices, :service_catalog)
400
+ sService = nil
401
+ hServiceToFind.each { | sServiceElem |
402
+ if hSearchServices.key?(sServiceElem)
403
+ sService = sServiceElem
404
+ break
405
+ end
406
+ }
407
+
408
+ forjError "Unable to find services %s" % hServiceToFind if sService.nil?
409
+ result = rhGet(hServices, :service_catalog, sService).keys
410
+ result.delete("name")
411
+ result.each_index { | iIndex |
412
+ result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
413
+ }
414
+ return result
415
+ else
416
+ forjError "'%s' is not a valid object for 'get_services'" % sObjectType
417
+ end
418
+ end
419
+ end