lorj_cloud 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitreview +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +43 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/data.yaml +0 -0
- data/lib/defaults.yaml +0 -0
- data/lib/lorj_cloud/version.rb +4 -0
- data/lib/lorj_cloud.rb +6 -0
- data/lib/process/cloud/process/common.rb +60 -0
- data/lib/process/cloud/process/connection.rb +92 -0
- data/lib/process/cloud/process/external_network.rb +90 -0
- data/lib/process/cloud/process/flavor.rb +97 -0
- data/lib/process/cloud/process/images.rb +99 -0
- data/lib/process/cloud/process/internet_network.rb +33 -0
- data/lib/process/cloud/process/internet_server.rb +29 -0
- data/lib/process/cloud/process/keypairs.rb +332 -0
- data/lib/process/cloud/process/network.rb +107 -0
- data/lib/process/cloud/process/public_ip.rb +106 -0
- data/lib/process/cloud/process/router.rb +267 -0
- data/lib/process/cloud/process/rules.rb +120 -0
- data/lib/process/cloud/process/security_groups.rb +120 -0
- data/lib/process/cloud/process/server.rb +127 -0
- data/lib/process/cloud/process/server_log.rb +34 -0
- data/lib/process/cloud/process/subnetwork.rb +96 -0
- data/lib/process/cloud_process.rb +30 -0
- data/lib/providers/hpcloud/compute.rb +105 -0
- data/lib/providers/hpcloud/hpcloud.rb +463 -0
- data/lib/providers/hpcloud/network.rb +115 -0
- data/lib/providers/hpcloud/security_groups.rb +68 -0
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +410 -0
- data/lib/providers/openstack/openstack_create.rb +206 -0
- data/lib/providers/openstack/openstack_delete.rb +28 -0
- data/lib/providers/openstack/openstack_get.rb +39 -0
- data/lib/providers/openstack/openstack_process.rb +26 -0
- data/lib/providers/openstack/openstack_query.rb +96 -0
- data/lib/providers/openstack/openstack_update.rb +35 -0
- data/lib/providers/templates/compute.rb +40 -0
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +32 -0
- data/lorj_cloud.gemspec +32 -0
- metadata +175 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
+
|
21
|
+
# Subnetwork Management
|
22
|
+
class CloudProcess
|
23
|
+
def forj_get_or_create_subnetwork(sCloudObj, hParams)
|
24
|
+
subnets = query_subnet(sCloudObj, hParams)
|
25
|
+
unless subnets.length == 0
|
26
|
+
register(subnets[0])
|
27
|
+
return subnets[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create the subnet
|
31
|
+
subnet = create_subnet(sCloudObj, hParams)
|
32
|
+
|
33
|
+
return nil if subnet.nil?
|
34
|
+
register(subnet)
|
35
|
+
subnet
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Define framework object on BaseDefinition
|
40
|
+
# Identify subnetwork as part of network.
|
41
|
+
class Lorj::BaseDefinition
|
42
|
+
define_obj(:subnetwork,
|
43
|
+
:create_e => :forj_get_or_create_subnetwork
|
44
|
+
)
|
45
|
+
|
46
|
+
obj_needs :CloudObject, :network_connection
|
47
|
+
obj_needs :CloudObject, :network
|
48
|
+
obj_needs :data, :subnetwork_name
|
49
|
+
|
50
|
+
def_attribute :network_id
|
51
|
+
end
|
52
|
+
|
53
|
+
# Subnetwork Management - internal functions
|
54
|
+
class CloudProcess
|
55
|
+
def create_subnet(sCloudObj, hParams)
|
56
|
+
name = hParams[:subnetwork_name]
|
57
|
+
PrcLib.state("Creating subnet '%s'", name)
|
58
|
+
begin
|
59
|
+
subnet = controller_create(sCloudObj, hParams)
|
60
|
+
PrcLib.info("Subnet '%s' created.", subnet[:name])
|
61
|
+
rescue => e
|
62
|
+
PrcLib.fatal(1, "Unable to create '%s' subnet.", name, e)
|
63
|
+
end
|
64
|
+
subnet
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_subnet
|
68
|
+
net_conn_obj = get_cloudObj(:network_connection)
|
69
|
+
sub_net_obj = get_cloudObj(:subnetwork)
|
70
|
+
|
71
|
+
PrcLib.state("Deleting subnet '%s'", sub_net_obj.name)
|
72
|
+
begin
|
73
|
+
provider_delete_subnetwork(net_conn_obj, sub_net_obj)
|
74
|
+
net_conn_obj.subnets.get(sub_net_obj.id).destroy
|
75
|
+
rescue => e
|
76
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def query_subnet(sCloudObj, hParams)
|
81
|
+
PrcLib.state('Searching for sub-network attached to '\
|
82
|
+
"network '%s'", hParams[:network, :name])
|
83
|
+
#######################
|
84
|
+
begin
|
85
|
+
query = { :network_id => hParams[:network, :id] }
|
86
|
+
info = {
|
87
|
+
:notfound => "No %s found from '%s' network",
|
88
|
+
:checkmatch => "Found 1 %s. checking exact match for network '%s'.",
|
89
|
+
:nomatch => "No %s for network '%s' match"
|
90
|
+
}
|
91
|
+
query_single(sCloudObj, query, hParams[:network, :name], info)
|
92
|
+
rescue => e
|
93
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
cloud_path = File.dirname(__FILE__)
|
20
|
+
|
21
|
+
# Define model
|
22
|
+
|
23
|
+
lorj_objects = %w(common connection network subnetwork router
|
24
|
+
external_network security_groups rules
|
25
|
+
keypairs images flavor internet_network server public_ip
|
26
|
+
server_log internet_server)
|
27
|
+
|
28
|
+
lorj_objects.each do |name|
|
29
|
+
load File.join(cloud_path, 'cloud', 'process', name + '.rb')
|
30
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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
|
@@ -0,0 +1,463 @@
|
|
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
|
+
attr_value_mapping :error, 'ERROR'
|
107
|
+
|
108
|
+
# ************************************ SERVER log Object
|
109
|
+
define_obj :server_log
|
110
|
+
|
111
|
+
# Excon::Response object type
|
112
|
+
def_attr_mapping :output, 'output'
|
113
|
+
|
114
|
+
# ************************************* Public IP Object
|
115
|
+
define_obj :public_ip
|
116
|
+
def_attr_mapping :server_id, :instance_id
|
117
|
+
def_attr_mapping :public_ip, :ip
|
118
|
+
|
119
|
+
# defines setup Cloud data (:account => true for setup)
|
120
|
+
define_data(:account_id,
|
121
|
+
:account => true,
|
122
|
+
:desc => 'HPCloud Access Key (From horizon, user drop down, '\
|
123
|
+
'manage keys)',
|
124
|
+
:validate => /^[A-Z0-9]*$/
|
125
|
+
)
|
126
|
+
define_data(:account_key,
|
127
|
+
:account => true,
|
128
|
+
:desc => 'HPCloud secret Key (From horizon, user drop down, '\
|
129
|
+
'manage keys)',
|
130
|
+
:encrypted => false,
|
131
|
+
:validate => /^.+/
|
132
|
+
)
|
133
|
+
define_data(:auth_uri,
|
134
|
+
:account => true,
|
135
|
+
:desc => 'HPCloud Authentication service URL (default is HP '\
|
136
|
+
'Public cloud)',
|
137
|
+
:validate => %r{^http(s)?://.*$},
|
138
|
+
:default_value => 'https://region-a.geo-1.identity.hpcloudsvc'\
|
139
|
+
'.com:35357/v2.0/'
|
140
|
+
)
|
141
|
+
define_data(:tenant,
|
142
|
+
:account => true,
|
143
|
+
:desc => 'HPCloud Tenant ID (from horizon, identity, projecs,'\
|
144
|
+
' Project ID)',
|
145
|
+
:validate => /^[0-9]+$/
|
146
|
+
)
|
147
|
+
|
148
|
+
define_data(:compute,
|
149
|
+
:account => true,
|
150
|
+
:desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)',
|
151
|
+
:depends_on => [:account_id, :account_key, :auth_uri, :tenant],
|
152
|
+
:list_values => {
|
153
|
+
:query_type => :controller_call,
|
154
|
+
:object => :services,
|
155
|
+
:query_call => :get_services,
|
156
|
+
:query_params => { :list_services => [:Compute, :compute] },
|
157
|
+
:validate => :list_strict
|
158
|
+
}
|
159
|
+
)
|
160
|
+
|
161
|
+
define_data(:network,
|
162
|
+
:account => true,
|
163
|
+
:desc => 'HPCloud Network service zone (Ex: region-a.geo-1)',
|
164
|
+
:depends_on => [:account_id, :account_key, :auth_uri, :tenant],
|
165
|
+
:list_values => {
|
166
|
+
:query_type => :controller_call,
|
167
|
+
:object => :services,
|
168
|
+
:query_call => :get_services,
|
169
|
+
:query_params => { :list_services => [:Networking, :network] },
|
170
|
+
:validate => :list_strict
|
171
|
+
}
|
172
|
+
)
|
173
|
+
|
174
|
+
data_value_mapping 'xsmall', 'standard.xsmall'
|
175
|
+
data_value_mapping 'small', 'standard.small'
|
176
|
+
data_value_mapping 'medium', 'standard.medium'
|
177
|
+
data_value_mapping 'large', 'standard.large'
|
178
|
+
data_value_mapping 'xlarge', 'standard.xlarge'
|
179
|
+
end
|
180
|
+
|
181
|
+
# Following class describe how FORJ should handle HP Cloud objects.
|
182
|
+
# Except Cloud connection, all HPCloud objects management are described/called
|
183
|
+
# in HP* modules.
|
184
|
+
class HpcloudController # rubocop: disable Metrics/ClassLength
|
185
|
+
def connect(sObjectType, hParams)
|
186
|
+
case sObjectType
|
187
|
+
when :services
|
188
|
+
Fog::HP.authenticate_v2(hParams[:hdata], hParams[:excon_opts])
|
189
|
+
when :compute_connection
|
190
|
+
Fog::Compute.new hParams[:hdata].merge(:provider => :hp, :version => 'v2')
|
191
|
+
when :network_connection
|
192
|
+
Fog::HP::Network.new(hParams[:hdata])
|
193
|
+
else
|
194
|
+
controller_error "'%s' is not a valid object for 'connect'", sObjectType
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# rubocop: disable MethodLength, CyclomaticComplexity, AbcSize
|
199
|
+
|
200
|
+
# Create controller for Hpcloud
|
201
|
+
def create(sObjectType, hParams)
|
202
|
+
case sObjectType
|
203
|
+
when :public_ip
|
204
|
+
required?(hParams, :compute_connection)
|
205
|
+
required?(hParams, :server)
|
206
|
+
HPCompute.server_assign_address(hParams[:compute_connection],
|
207
|
+
hParams[:server])
|
208
|
+
when :server
|
209
|
+
required?(hParams, :compute_connection)
|
210
|
+
required?(hParams, :image)
|
211
|
+
required?(hParams, :network)
|
212
|
+
required?(hParams, :flavor)
|
213
|
+
required?(hParams, :keypairs)
|
214
|
+
required?(hParams, :security_groups)
|
215
|
+
required?(hParams, :server_name)
|
216
|
+
|
217
|
+
options = {
|
218
|
+
:name => hParams[:server_name],
|
219
|
+
:flavor_id => hParams[:flavor].id,
|
220
|
+
:image_id => hParams[:image].id,
|
221
|
+
:key_name => hParams[:keypairs].name,
|
222
|
+
:security_groups => [hParams[:security_groups].name],
|
223
|
+
:networks => [hParams[:network].id]
|
224
|
+
}
|
225
|
+
|
226
|
+
HPCompute.create_server(hParams[:compute_connection], options,
|
227
|
+
hParams[:user_data], hParams[:meta_data])
|
228
|
+
when :image
|
229
|
+
required?(hParams, :compute_connection)
|
230
|
+
required?(hParams, :image_name)
|
231
|
+
|
232
|
+
HPCompute.get_image(hParams[:compute_connection], hParams[:image_name])
|
233
|
+
when :network
|
234
|
+
required?(hParams, :network_connection)
|
235
|
+
required?(hParams, :network_name)
|
236
|
+
|
237
|
+
HPNetwork.create_network(hParams[:network_connection],
|
238
|
+
hParams[:network_name])
|
239
|
+
when :subnetwork
|
240
|
+
required?(hParams, :network_connection)
|
241
|
+
required?(hParams, :network)
|
242
|
+
required?(hParams, :subnetwork_name)
|
243
|
+
|
244
|
+
HPNetwork.create_subnetwork(hParams[:network_connection],
|
245
|
+
hParams[:network],
|
246
|
+
hParams[:subnetwork_name])
|
247
|
+
when :security_groups
|
248
|
+
required?(hParams, :network_connection)
|
249
|
+
required?(hParams, :security_group)
|
250
|
+
|
251
|
+
HPSecurityGroups.create_sg(hParams[:network_connection],
|
252
|
+
hParams[:security_group], hParams[:sg_desc])
|
253
|
+
when :keypairs
|
254
|
+
required?(hParams, :compute_connection)
|
255
|
+
required?(hParams, :keypair_name)
|
256
|
+
required?(hParams, :public_key)
|
257
|
+
|
258
|
+
HPKeyPairs.create_keypair(hParams[:compute_connection],
|
259
|
+
hParams[:keypair_name], hParams[:public_key])
|
260
|
+
when :router
|
261
|
+
required?(hParams, :network_connection)
|
262
|
+
required?(hParams, :router_name)
|
263
|
+
|
264
|
+
# Forcelly used admin_status_up to true.
|
265
|
+
hParams[:hdata] = hParams[:hdata].merge(:admin_state_up => true)
|
266
|
+
|
267
|
+
HPNetwork.create_router(hParams[:network_connection], hParams[:hdata])
|
268
|
+
when :rule
|
269
|
+
required?(hParams, :network_connection)
|
270
|
+
required?(hParams, :security_groups)
|
271
|
+
HPSecurityGroups.create_rule(hParams[:network_connection],
|
272
|
+
hParams[:hdata])
|
273
|
+
when :router_interface
|
274
|
+
required?(hParams, :router)
|
275
|
+
required?(hParams, :subnetwork)
|
276
|
+
HPNetwork.add_interface(hParams[:router], hParams[:subnetwork])
|
277
|
+
else
|
278
|
+
controller_error "'%s' is not a valid object for 'create'", sObjectType
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# This function return a collection which have to provide:
|
283
|
+
# functions: [], length, each
|
284
|
+
# Used by network process.
|
285
|
+
def query(sObjectType, sQuery, hParams)
|
286
|
+
case sObjectType
|
287
|
+
when :public_ip
|
288
|
+
required?(hParams, :compute_connection)
|
289
|
+
required?(hParams, :server)
|
290
|
+
HPCompute.query_server_assigned_addresses(hParams[:compute_connection],
|
291
|
+
hParams[:server], sQuery)
|
292
|
+
when :server
|
293
|
+
required?(hParams, :compute_connection)
|
294
|
+
HPCompute.query_server(hParams[:compute_connection], sQuery)
|
295
|
+
when :image
|
296
|
+
required?(hParams, :compute_connection)
|
297
|
+
HPCompute.query_image(hParams[:compute_connection], sQuery)
|
298
|
+
when :network
|
299
|
+
required?(hParams, :network_connection)
|
300
|
+
HPNetwork.query_network(hParams[:network_connection], sQuery)
|
301
|
+
when :subnetwork
|
302
|
+
required?(hParams, :network_connection)
|
303
|
+
HPNetwork.query_subnetwork(hParams[:network_connection], sQuery)
|
304
|
+
when :router
|
305
|
+
required?(hParams, :network_connection)
|
306
|
+
HPNetwork.query_router(hParams[:network_connection], sQuery)
|
307
|
+
when :port
|
308
|
+
required?(hParams, :network_connection)
|
309
|
+
HPNetwork.query_port(hParams[:network_connection], sQuery)
|
310
|
+
when :security_groups
|
311
|
+
required?(hParams, :network_connection)
|
312
|
+
HPSecurityGroups.query_sg(hParams[:network_connection], sQuery)
|
313
|
+
when :rule
|
314
|
+
required?(hParams, :network_connection)
|
315
|
+
HPSecurityGroups.query_rule(hParams[:network_connection], sQuery)
|
316
|
+
when :keypairs
|
317
|
+
required?(hParams, :compute_connection)
|
318
|
+
HPKeyPairs.query_keypair(hParams[:compute_connection], sQuery)
|
319
|
+
when :flavor
|
320
|
+
required?(hParams, :compute_connection)
|
321
|
+
HPCompute.query_flavor(hParams[:compute_connection], sQuery)
|
322
|
+
else
|
323
|
+
controller_error "'%s' is not a valid object for 'query'", sObjectType
|
324
|
+
end
|
325
|
+
end
|
326
|
+
# rubocop: enable CyclomaticComplexity, MethodLength
|
327
|
+
|
328
|
+
def delete(sObjectType, hParams)
|
329
|
+
case sObjectType
|
330
|
+
when :network
|
331
|
+
HPNetwork.delete_network(hParams[:network_connection],
|
332
|
+
hParams[:network])
|
333
|
+
when :rule
|
334
|
+
HPSecurityGroups.delete_rule(hParams[:network_connection],
|
335
|
+
hParams[:id])
|
336
|
+
obj = hParams[:network_connection]
|
337
|
+
obj.security_group_rules.get(hParams[:id]).destroy
|
338
|
+
when :server
|
339
|
+
required?(hParams, :compute_connection)
|
340
|
+
required?(hParams, :server)
|
341
|
+
HPCompute.delete_server(hParams[:compute_connection],
|
342
|
+
hParams[:server])
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def get(sObjectType, sUniqId, hParams)
|
347
|
+
case sObjectType
|
348
|
+
when :server_log
|
349
|
+
required?(hParams, :server)
|
350
|
+
|
351
|
+
hParams[:server].console_output(sUniqId)
|
352
|
+
when :server
|
353
|
+
required?(hParams, :compute_connection)
|
354
|
+
HPCompute.get_server(hParams[:compute_connection], sUniqId)
|
355
|
+
when :image
|
356
|
+
required?(hParams, :compute_connection)
|
357
|
+
HPCompute.get_image(hParams[:compute_connection], sUniqId)
|
358
|
+
when :network
|
359
|
+
required?(hParams, :network_connection)
|
360
|
+
HPNetwork.get_network(hParams[:network_connection], sUniqId)
|
361
|
+
when :keypairs
|
362
|
+
required?(hParams, :compute_connection)
|
363
|
+
HPKeyPairs.get_keypair(hParams[:compute_connection], sUniqId)
|
364
|
+
else
|
365
|
+
forjError "'%s' is not a valid object for 'get'", sObjectType
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def query_each(oFogObject)
|
370
|
+
case oFogObject.class.to_s
|
371
|
+
when 'Fog::HP::Network::Networks'
|
372
|
+
oFogObject.each { |value| yield(value) }
|
373
|
+
else
|
374
|
+
controller_error "'%s' is not a valid list for 'each'",
|
375
|
+
oFogObject.class
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def get_attr(oControlerObject, key)
|
380
|
+
if oControlerObject.is_a?(Excon::Response)
|
381
|
+
oControlerObject.data.rh_get(:body, key)
|
382
|
+
else
|
383
|
+
attributes = oControlerObject.attributes
|
384
|
+
def_attributes = oControlerObject.class.attributes
|
385
|
+
controller_error "attribute '%s' is unknown in '%s'. "\
|
386
|
+
"Valid one are : '%s'",
|
387
|
+
key[0], oControlerObject.class,
|
388
|
+
def_attributes unless def_attributes.include?(key[0])
|
389
|
+
attributes.rh_get(key)
|
390
|
+
end
|
391
|
+
rescue => e
|
392
|
+
controller_error "Unable to map '%s'. %s", key, e.message
|
393
|
+
end
|
394
|
+
|
395
|
+
def set_attr(oControlerObject, key, value)
|
396
|
+
controller_class = oControlerObject.class
|
397
|
+
|
398
|
+
controller_error "No set feature for '%s'",
|
399
|
+
controller_class if oControlerObject.is_a?(Excon::Response)
|
400
|
+
|
401
|
+
attributes = oControlerObject.attributes
|
402
|
+
def_attributes = oControlerObject.class.attributes
|
403
|
+
controller_error "attribute '%s' is unknown in '%s'. Valid one are : '%s'",
|
404
|
+
key[0], oControlerObject.class,
|
405
|
+
def_attributes unless def_attributes.include?(key[0])
|
406
|
+
attributes.rh_set(value, key)
|
407
|
+
rescue => e
|
408
|
+
controller_error "Unable to map '%s' on '%s'\n%s",
|
409
|
+
key, sObjectType, e.message
|
410
|
+
end
|
411
|
+
|
412
|
+
def update(sObjectType, oObject, _hParams)
|
413
|
+
case sObjectType
|
414
|
+
when :router
|
415
|
+
controller_error 'Object to update is nil' if oObject.nil?
|
416
|
+
|
417
|
+
HPNetwork.update_router(oObject[:object])
|
418
|
+
else
|
419
|
+
controller_error "'%s' is not a valid list for 'update'",
|
420
|
+
oFogObject.class
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
# This function requires to return an Array of values or nil.
|
425
|
+
def get_services(sObjectType, oParams)
|
426
|
+
case sObjectType
|
427
|
+
when :services
|
428
|
+
# oParams[sObjectType] will provide the controller object.
|
429
|
+
# This one can be interpreted only by controller code,
|
430
|
+
# except if controller declares how to map with this object.
|
431
|
+
# Processes can deal only process mapped data.
|
432
|
+
# Currently there is no services process function. No need to map.
|
433
|
+
services = oParams[:services]
|
434
|
+
if !oParams[:list_services].is_a?(Array)
|
435
|
+
service_to_find = [oParams[:list_services]]
|
436
|
+
else
|
437
|
+
service_to_find = oParams[:list_services]
|
438
|
+
end
|
439
|
+
# Search for service. Ex: Can be :Networking or network. I currently do
|
440
|
+
# not know why...
|
441
|
+
search_services = services.rh_get(:service_catalog)
|
442
|
+
service = nil
|
443
|
+
service_to_find.each do |sServiceElem|
|
444
|
+
if search_services.key?(sServiceElem)
|
445
|
+
service = sServiceElem
|
446
|
+
break
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
controller_error 'Unable to find services %s',
|
451
|
+
service_to_find if service.nil?
|
452
|
+
result = services.rh_get(:service_catalog, service).keys
|
453
|
+
result.delete('name')
|
454
|
+
result.each_index do |iIndex|
|
455
|
+
result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
|
456
|
+
end
|
457
|
+
return result
|
458
|
+
else
|
459
|
+
controller_error "'%s' is not a valid object for 'get_services'",
|
460
|
+
sObjectType
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|