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,115 @@
|
|
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
|
@@ -0,0 +1,68 @@
|
|
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
|
@@ -0,0 +1,144 @@
|
|
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
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
21
|
+
class Mock
|
22
|
+
# mock do not need to use any mapping. It adapts itself to what the process
|
23
|
+
# has defined.
|
24
|
+
end
|
25
|
+
|
26
|
+
# This Mock controller keep the data in memory in hash/Array data.
|
27
|
+
class MockController
|
28
|
+
@@data = {} # rubocop: disable ClassVars
|
29
|
+
|
30
|
+
def create(sObjectType, hParams)
|
31
|
+
PrcLib.debug("Mock: create object '%s' with parameters (hdata) '%s'",
|
32
|
+
sObjectType, hParams[:hdata])
|
33
|
+
|
34
|
+
result = {}
|
35
|
+
hParams[].keys.each do |key|
|
36
|
+
next if key == :hdata
|
37
|
+
result[key] = hParams[key]
|
38
|
+
end
|
39
|
+
result.merge!(hParams[:hdata])
|
40
|
+
|
41
|
+
@@data[sObjectType] = [] unless @@data.key?(sObjectType)
|
42
|
+
|
43
|
+
array = @@data[sObjectType]
|
44
|
+
|
45
|
+
array.each do |value|
|
46
|
+
fail if value.key?(result[:name])
|
47
|
+
end
|
48
|
+
array << result
|
49
|
+
|
50
|
+
result[:id] = array.length - 1
|
51
|
+
|
52
|
+
# Typical code:
|
53
|
+
# ~ case sObjectType
|
54
|
+
# ~ when :public_ip
|
55
|
+
# Following function can be executed to ensure the object :connection exists
|
56
|
+
# ~ required?(hParams, :connection)
|
57
|
+
# ~ required?(hParams, :server)
|
58
|
+
# ~ ... CODE to create
|
59
|
+
# ~ else
|
60
|
+
# ~ controller_error "'%s' is not a valid object for 'create'", sObjectType
|
61
|
+
# ~ end
|
62
|
+
# The code should return some data
|
63
|
+
# This data will be encapsulated in Lorj::Data object.
|
64
|
+
# data will be extracted by the framework with the controller get_attr
|
65
|
+
# function and mapped.
|
66
|
+
PrcLib.debug("Mock: object '%s' = '%s' is created.", sObjectType, result)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
# This function return a collection which have to provide:
|
71
|
+
# functions: [], length, each
|
72
|
+
# Used by network process.
|
73
|
+
def query(sObjectType, sQuery, hParams)
|
74
|
+
PrcLib.debug("Mock: query object '%s' with hdata '%s' using query '%s'",
|
75
|
+
sObjectType, hParams[:hdata], sQuery)
|
76
|
+
|
77
|
+
return [] unless @@data.key?(sObjectType)
|
78
|
+
|
79
|
+
result = []
|
80
|
+
|
81
|
+
@@data[sObjectType].each do |value|
|
82
|
+
elem = value
|
83
|
+
sQuery.each do |query_key, query_value|
|
84
|
+
elem = nil if !value.key?(query_key) || value[query_key] != query_value
|
85
|
+
end
|
86
|
+
result << elem if elem
|
87
|
+
end
|
88
|
+
result
|
89
|
+
end
|
90
|
+
|
91
|
+
def delete(sObjectType, hParams)
|
92
|
+
PrcLib.debug("Mock: delete object '%s' with hdata '%s'",
|
93
|
+
sObjectType, hParams[:hdata])
|
94
|
+
return nil unless @@data.key?(sObjectType)
|
95
|
+
|
96
|
+
return false if !hParams.exist?(sObjectType) || hParams[sObjectType].nil?
|
97
|
+
@@data[sObjectType].delete(hParams[sObjectType])
|
98
|
+
PrcLib.debug("Mock: object '%s' = '%s' is deleted.",
|
99
|
+
sObjectType, hParams[sObjectType])
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
def get(sObjectType, sUniqId, hParams)
|
104
|
+
PrcLib.debug("Mock: Get object '%s' = '%s' with hdata '%s'",
|
105
|
+
sObjectType, sUniqId, hParams[:hdata])
|
106
|
+
return nil unless @@data.key?(sObjectType)
|
107
|
+
@@data[sObjectType][sUniqId]
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_attr(oControlerObject, key)
|
111
|
+
# This controller function read the data and
|
112
|
+
# extract the information requested by the framework.
|
113
|
+
# Those data will be mapped to the process data model.
|
114
|
+
# The key is an array, to get data from a level tree.
|
115
|
+
# [data_l1, data_l2, data_l3] => should retrieve data from structure like
|
116
|
+
# data[ data_l2[ data_l3 ] ]
|
117
|
+
attributes = oControlerObject
|
118
|
+
|
119
|
+
attributes.rh_get(key)
|
120
|
+
rescue => e
|
121
|
+
controller_error "Unable to map '%s'.\n%s", key, e.message
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_attr(oControlerObject, key, value)
|
125
|
+
attributes = oControlerObject
|
126
|
+
|
127
|
+
attributes.rh_set(value, key)
|
128
|
+
rescue => e
|
129
|
+
controller_error "Unable to map '%s' on '%s'.\n%s",
|
130
|
+
key, sObjectType, e.message
|
131
|
+
end
|
132
|
+
|
133
|
+
def update(sObjectType, oObject, hParams)
|
134
|
+
PrcLib.debug("Mock: Update object '%s' = '%s' with hdata '%s'",
|
135
|
+
sObjectType, sUniqId, hParams[:hdata])
|
136
|
+
return false unless @@data.key?(sObjectType)
|
137
|
+
|
138
|
+
return false unless @@data[sObjectType][oObject[:id]].nil?
|
139
|
+
# Considered hash object is already updated.
|
140
|
+
# This action emule the object save which doesn't make sense in this empty
|
141
|
+
# Mock controller.
|
142
|
+
true
|
143
|
+
end
|
144
|
+
end
|