lorj 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/example/students_1/process/students.rb +1 -1
  4. data/example/students_1/student_v1.md +2 -0
  5. data/example/students_1/students.rb +2 -1
  6. data/example/students_2/process/students.rb +1 -1
  7. data/example/students_2/students.rb +4 -2
  8. data/example/students_3/controller/yaml_students_def.rb +1 -1
  9. data/example/students_3/process/students.rb +1 -1
  10. data/example/students_3/student_v3.md +5 -3
  11. data/example/students_3/students.rb +5 -3
  12. data/example/students_4/controller/yaml_students_def.rb +1 -1
  13. data/example/students_4/process/students/definition/students.rb +1 -1
  14. data/example/students_4/students.rb +5 -3
  15. data/example/students_5/controller/yaml_students.rb +1 -1
  16. data/example/students_5/process/students.rb +1 -1
  17. data/example/students_5/student_v5.md +4 -4
  18. data/example/students_5/students.rb +8 -7
  19. data/example/yaml_students/students.rb +4 -4
  20. data/lib/core/core.rb +110 -64
  21. data/lib/core/core_internal.rb +110 -15
  22. data/lib/core/core_object_data.rb +4 -4
  23. data/lib/core/core_process_setup.rb +3 -30
  24. data/lib/core/lorj_data.rb +1 -1
  25. data/lib/core/lorj_keypath.rb +3 -1
  26. data/lib/core/process.rb +67 -0
  27. data/lib/lorj/version.rb +2 -1
  28. data/lib/lorj.rb +3 -4
  29. data/lib/lorj_account.rb +6 -5
  30. data/lib/lorj_config.rb +3 -2
  31. data/lib/providers/templates/compute.rb +1 -1
  32. data/lorj-spec/controllers/mock/mock.rb +144 -0
  33. data/lorj-spec/data.yaml +0 -0
  34. data/lorj-spec/process/mock2_process.rb +48 -0
  35. data/lorj-spec/process/mock_process.rb +48 -0
  36. data/lorj-spec/providers/mock2/mock2.rb +0 -0
  37. data/lorj.gemspec +2 -4
  38. data/spec/05_lorj_keypath_spec.rb +78 -0
  39. data/spec/20_lorj_meta_spec.rb +1 -1
  40. data/spec/21_lorj_processes_spec.rb +115 -0
  41. metadata +27 -42
  42. data/lib/core_process/cloud/process/common.rb +0 -60
  43. data/lib/core_process/cloud/process/connection.rb +0 -92
  44. data/lib/core_process/cloud/process/external_network.rb +0 -90
  45. data/lib/core_process/cloud/process/flavor.rb +0 -97
  46. data/lib/core_process/cloud/process/images.rb +0 -99
  47. data/lib/core_process/cloud/process/internet_network.rb +0 -33
  48. data/lib/core_process/cloud/process/internet_server.rb +0 -29
  49. data/lib/core_process/cloud/process/keypairs.rb +0 -332
  50. data/lib/core_process/cloud/process/network.rb +0 -107
  51. data/lib/core_process/cloud/process/public_ip.rb +0 -102
  52. data/lib/core_process/cloud/process/router.rb +0 -267
  53. data/lib/core_process/cloud/process/rules.rb +0 -120
  54. data/lib/core_process/cloud/process/security_groups.rb +0 -120
  55. data/lib/core_process/cloud/process/server.rb +0 -126
  56. data/lib/core_process/cloud/process/server_log.rb +0 -34
  57. data/lib/core_process/cloud/process/subnetwork.rb +0 -96
  58. data/lib/core_process/cloud_process.rb +0 -30
  59. data/lib/prc_base_config.rb +0 -300
  60. data/lib/prc_core_config.rb +0 -1258
  61. data/lib/prc_section_config.rb +0 -90
  62. data/lib/providers/hpcloud/compute.rb +0 -105
  63. data/lib/providers/hpcloud/hpcloud.rb +0 -462
  64. data/lib/providers/hpcloud/network.rb +0 -115
  65. data/lib/providers/hpcloud/security_groups.rb +0 -68
  66. data/lib/providers/openstack/openstack.rb +0 -410
  67. data/lib/providers/openstack/openstack_create.rb +0 -205
  68. data/lib/providers/openstack/openstack_delete.rb +0 -28
  69. data/lib/providers/openstack/openstack_get.rb +0 -39
  70. data/lib/providers/openstack/openstack_process.rb +0 -26
  71. data/lib/providers/openstack/openstack_query.rb +0 -96
  72. data/lib/providers/openstack/openstack_update.rb +0 -35
  73. data/lib/rh.rb +0 -426
  74. data/spec/01_hash_rh_spec.rb +0 -282
  75. data/spec/02_prc_base_config_spec.rb +0 -227
  76. data/spec/03_prc_section_config_spec.rb +0 -196
  77. data/spec/04_prc_core_config_spec.rb +0 -325
