lorj 1.0.9 → 1.0.10
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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/example/students_1/process/students.rb +1 -1
- data/example/students_1/student_v1.md +2 -0
- data/example/students_1/students.rb +2 -1
- data/example/students_2/process/students.rb +1 -1
- data/example/students_2/students.rb +4 -2
- data/example/students_3/controller/yaml_students_def.rb +1 -1
- data/example/students_3/process/students.rb +1 -1
- data/example/students_3/student_v3.md +5 -3
- data/example/students_3/students.rb +5 -3
- data/example/students_4/controller/yaml_students_def.rb +1 -1
- data/example/students_4/process/students/definition/students.rb +1 -1
- data/example/students_4/students.rb +5 -3
- data/example/students_5/controller/yaml_students.rb +1 -1
- data/example/students_5/process/students.rb +1 -1
- data/example/students_5/student_v5.md +4 -4
- data/example/students_5/students.rb +8 -7
- data/example/yaml_students/students.rb +4 -4
- data/lib/core/core.rb +110 -64
- data/lib/core/core_internal.rb +110 -15
- data/lib/core/core_object_data.rb +4 -4
- data/lib/core/core_process_setup.rb +3 -30
- data/lib/core/lorj_data.rb +1 -1
- data/lib/core/lorj_keypath.rb +3 -1
- data/lib/core/process.rb +67 -0
- data/lib/lorj/version.rb +2 -1
- data/lib/lorj.rb +3 -4
- data/lib/lorj_account.rb +6 -5
- data/lib/lorj_config.rb +3 -2
- data/lib/providers/templates/compute.rb +1 -1
- data/lorj-spec/controllers/mock/mock.rb +144 -0
- data/lorj-spec/data.yaml +0 -0
- data/lorj-spec/process/mock2_process.rb +48 -0
- data/lorj-spec/process/mock_process.rb +48 -0
- data/lorj-spec/providers/mock2/mock2.rb +0 -0
- data/lorj.gemspec +2 -4
- data/spec/05_lorj_keypath_spec.rb +78 -0
- data/spec/20_lorj_meta_spec.rb +1 -1
- data/spec/21_lorj_processes_spec.rb +115 -0
- metadata +27 -42
- data/lib/core_process/cloud/process/common.rb +0 -60
- data/lib/core_process/cloud/process/connection.rb +0 -92
- data/lib/core_process/cloud/process/external_network.rb +0 -90
- data/lib/core_process/cloud/process/flavor.rb +0 -97
- data/lib/core_process/cloud/process/images.rb +0 -99
- data/lib/core_process/cloud/process/internet_network.rb +0 -33
- data/lib/core_process/cloud/process/internet_server.rb +0 -29
- data/lib/core_process/cloud/process/keypairs.rb +0 -332
- data/lib/core_process/cloud/process/network.rb +0 -107
- data/lib/core_process/cloud/process/public_ip.rb +0 -102
- data/lib/core_process/cloud/process/router.rb +0 -267
- data/lib/core_process/cloud/process/rules.rb +0 -120
- data/lib/core_process/cloud/process/security_groups.rb +0 -120
- data/lib/core_process/cloud/process/server.rb +0 -126
- data/lib/core_process/cloud/process/server_log.rb +0 -34
- data/lib/core_process/cloud/process/subnetwork.rb +0 -96
- data/lib/core_process/cloud_process.rb +0 -30
- data/lib/prc_base_config.rb +0 -300
- data/lib/prc_core_config.rb +0 -1258
- data/lib/prc_section_config.rb +0 -90
- data/lib/providers/hpcloud/compute.rb +0 -105
- data/lib/providers/hpcloud/hpcloud.rb +0 -462
- data/lib/providers/hpcloud/network.rb +0 -115
- data/lib/providers/hpcloud/security_groups.rb +0 -68
- data/lib/providers/openstack/openstack.rb +0 -410
- data/lib/providers/openstack/openstack_create.rb +0 -205
- data/lib/providers/openstack/openstack_delete.rb +0 -28
- data/lib/providers/openstack/openstack_get.rb +0 -39
- data/lib/providers/openstack/openstack_process.rb +0 -26
- data/lib/providers/openstack/openstack_query.rb +0 -96
- data/lib/providers/openstack/openstack_update.rb +0 -35
- data/lib/rh.rb +0 -426
- data/spec/01_hash_rh_spec.rb +0 -282
- data/spec/02_prc_base_config_spec.rb +0 -227
- data/spec/03_prc_section_config_spec.rb +0 -196
- data/spec/04_prc_core_config_spec.rb +0 -325
@@ -1,115 +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
|
-
# HPcloud network class
|
18
|
-
module HPNetwork
|
19
|
-
# Network driver
|
20
|
-
def self.query_network(oNetworkConnect, sQuery)
|
21
|
-
oNetworkConnect.networks.all(sQuery)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.create_network(oNetworkConnect, name)
|
25
|
-
oNetworkConnect.networks.create(:name => name)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.delete_network(oNetworkConnect, oNetwork)
|
29
|
-
oNetworkConnect.networks.get(oNetwork.id).destroy
|
30
|
-
end
|
31
|
-
|
32
|
-
# SubNetwork driver
|
33
|
-
def self.query_subnetwork(oNetworkConnect, sQuery)
|
34
|
-
oNetworkConnect.subnets.all(sQuery)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.create_subnetwork(oNetworkConnect, oNetwork, name)
|
38
|
-
oNetworkConnect.subnets.create(
|
39
|
-
:network_id => oNetwork.id,
|
40
|
-
:name => name,
|
41
|
-
:cidr => get_next_subnet(oNetworkConnect),
|
42
|
-
:ip_version => '4'
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.delete_subnetwork(oNetworkConnect, oSubNetwork)
|
47
|
-
oNetworkConnect.subnets.get(oSubNetwork.id).destroy
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.get_next_subnet(oNetworkConnect)
|
51
|
-
subnet_values = []
|
52
|
-
subnets = oNetworkConnect.subnets.all
|
53
|
-
|
54
|
-
subnets.each do|s|
|
55
|
-
subnet_values.push(s.cidr)
|
56
|
-
end
|
57
|
-
|
58
|
-
gap = false
|
59
|
-
count = 0
|
60
|
-
range_used = []
|
61
|
-
new_subnet = 0
|
62
|
-
new_cidr = ''
|
63
|
-
|
64
|
-
subnet_values = subnet_values.sort!
|
65
|
-
|
66
|
-
subnet_values.each do|value|
|
67
|
-
range_used.push(value[5])
|
68
|
-
end
|
69
|
-
|
70
|
-
range_used.each do |n|
|
71
|
-
if count.to_i == n.to_i
|
72
|
-
else
|
73
|
-
new_subnet = count
|
74
|
-
gap = true
|
75
|
-
break
|
76
|
-
end
|
77
|
-
count += 1
|
78
|
-
end
|
79
|
-
|
80
|
-
if gap
|
81
|
-
new_cidr = format('10.0.%s.0/24', count)
|
82
|
-
else
|
83
|
-
max_value = range_used.max
|
84
|
-
new_subnet = max_value.to_i + 1
|
85
|
-
new_cidr = format('10.0.%s.0/24', new_subnet)
|
86
|
-
end
|
87
|
-
new_cidr
|
88
|
-
rescue => e
|
89
|
-
Logging.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
90
|
-
end
|
91
|
-
|
92
|
-
# router driver
|
93
|
-
def self.query_router(oNetworkConnect, sQuery)
|
94
|
-
oNetworkConnect.routers.all(sQuery)
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.update_router(oRouters)
|
98
|
-
oRouters.save
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.create_router(oNetwork, hOptions)
|
102
|
-
oNetwork.routers.create(hOptions)
|
103
|
-
end
|
104
|
-
|
105
|
-
# router interface
|
106
|
-
|
107
|
-
def self.add_interface(oRouter, oSubNetwork)
|
108
|
-
oRouter.add_interface(oSubNetwork.id, nil)
|
109
|
-
end
|
110
|
-
|
111
|
-
# Port driver
|
112
|
-
def self.query_port(oNetworkConnect, sQuery)
|
113
|
-
oNetworkConnect.ports.all(sQuery)
|
114
|
-
end
|
115
|
-
end
|
@@ -1,68 +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
|
-
# HPCloud security groups
|
18
|
-
module HPSecurityGroups
|
19
|
-
def self.query_sg(oNetworkConnect, sQuery)
|
20
|
-
oNetworkConnect.security_groups.all(sQuery)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.create_sg(oNetwork, name, description)
|
24
|
-
params = { :name => name }
|
25
|
-
params[:description] = description if description
|
26
|
-
oNetwork.security_groups.create(params)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.create_rule(oNetwork, hData)
|
30
|
-
oNetwork.security_group_rules.create(hData)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.query_rule(oNetwork, sQuery)
|
34
|
-
oNetwork.security_group_rules.all(sQuery)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.delete_rule(oNetwork, rule_id)
|
38
|
-
oNetwork.security_group_rules.get(rule_id).destroy
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# HPCloud keypairs
|
43
|
-
module HPKeyPairs
|
44
|
-
def self.query_keypair(oComputeConnect, sQuery)
|
45
|
-
keypairs = oComputeConnect.key_pairs.all
|
46
|
-
results = []
|
47
|
-
keypairs.each do |sElem|
|
48
|
-
is_selected = true
|
49
|
-
attributes = sElem.instance_variable_get(:@attributes)
|
50
|
-
sQuery.each do |key, value|
|
51
|
-
if attributes[key] != value
|
52
|
-
is_selected = false
|
53
|
-
break
|
54
|
-
end
|
55
|
-
end
|
56
|
-
results.push sElem if is_selected
|
57
|
-
end
|
58
|
-
results
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.get_keypair(oComputeConnect, sId)
|
62
|
-
oComputeConnect.key_pairs.get(sId)
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.create_keypair(oComputeConnect, name, pubkey)
|
66
|
-
oComputeConnect.key_pairs.create(:name => name, :public_key => pubkey)
|
67
|
-
end
|
68
|
-
end
|
@@ -1,410 +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
|
-
require 'fog'
|
20
|
-
require 'uri'
|
21
|
-
|
22
|
-
hpcloud_path = File.expand_path(File.dirname(__FILE__))
|
23
|
-
|
24
|
-
require File.join(hpcloud_path, 'openstack_query.rb')
|
25
|
-
require File.join(hpcloud_path, 'openstack_get.rb')
|
26
|
-
require File.join(hpcloud_path, 'openstack_delete.rb')
|
27
|
-
require File.join(hpcloud_path, 'openstack_create.rb')
|
28
|
-
require File.join(hpcloud_path, 'openstack_update.rb')
|
29
|
-
|
30
|
-
# Defines Meta Openstack object
|
31
|
-
class Openstack
|
32
|
-
process_default :use_controller => true
|
33
|
-
|
34
|
-
define_obj :services
|
35
|
-
# Define Data used by service
|
36
|
-
|
37
|
-
obj_needs :data, :account_id, :mapping => :openstack_username
|
38
|
-
obj_needs :data, :account_key, :mapping => :openstack_api_key,
|
39
|
-
:decrypt => true
|
40
|
-
obj_needs :data, :auth_uri, :mapping => :openstack_auth_uri
|
41
|
-
obj_needs :data, :tenant, :mapping => :openstack_tenant
|
42
|
-
obj_needs :data, ':excon_opts/:connect_timeout', :default_value => 30
|
43
|
-
obj_needs :data, ':excon_opts/:read_timeout', :default_value => 240
|
44
|
-
obj_needs :data, ':excon_opts/:write_timeout', :default_value => 240
|
45
|
-
|
46
|
-
define_obj :compute_connection
|
47
|
-
# Defines Data used by compute.
|
48
|
-
|
49
|
-
obj_needs :data, :account_id, :mapping => :openstack_username
|
50
|
-
obj_needs :data, :account_key, :mapping => :openstack_api_key,
|
51
|
-
:decrypt => true
|
52
|
-
obj_needs :data, :auth_uri, :mapping => :openstack_auth_url
|
53
|
-
obj_needs :data, :tenant, :mapping => :openstack_tenant
|
54
|
-
obj_needs :data, :compute, :mapping => :openstack_region
|
55
|
-
|
56
|
-
define_obj :network_connection
|
57
|
-
obj_needs :data, :account_id, :mapping => :openstack_username
|
58
|
-
obj_needs :data, :account_key, :mapping => :openstack_api_key,
|
59
|
-
:decrypt => true
|
60
|
-
obj_needs :data, :auth_uri, :mapping => :openstack_auth_url
|
61
|
-
obj_needs :data, :tenant, :mapping => :openstack_tenant
|
62
|
-
obj_needs :data, :network, :mapping => :openstack_region
|
63
|
-
|
64
|
-
# Openstack tenants object
|
65
|
-
define_obj(:tenants, :create_e => :openstack_get_tenant)
|
66
|
-
obj_needs :CloudObject, :compute_connection
|
67
|
-
obj_needs :data, :tenant
|
68
|
-
|
69
|
-
# Openstack Network
|
70
|
-
define_obj :network
|
71
|
-
def_hdata :network_name, :mapping => :name
|
72
|
-
def_attr_mapping :external, :router_external
|
73
|
-
|
74
|
-
define_obj :keypairs
|
75
|
-
|
76
|
-
undefine_attribute :id # Do not return any predefined ID
|
77
|
-
|
78
|
-
define_obj :server_log
|
79
|
-
|
80
|
-
# Excon::Response object type
|
81
|
-
def_attr_mapping :output, 'output'
|
82
|
-
|
83
|
-
define_obj :security_groups
|
84
|
-
# Added tenant data to add in queries.
|
85
|
-
obj_needs :CloudObject, :tenants
|
86
|
-
|
87
|
-
define_obj :rule
|
88
|
-
obj_needs :data, :dir, :mapping => :direction
|
89
|
-
attr_value_mapping :IN, 'ingress'
|
90
|
-
attr_value_mapping :OUT, 'egress'
|
91
|
-
|
92
|
-
obj_needs :data, :proto, :mapping => :protocol
|
93
|
-
obj_needs :data, :port_min, :mapping => :port_range_min
|
94
|
-
obj_needs :data, :port_max, :mapping => :port_range_max
|
95
|
-
obj_needs :data, :addr_map, :mapping => :remote_ip_prefix
|
96
|
-
obj_needs :data, :sg_id, :mapping => :security_group_id
|
97
|
-
|
98
|
-
def_attr_mapping :dir, :direction
|
99
|
-
def_attr_mapping :proto, :protocol
|
100
|
-
def_attr_mapping :port_min, :port_range_min
|
101
|
-
def_attr_mapping :port_max, :port_range_max
|
102
|
-
def_attr_mapping :addr_map, :remote_ip_prefix
|
103
|
-
def_attr_mapping :sg_id, :security_group_id
|
104
|
-
|
105
|
-
define_data(:account_id,
|
106
|
-
:account => true,
|
107
|
-
:desc => 'Openstack Username',
|
108
|
-
:validate => /^.+/
|
109
|
-
)
|
110
|
-
|
111
|
-
define_data(:account_key,
|
112
|
-
:account => true,
|
113
|
-
:desc => 'Openstack Password',
|
114
|
-
:validate => /^.+/
|
115
|
-
)
|
116
|
-
define_data(:auth_uri,
|
117
|
-
:account => true,
|
118
|
-
:explanation => "The authentication service is identified as '"\
|
119
|
-
"identity' under your horizon UI - Project/Compute then "\
|
120
|
-
'Access & security.',
|
121
|
-
:desc => 'Openstack Authentication service URL. '\
|
122
|
-
'Ex: https://mycloud:5000/v2.0/tokens',
|
123
|
-
:validate => %r{^http(s)?:\/\/.*\/tokens$}
|
124
|
-
)
|
125
|
-
define_data(:tenant,
|
126
|
-
:account => true,
|
127
|
-
:explanation => 'The Project name is shown from your horizon UI'\
|
128
|
-
', on top left, close to the logo',
|
129
|
-
:desc => 'Openstack Tenant Name',
|
130
|
-
:validate => /^.+/
|
131
|
-
)
|
132
|
-
|
133
|
-
define_data(:compute,
|
134
|
-
:account => true,
|
135
|
-
:default_value => '<%= config[:network] %>',
|
136
|
-
:explanation => 'Depending on your installation, you may need to'\
|
137
|
-
' provide a Region name. This information is shown under your '\
|
138
|
-
'horizon UI - close right to the project name (top left).'\
|
139
|
-
"\nYou can also get it from Project-Compute-Access & Security-"\
|
140
|
-
'API, then download the Openstack RC file. The Region name is '\
|
141
|
-
'set as OS_REGION_NAME.'\
|
142
|
-
"\nIf there is no region shown, you can ignore it.",
|
143
|
-
:desc => 'Openstack Compute Region (Ex: RegionOne)',
|
144
|
-
:depends_on => [:account_id, :account_key, :auth_uri, :tenant],
|
145
|
-
:list_values => {
|
146
|
-
:query_type => :controller_call,
|
147
|
-
:object => :services,
|
148
|
-
:query_call => :get_services,
|
149
|
-
:query_params => { :list_services => [:Compute, :compute] },
|
150
|
-
:validate => :list_strict
|
151
|
-
}
|
152
|
-
)
|
153
|
-
|
154
|
-
define_data(:network,
|
155
|
-
:account => true,
|
156
|
-
:default_value => '<%= config[:compute] %>',
|
157
|
-
:desc => 'Openstack Network Region (Ex: RegionOne)',
|
158
|
-
:explanation => 'Depending on your installation, you may need to'\
|
159
|
-
' provide a Region name. This information is shown under your '\
|
160
|
-
'horizon UI - close right to the project name (top left).'\
|
161
|
-
"\nYou can also get it from Project-Compute-Access & Security-"\
|
162
|
-
'API, then download the Openstack RC file. The Region name is '\
|
163
|
-
'set as OS_REGION_NAME.'\
|
164
|
-
"\nIf there is no region shown, you can ignore it.",
|
165
|
-
:depends_on => [:account_id, :account_key, :auth_uri, :tenant],
|
166
|
-
:list_values => {
|
167
|
-
:query_type => :controller_call,
|
168
|
-
:object => :services,
|
169
|
-
:query_call => :get_services,
|
170
|
-
:query_params => { :list_services => [:Networking, :network] },
|
171
|
-
:validate => :list_strict
|
172
|
-
}
|
173
|
-
)
|
174
|
-
|
175
|
-
define_obj :server
|
176
|
-
def_attr_mapping :status, :state
|
177
|
-
attr_value_mapping :create, 'BUILD'
|
178
|
-
attr_value_mapping :boot, :boot
|
179
|
-
attr_value_mapping :active, 'ACTIVE'
|
180
|
-
attr_value_mapping :active, 'ACTIVE'
|
181
|
-
|
182
|
-
def_attr_mapping :private_ip_address, :accessIPv4
|
183
|
-
def_attr_mapping :public_ip_address, :accessIPv4
|
184
|
-
def_attr_mapping :image_id, [:image, 'id']
|
185
|
-
|
186
|
-
define_obj :router
|
187
|
-
obj_needs_optional
|
188
|
-
obj_needs :data, :router_name, :mapping => :name
|
189
|
-
|
190
|
-
# The FORJ gateway_network_id is extracted
|
191
|
-
# from Fog::HP::Network::Router[:external_gateway_info][:network_id]
|
192
|
-
|
193
|
-
obj_needs :data,
|
194
|
-
:external_gateway_id,
|
195
|
-
:mapping => [:external_gateway_info, 'network_id']
|
196
|
-
|
197
|
-
def_attr_mapping :gateway_network_id, [:external_gateway_info, 'network_id']
|
198
|
-
|
199
|
-
# Port attributes used specifically by openstack fog API.
|
200
|
-
define_obj :port
|
201
|
-
def_attribute :device_owner
|
202
|
-
def_attribute :network_id
|
203
|
-
|
204
|
-
define_obj :public_ip
|
205
|
-
def_attr_mapping :server_id, :instance_id
|
206
|
-
def_attr_mapping :public_ip, :ip
|
207
|
-
|
208
|
-
define_obj :image
|
209
|
-
def_attr_mapping :image_name, :name
|
210
|
-
end
|
211
|
-
|
212
|
-
# Following class describe how FORJ should handle Openstack Cloud objects.
|
213
|
-
class OpenstackController
|
214
|
-
def self.def_cruds(*crud_types)
|
215
|
-
crud_types.each do |crud_type|
|
216
|
-
case crud_type
|
217
|
-
when :create, :delete
|
218
|
-
base_method(crud_type)
|
219
|
-
when :query, :get
|
220
|
-
query_method(crud_type)
|
221
|
-
when :update
|
222
|
-
update_method(crud_type)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def self.update_method(crud_type)
|
228
|
-
define_method(crud_type) do |sObjectType, obj, hParams|
|
229
|
-
method_name = "#{crud_type}_#{sObjectType}"
|
230
|
-
if self.class.method_defined? method_name
|
231
|
-
send(method_name, obj, hParams)
|
232
|
-
else
|
233
|
-
controller_error "'%s' is not a valid object for '%s'",
|
234
|
-
sObjectType, crud_type
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def self.query_method(crud_type)
|
240
|
-
define_method(crud_type) do |sObjectType, sCondition, hParams|
|
241
|
-
method_name = "#{crud_type}_#{sObjectType}"
|
242
|
-
if self.class.method_defined? method_name
|
243
|
-
send(method_name, hParams, sCondition)
|
244
|
-
else
|
245
|
-
controller_error "'%s' is not a valid object for '%s'",
|
246
|
-
sObjectType, crud_type
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
def self.base_method(crud_type)
|
252
|
-
define_method(crud_type) do |sObjectType, hParams|
|
253
|
-
method_name = "#{crud_type}_#{sObjectType}"
|
254
|
-
if self.class.method_defined? method_name
|
255
|
-
send(method_name, hParams)
|
256
|
-
else
|
257
|
-
controller_error "'%s' is not a valid object for '%s'",
|
258
|
-
sObjectType, crud_type
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
# Define the Openstack controller handlers
|
264
|
-
def_cruds :create, :delete, :get, :query, :update
|
265
|
-
|
266
|
-
def connect(sObjectType, hParams)
|
267
|
-
case sObjectType
|
268
|
-
when :services
|
269
|
-
# Fog use URI type for auth uri: URI.parse(:auth_uri)
|
270
|
-
# Convert openstack_auth_uri to type URI
|
271
|
-
hParams[:hdata][:openstack_auth_uri] =
|
272
|
-
URI.parse(hParams[:hdata][:openstack_auth_uri])
|
273
|
-
retrieve_result =
|
274
|
-
Fog::OpenStack.retrieve_tokens_v2(hParams[:hdata],
|
275
|
-
hParams[:excon_opts])
|
276
|
-
creds = format_retrieve_result(retrieve_result)
|
277
|
-
return creds
|
278
|
-
when :compute_connection
|
279
|
-
Fog::Compute.new(
|
280
|
-
hParams[:hdata].merge(:provider => :openstack)
|
281
|
-
)
|
282
|
-
when :network_connection
|
283
|
-
Fog::Network::OpenStack.new(hParams[:hdata])
|
284
|
-
else
|
285
|
-
controller_error "'%s' is not a valid object for 'connect'", sObjectType
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
def set_attr(oControlerObject, key, value)
|
290
|
-
if oControlerObject.is_a?(Excon::Response)
|
291
|
-
controller_error "No set feature for '%s'", oControlerObject.class
|
292
|
-
end
|
293
|
-
|
294
|
-
attributes = oControlerObject.attributes
|
295
|
-
|
296
|
-
controller_error "attribute '%s' is unknown in '%s'. Valid one are : '%s'",
|
297
|
-
key[0],
|
298
|
-
oControlerObject.class,
|
299
|
-
oControlerObject.class.attributes unless
|
300
|
-
oControlerObject.class.attributes.include?(key[0])
|
301
|
-
|
302
|
-
attributes.rh_set(value, key)
|
303
|
-
rescue => e
|
304
|
-
controller_error "Unable to map '%s' on '%s'. %s",
|
305
|
-
key, oControlerObject, e.message
|
306
|
-
end
|
307
|
-
|
308
|
-
def get_attr(oControlerObject, key)
|
309
|
-
if oControlerObject.is_a?(Excon::Response)
|
310
|
-
oControlerObject.data.rh_get(:body, key)
|
311
|
-
else
|
312
|
-
attributes = oControlerObject.attributes
|
313
|
-
controller_error "attribute '%s' is unknown in '%s'."\
|
314
|
-
" Valid one are : '%s'",
|
315
|
-
key[0],
|
316
|
-
oControlerObject.class,
|
317
|
-
oControlerObject.class.attributes unless
|
318
|
-
oControlerObject.class.attributes.include?(key[0])
|
319
|
-
return attributes.rh_get(key) if attributes.rh_exist?(key)
|
320
|
-
_get_instance_attr(oControlerObject, key)
|
321
|
-
end
|
322
|
-
rescue => e
|
323
|
-
controller_error "==>Unable to map '%s'. %s", key, e.message
|
324
|
-
end
|
325
|
-
|
326
|
-
def _get_instance_attr(oControlerObject, key)
|
327
|
-
return nil if oControlerObject.send(key[0]).nil?
|
328
|
-
return oControlerObject.send(key[0]) if key.length == 1
|
329
|
-
oControlerObject.send(key[0]).rh_get(key[1..-1])
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
# Following class describe how FORJ should handle Openstack Cloud objects.
|
334
|
-
class OpenstackController
|
335
|
-
# This function requires to return an Array of values or nil.
|
336
|
-
def get_services(sObjectType, oParams)
|
337
|
-
case sObjectType
|
338
|
-
when :services
|
339
|
-
# oParams[sObjectType] will provide the controller object.
|
340
|
-
# This one can be interpreted only by controller code,
|
341
|
-
# except if controller declares how to map with this object.
|
342
|
-
# Processes can deal only process mapped data.
|
343
|
-
# Currently there is no services process function. No need to map.
|
344
|
-
services = oParams[:services]
|
345
|
-
if !oParams[:list_services].is_a?(Array)
|
346
|
-
service_to_find = [oParams[:list_services]]
|
347
|
-
else
|
348
|
-
service_to_find = oParams[:list_services]
|
349
|
-
end
|
350
|
-
# Search for service. Ex: Can be :Networking or network. I currently do
|
351
|
-
# not know why...
|
352
|
-
search_services = services.rh_get(:service_catalog)
|
353
|
-
service = nil
|
354
|
-
service_to_find.each do |sServiceElem|
|
355
|
-
if search_services.key?(sServiceElem)
|
356
|
-
service = sServiceElem
|
357
|
-
break
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
controller_error 'Unable to find services %s',
|
362
|
-
service_to_find if service.nil?
|
363
|
-
result = services.rh_get(:service_catalog, service).keys
|
364
|
-
result.delete('name')
|
365
|
-
result.each_index do |iIndex|
|
366
|
-
result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
|
367
|
-
end
|
368
|
-
return result
|
369
|
-
else
|
370
|
-
controller_error "'%s' is not a valid object for 'get_services'",
|
371
|
-
sObjectType
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
def format_retrieve_result(retrieve_result)
|
376
|
-
{
|
377
|
-
:auth_token => retrieve_result['access']['token']['id'],
|
378
|
-
:expires => retrieve_result['access']['token']['expires'],
|
379
|
-
:service_catalog =>
|
380
|
-
get_service_catalog(retrieve_result['access']['serviceCatalog']),
|
381
|
-
:endpoint_url => nil,
|
382
|
-
:cdn_endpoint_url => nil
|
383
|
-
}
|
384
|
-
end
|
385
|
-
|
386
|
-
def get_service_catalog(body)
|
387
|
-
fail 'Unable to parse service catalog.' unless body
|
388
|
-
service_catalog = {}
|
389
|
-
body.each do |s|
|
390
|
-
type = s['type']
|
391
|
-
next if type.nil?
|
392
|
-
type = type.to_sym
|
393
|
-
next if s['endpoints'].nil?
|
394
|
-
service_catalog[type] = {}
|
395
|
-
service_catalog[type]['name'] = s['name']
|
396
|
-
service_catalog = parse_service_catalog_endpoint(s, type, service_catalog)
|
397
|
-
end
|
398
|
-
service_catalog
|
399
|
-
end
|
400
|
-
|
401
|
-
def parse_service_catalog_endpoint(s, type, service_catalog)
|
402
|
-
s['endpoints'].each do |ep|
|
403
|
-
next if ep['region'].nil?
|
404
|
-
next if ep['publicURL'].nil?
|
405
|
-
next if ep['publicURL'].empty?
|
406
|
-
service_catalog[type][ep['region'].to_sym] = ep['publicURL']
|
407
|
-
end
|
408
|
-
service_catalog
|
409
|
-
end
|
410
|
-
end
|