@@ -1,90 +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
- require 'rubygems'
18
- require 'yaml'
19
-
20
- module PRC
21
- # SectionConfig class layer based on BaseConfig.
22
- #
23
- # It supports a data_options :section for #[], #[]=, etc...
24
- #
25
- class SectionConfig < PRC::BaseConfig
26
- # Get the value of a specific key under a section.
27
- # You have to call #data_options(:section => 'MySection')
28
- #
29
- # * *Args* :
30
- # - +keys+ : keys to get values from a section set by data_options.
31
- # If section is not set, it will use :default
32
- # * *Returns* :
33
- # - key value.
34
- # * *Raises* :
35
- # Nothing
36
- def [](*keys)
37
- return nil if keys.length == 0
38
- return p_get(:default, *keys) if @data_options[:section].nil?
39
- p_get(@data_options[:section], *keys)
40
- end
41
-
42
- # Set the value of a specific key under a section.
43
- # You have to call #data_options(:section => 'MySection')
44
- #
45
- # * *Args* :
46
- # - +keys+ : keys to get values from a section set by data_options.
47
- # If section is not set, it will use :default
48
- # * *Returns* :
49
- # - key value.
50
- # * *Raises* :
51
- # Nothing
52
- def []=(*keys, value)
53
- return nil if keys.length == 0
54
- return p_set(:default, *keys, value) if @data_options[:section].nil?
55
- p_set(@data_options[:section], *keys, value)
56
- end
57
-
58
- # Check key existence under a section.
59
- # You have to call #data_options(:section => 'MySection')
60
- #
61
- # * *Args* :
62
- # - +keys+ : keys to get values from a section set by data_options.
63
- # If section is not set, it will use :default
64
- # * *Returns* :
65
- # - key value.
66
- # * *Raises* :
67
- # Nothing
68
- def exist?(*keys)
69
- return nil if keys.length == 0
70
- return p_exist?(:default, *keys) if @data_options[:section].nil?
71
- p_exist?(@data_options[:section], *keys)
72
- end
73
-
74
- # remove the key under a section.
75
- # You have to call #data_options(:section => 'MySection')
76
- #
77
- # * *Args* :
78
- # - +keys+ : keys to get values from a section set by data_options.
79
- # If section is not set, it will use :default
80
- # * *Returns* :
81
- # - key value.
82
- # * *Raises* :
83
- # Nothing
84
- def del(*keys)
85
- return nil if keys.length == 0
86
- return p_del(:default, *keys) if @data_options[:section].nil?
87
- p_del(@data_options[:section], *keys)
88
- end
89
- end
90
- end
@@ -1,105 +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
- # Defined HPCloud controller.
18
- module HPCompute
19
- def self.get_server(oComputeConnect, sId)
20
- oComputeConnect.servers.get(sId)
21
- end
22
-
23
- def self.query_addresses(oComputeConnect, sQuery)
24
- oComputeConnect.addresses.all(sQuery)
25
- end
26
-
27
- def self.query_server(oComputeConnect, sQuery)
28
- oComputeConnect.servers.all(sQuery)
29
- end
30
-
31
- def self.query_image(oComputeConnect, sQuery)
32
- # HP Fog query is exact matching. No way to filter with a Regexp
33
- # Testing it and filtering it.
34
- # TODO: Be able to support Regexp in queries then extract all and filter.
35
- oComputeConnect.images.all(sQuery)
36
- end
37
-
38
- def self.query_flavor(oComputeConnect, sQuery)
39
- oComputeConnect.flavors.all(sQuery)
40
- end
41
-
42
- def self.create_server(oComputeConnect, options, oUser_data, oMeta_data)
43
- if oUser_data
44
- options[:user_data_encoded] = Base64.strict_encode64(oUser_data)
45
- end
46
- options[:metadata] = oMeta_data if oMeta_data
47
- server = oComputeConnect.servers.create(options)
48
- HPCompute.get_server(oComputeConnect, server.id) if server
49
- end
50
-
51
- def self.query_server_assigned_addresses(oComputeConnect, _oServer, sQuery)
52
- # CloudProcess used a simplified way to manage IPs.
53
- # Following is the translation to get the public IPs for the server
54
-
55
- result = []
56
- addresses = oComputeConnect.addresses.all
57
- addresses.each do |oElem|
58
- is_found = true
59
- sQuery.each do |key, value|
60
- if !oElem.attributes.key?(key) || oElem.attributes[key] != value
61
- is_found = false
62
- break
63
- end
64
- end
65
- result << oElem if is_found
66
- end
67
- result
68
- end
69
-
70
- def self.server_assign_address(oComputeConnect, server)
71
- while server.state != 'ACTIVE'
72
- sleep(5)
73
- server = oComputeConnect.servers.get(server.id)
74
- end
75
-
76
- addresses = oComputeConnect.addresses.all
77
- address = nil
78
- # Search for an available IP
79
- addresses.each do |oElem|
80
- if oElem.fixed_ip.nil?
81
- address = oElem
82
- break
83
- end
84
- end
85
-
86
- if address.nil?
87
- # Create a new public IP to add in the pool.
88
- address = oComputeConnect.addresses.create
89
- end
90
- fail "No Public IP to assign to server '%s'", server.name if address.nil?
91
- address.server = server # associate the server
92
- address.reload
93
- # This function needs to returns a list of object.
94
- # This list must support the each function.
95
- address
96
- end
97
-
98
- def self.delete_server(oComputeConnect, server)
99
- oComputeConnect.servers.get(server.id).destroy
100
- end
101
-
102
- def self.get_image(oComputeConnect, oImageID)
103
- oComputeConnect.images.get(oImageID)
104
- end
105
- end
@@ -1,462 +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 class describes how to process some actions, and will do everything prior
18
- # this task to make it to work.
19
-
20
- require 'fog' # We use fog to access HPCloud
21
-
22
- hpcloud_path = File.expand_path(File.dirname(__FILE__))
23
-
24
- load File.join(hpcloud_path, 'compute.rb')
25
- load File.join(hpcloud_path, 'network.rb')
26
- load File.join(hpcloud_path, 'security_groups.rb')
27
-
28
- # Defines Meta HPCloud object
29
- class Hpcloud
30
- define_obj :services
31
- obj_needs :data, :account_id, :mapping => :hp_access_key
32
- obj_needs :data, :account_key, :mapping => :hp_secret_key
33
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
34
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
35
- obj_needs :data, ':excon_opts/:connect_timeout', :default_value => 30
36
- obj_needs :data, ':excon_opts/:read_timeout', :default_value => 240
37
- obj_needs :data, ':excon_opts/:write_timeout', :default_value => 240
38
-
39
- # Defines Object structure and function stored on the Hpcloud class object.
40
- # Compute Object
41
- define_obj :compute_connection
42
- # Defines Data used by compute.
43
-
44
- obj_needs :data, :account_id, :mapping => :hp_access_key
45
- obj_needs :data, :account_key, :mapping => :hp_secret_key
46
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
47
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
48
- obj_needs :data, :compute, :mapping => :hp_avl_zone
49
-
50
- define_obj :network_connection
51
- obj_needs :data, :account_id, :mapping => :hp_access_key
52
- obj_needs :data, :account_key, :mapping => :hp_secret_key
53
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
54
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
55
- obj_needs :data, :network, :mapping => :hp_avl_zone
56
-
57
- # Forj predefine following query mapping, used by ForjProcess
58
- # id => id, name => name
59
- # If we need to add another mapping, add
60
- # query_mapping :id => :MyID
61
- # If the query is not push through and Hash object, the Provider
62
- # will needs to create his own mapping function.
63
- define_obj :network
64
- def_attr_mapping :external, :router_external
65
-
66
- define_obj :rule
67
- obj_needs :data, :dir, :mapping => :direction
68
- attr_value_mapping :IN, 'ingress'
69
- attr_value_mapping :OUT, 'egress'
70
-
71
- obj_needs :data, :proto, :mapping => :protocol
72
- obj_needs :data, :port_min, :mapping => :port_range_min
73
- obj_needs :data, :port_max, :mapping => :port_range_max
74
- obj_needs :data, :addr_map, :mapping => :remote_ip_prefix
75
- obj_needs :data, :sg_id, :mapping => :security_group_id
76
-
77
- def_attr_mapping :dir, :direction
78
- def_attr_mapping :proto, :protocol
79
- def_attr_mapping :port_min, :port_range_min
80
- def_attr_mapping :port_max, :port_range_max
81
- def_attr_mapping :addr_map, :remote_ip_prefix
82
- def_attr_mapping :sg_id, :security_group_id
83
-
84
- define_obj :keypairs
85
-
86
- undefine_attribute :id # Do not return any predefined ID
87
-
88
- # ************************************ Router Object
89
- define_obj :router
90
-
91
- obj_needs_optional
92
- obj_needs :data, :router_name, :mapping => :name
93
- # The FORJ gateway_network_id is extracted from
94
- # Fog::HP::Network::Router[:external_gateway_info][:network_id]
95
- obj_needs :data, :external_gateway_id, :mapping => [:external_gateway_info,
96
- 'network_id']
97
-
98
- def_attr_mapping :gateway_network_id, [:external_gateway_info, 'network_id']
99
-
100
- # ************************************ SERVER Object
101
- define_obj :server
102
- def_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
- def_attr_mapping :output, 'output'
112
-
113
- # ************************************* Public IP Object
114
- define_obj :public_ip
115
- def_attr_mapping :server_id, :instance_id
116
- def_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, '\
122
- 'manage keys)',
123
- :validate => /^[A-Z0-9]*$/
124
- )
125
- define_data(:account_key,
126
- :account => true,
127
- :desc => 'HPCloud secret Key (From horizon, user drop down, '\
128
- 'manage keys)',
129
- :encrypted => false,
130
- :validate => /^.+/
131
- )
132
- define_data(:auth_uri,
133
- :account => true,
134
- :desc => 'HPCloud Authentication service URL (default is HP '\
135
- 'Public cloud)',
136
- :validate => %r{^http(s)?://.*$},
137
- :default_value => 'https://region-a.geo-1.identity.hpcloudsvc'\
138
- '.com:35357/v2.0/'
139
- )
140
- define_data(:tenant,
141
- :account => true,
142
- :desc => 'HPCloud Tenant ID (from horizon, identity, projecs,'\
143
- ' Project ID)',
144
- :validate => /^[0-9]+$/
145
- )
146
-
147
- define_data(:compute,
148
- :account => true,
149
- :desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)',
150
- :depends_on => [:account_id, :account_key, :auth_uri, :tenant],
151
- :list_values => {
152
- :query_type => :controller_call,
153
- :object => :services,
154
- :query_call => :get_services,
155
- :query_params => { :list_services => [:Compute, :compute] },
156
- :validate => :list_strict
157
- }
158
- )
159
-
160
- define_data(:network,
161
- :account => true,
162
- :desc => 'HPCloud Network service zone (Ex: region-a.geo-1)',
163
- :depends_on => [:account_id, :account_key, :auth_uri, :tenant],
164
- :list_values => {
165
- :query_type => :controller_call,
166
- :object => :services,
167
- :query_call => :get_services,
168
- :query_params => { :list_services => [:Networking, :network] },
169
- :validate => :list_strict
170
- }
171
- )
172
-
173
- data_value_mapping 'xsmall', 'standard.xsmall'
174
- data_value_mapping 'small', 'standard.small'
175
- data_value_mapping 'medium', 'standard.medium'
176
- data_value_mapping 'large', 'standard.large'
177
- data_value_mapping 'xlarge', 'standard.xlarge'
178
- end
179
-
180
- # Following class describe how FORJ should handle HP Cloud objects.
181
- # Except Cloud connection, all HPCloud objects management are described/called
182
- # in HP* modules.
183
- class HpcloudController # rubocop: disable Metrics/ClassLength
184
- def connect(sObjectType, hParams)
185
- case sObjectType
186
- when :services
187
- Fog::HP.authenticate_v2(hParams[:hdata], hParams[:excon_opts])
188
- when :compute_connection
189
- Fog::Compute.new hParams[:hdata].merge(:provider => :hp, :version => 'v2')
190
- when :network_connection
191
- Fog::HP::Network.new(hParams[:hdata])
192
- else
193
- controller_error "'%s' is not a valid object for 'connect'", sObjectType
194
- end
195
- end
196
-
197
- # rubocop: disable MethodLength, CyclomaticComplexity, AbcSize
198
-
199
- # Create controller for Hpcloud
200
- def create(sObjectType, hParams)
201
- case sObjectType
202
- when :public_ip
203
- required?(hParams, :compute_connection)
204
- required?(hParams, :server)
205
- HPCompute.server_assign_address(hParams[:compute_connection],
206
- hParams[:server])
207
- when :server
208
- required?(hParams, :compute_connection)
209
- required?(hParams, :image)
210
- required?(hParams, :network)
211
- required?(hParams, :flavor)
212
- required?(hParams, :keypairs)
213
- required?(hParams, :security_groups)
214
- required?(hParams, :server_name)
215
-
216
- options = {
217
- :name => hParams[:server_name],
218
- :flavor_id => hParams[:flavor].id,
219
- :image_id => hParams[:image].id,
220
- :key_name => hParams[:keypairs].name,
221
- :security_groups => [hParams[:security_groups].name],
222
- :networks => [hParams[:network].id]
223
- }
224
-
225
- HPCompute.create_server(hParams[:compute_connection], options,
226
- hParams[:user_data], hParams[:meta_data])
227
- when :image
228
- required?(hParams, :compute_connection)
229
- required?(hParams, :image_name)
230
-
231
- HPCompute.get_image(hParams[:compute_connection], hParams[:image_name])
232
- when :network
233
- required?(hParams, :network_connection)
234
- required?(hParams, :network_name)
235
-
236
- HPNetwork.create_network(hParams[:network_connection],
237
- hParams[:network_name])
238
- when :subnetwork
239
- required?(hParams, :network_connection)
240
- required?(hParams, :network)
241
- required?(hParams, :subnetwork_name)
242
-
243
- HPNetwork.create_subnetwork(hParams[:network_connection],
244
- hParams[:network],
245
- hParams[:subnetwork_name])
246
- when :security_groups
247
- required?(hParams, :network_connection)
248
- required?(hParams, :security_group)
249
-
250
- HPSecurityGroups.create_sg(hParams[:network_connection],
251
- hParams[:security_group], hParams[:sg_desc])
252
- when :keypairs
253
- required?(hParams, :compute_connection)
254
- required?(hParams, :keypair_name)
255
- required?(hParams, :public_key)
256
-
257
- HPKeyPairs.create_keypair(hParams[:compute_connection],
258
- hParams[:keypair_name], hParams[:public_key])
259
- when :router
260
- required?(hParams, :network_connection)
261
- required?(hParams, :router_name)
262
-
263
- # Forcelly used admin_status_up to true.
264
- hParams[:hdata] = hParams[:hdata].merge(:admin_state_up => true)
265
-
266
- HPNetwork.create_router(hParams[:network_connection], hParams[:hdata])
267
- when :rule
268
- required?(hParams, :network_connection)
269
- required?(hParams, :security_groups)
270
- HPSecurityGroups.create_rule(hParams[:network_connection],
271
- hParams[:hdata])
272
- when :router_interface
273
- required?(hParams, :router)
274
- required?(hParams, :subnetwork)
275
- HPNetwork.add_interface(hParams[:router], hParams[:subnetwork])
276
- else
277
- controller_error "'%s' is not a valid object for 'create'", sObjectType
278
- end
279
- end
280
-
281
- # This function return a collection which have to provide:
282
- # functions: [], length, each
283
- # Used by network process.
284
- def query(sObjectType, sQuery, hParams)
285
- case sObjectType
286
- when :public_ip
287
- required?(hParams, :compute_connection)
288
- required?(hParams, :server)
289
- HPCompute.query_server_assigned_addresses(hParams[:compute_connection],
290
- hParams[:server], sQuery)
291
- when :server
292
- required?(hParams, :compute_connection)
293
- HPCompute.query_server(hParams[:compute_connection], sQuery)
294
- when :image
295
- required?(hParams, :compute_connection)
296
- HPCompute.query_image(hParams[:compute_connection], sQuery)
297
- when :network
298
- required?(hParams, :network_connection)
299
- HPNetwork.query_network(hParams[:network_connection], sQuery)
300
- when :subnetwork
301
- required?(hParams, :network_connection)
302
- HPNetwork.query_subnetwork(hParams[:network_connection], sQuery)
303
- when :router
304
- required?(hParams, :network_connection)
305
- HPNetwork.query_router(hParams[:network_connection], sQuery)
306
- when :port
307
- required?(hParams, :network_connection)
308
- HPNetwork.query_port(hParams[:network_connection], sQuery)
309
- when :security_groups
310
- required?(hParams, :network_connection)
311
- HPSecurityGroups.query_sg(hParams[:network_connection], sQuery)
312
- when :rule
313
- required?(hParams, :network_connection)
314
- HPSecurityGroups.query_rule(hParams[:network_connection], sQuery)
315
- when :keypairs
316
- required?(hParams, :compute_connection)
317
- HPKeyPairs.query_keypair(hParams[:compute_connection], sQuery)
318
- when :flavor
319
- required?(hParams, :compute_connection)
320
- HPCompute.query_flavor(hParams[:compute_connection], sQuery)
321
- else
322
- controller_error "'%s' is not a valid object for 'query'", sObjectType
323
- end
324
- end
325
- # rubocop: enable CyclomaticComplexity, MethodLength
326
-
327
- def delete(sObjectType, hParams)
328
- case sObjectType
329
- when :network
330
- HPNetwork.delete_network(hParams[:network_connection],
331
- hParams[:network])
332
- when :rule
333
- HPSecurityGroups.delete_rule(hParams[:network_connection],
334
- hParams[:id])
335
- obj = hParams[:network_connection]
336
- obj.security_group_rules.get(hParams[:id]).destroy
337
- when :server
338
- required?(hParams, :compute_connection)
339
- required?(hParams, :server)
340
- HPCompute.delete_server(hParams[:compute_connection],
341
- hParams[:server])
342
- end
343
- end
344
-
345
- def get(sObjectType, sUniqId, hParams)
346
- case sObjectType
347
- when :server_log
348
- required?(hParams, :server)
349
-
350
- hParams[:server].console_output(sUniqId)
351
- when :server
352
- required?(hParams, :compute_connection)
353
- HPCompute.get_server(hParams[:compute_connection], sUniqId)
354
- when :image
355
- required?(hParams, :compute_connection)
356
- HPCompute.get_image(hParams[:compute_connection], sUniqId)
357
- when :network
358
- required?(hParams, :network_connection)
359
- HPNetwork.get_network(hParams[:network_connection], sUniqId)
360
- when :keypairs
361
- required?(hParams, :compute_connection)
362
- HPKeyPairs.get_keypair(hParams[:compute_connection], sUniqId)
363
- else
364
- forjError "'%s' is not a valid object for 'get'", sObjectType
365
- end
366
- end
367
-
368
- def query_each(oFogObject)
369
- case oFogObject.class.to_s
370
- when 'Fog::HP::Network::Networks'
371
- oFogObject.each { |value| yield(value) }
372
- else
373
- controller_error "'%s' is not a valid list for 'each'",
374
- oFogObject.class
375
- end
376
- end
377
-
378
- def get_attr(oControlerObject, key)
379
- if oControlerObject.is_a?(Excon::Response)
380
- oControlerObject.data.rh_get(:body, key)
381
- else
382
- attributes = oControlerObject.attributes
383
- def_attributes = oControlerObject.class.attributes
384
- controller_error "attribute '%s' is unknown in '%s'. "\
385
- "Valid one are : '%s'",
386
- key[0], oControlerObject.class,
387
- def_attributes unless def_attributes.include?(key[0])
388
- attributes.rh_get(key)
389
- end
390
- rescue => e
391
- controller_error "Unable to map '%s'. %s", key, e.message
392
- end
393
-
394
- def set_attr(oControlerObject, key, value)
395
- controller_class = oControlerObject.class
396
-
397
- controller_error "No set feature for '%s'",
398
- controller_class if oControlerObject.is_a?(Excon::Response)
399
-
400
- attributes = oControlerObject.attributes
401
- def_attributes = oControlerObject.class.attributes
402
- controller_error "attribute '%s' is unknown in '%s'. Valid one are : '%s'",
403
- key[0], oControlerObject.class,
404
- def_attributes unless def_attributes.include?(key[0])
405
- attributes.rh_set(value, key)
406
- rescue => e
407
- controller_error "Unable to map '%s' on '%s'\n%s",
408
- key, sObjectType, e.message
409
- end
410
-
411
- def update(sObjectType, oObject, _hParams)
412
- case sObjectType
413
- when :router
414
- controller_error 'Object to update is nil' if oObject.nil?
415
-
416
- HPNetwork.update_router(oObject[:object])
417
- else
418
- controller_error "'%s' is not a valid list for 'update'",
419
- oFogObject.class
420
- end
421
- end
422
-
423
- # This function requires to return an Array of values or nil.
424
- def get_services(sObjectType, oParams)
425
- case sObjectType
426
- when :services
427
- # oParams[sObjectType] will provide the controller object.
428
- # This one can be interpreted only by controller code,
429
- # except if controller declares how to map with this object.
430
- # Processes can deal only process mapped data.
431
- # Currently there is no services process function. No need to map.
432
- services = oParams[:services]
433
- if !oParams[:list_services].is_a?(Array)
434
- service_to_find = [oParams[:list_services]]
435
- else
436
- service_to_find = oParams[:list_services]
437
- end
438
- # Search for service. Ex: Can be :Networking or network. I currently do
439
- # not know why...
440
- search_services = services.rh_get(:service_catalog)
441
- service = nil
442
- service_to_find.each do |sServiceElem|
443
- if search_services.key?(sServiceElem)
444
- service = sServiceElem
445
- break
446
- end
447
- end
448
-
449
- controller_error 'Unable to find services %s',
450
- service_to_find if service.nil?
451
- result = services.rh_get(:service_catalog, service).keys
452
- result.delete('name')
453
- result.each_index do |iIndex|
454
- result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
455
- end
456
- return result
457
- else
458
- controller_error "'%s' is not a valid object for 'get_services'",
459
- sObjectType
460
- end
461
- end
462
- end