factor-connector-rackspace 0.0.6 → 0.0.7
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/lib/factor/connector/rackspace_loadbalancers.rb +121 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f330385bcfc4ca737e21561f5c53db7642086b7
|
4
|
+
data.tar.gz: c96973523b5e0ad345f59ef37c2af3f55cca52e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 038aa437c44c9dcd3a39f9a62afc7baa7c948af37e092f67311e9cfc23043e16e78e651c8eea7e1388b67f835df79364cae8b7ade5ac0e351d520930a0dcfd61
|
7
|
+
data.tar.gz: 12667c19cbf3e34933246a143b26b0ff22e45c27730df6faee488a0ff3298985eb973dae835cb6323e12df98ccd458b48e98086628259ef46061db2f4cb96961
|
@@ -36,9 +36,10 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
36
36
|
action 'get' do |params|
|
37
37
|
username = params['username']
|
38
38
|
api_key = params['api_key']
|
39
|
-
region = params['region']
|
40
|
-
load_balancer_id = params['
|
39
|
+
region = (params['region'] || 'ord').to_sym
|
40
|
+
load_balancer_id = params['id']
|
41
41
|
|
42
|
+
fail "Load Balancer ID (id) is required" unless load_balancer_id
|
42
43
|
fail "Username is required" unless username
|
43
44
|
fail "API key is required" unless api_key
|
44
45
|
|
@@ -66,12 +67,54 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
66
67
|
action_callback load_balancer_hash
|
67
68
|
end
|
68
69
|
|
70
|
+
action 'nodes' do |params|
|
71
|
+
username = params['username']
|
72
|
+
api_key = params['api_key']
|
73
|
+
load_balancer_id = params['id']
|
74
|
+
region = (params['region'] || 'ord').to_sym
|
75
|
+
|
76
|
+
fail "Load Balancer ID (id) is required" unless load_balancer_id
|
77
|
+
fail "Username is required" unless username
|
78
|
+
fail "API Key is required" unless api_key
|
79
|
+
|
80
|
+
balancer_payload = {
|
81
|
+
:rackspace_username => username,
|
82
|
+
:rackspace_api_key => api_key,
|
83
|
+
:rackspace_region => region
|
84
|
+
}
|
85
|
+
|
86
|
+
info "Initializing connection settings"
|
87
|
+
begin
|
88
|
+
fog_wrapper = Fog::Rackspace::LoadBalancers.new balancer_payload
|
89
|
+
rescue
|
90
|
+
fail "Couldn't initialize connection"
|
91
|
+
end
|
92
|
+
|
93
|
+
info "Retrieving load balancer #{load_balancer_id}"
|
94
|
+
begin
|
95
|
+
load_balancer = fog_wrapper.load_balancers.get(load_balancer_id)
|
96
|
+
rescue
|
97
|
+
fail "Failed to retrieve load balancer"
|
98
|
+
end
|
99
|
+
|
100
|
+
info "Retrieving list of nodes from #{load_balancer_id}"
|
101
|
+
begin
|
102
|
+
nodes = load_balancer.nodes.all.map { |s| s.attributes }
|
103
|
+
rescue => ex
|
104
|
+
error ex.message
|
105
|
+
fail "Failed to retrieve Nodes"
|
106
|
+
end
|
107
|
+
|
108
|
+
action_callback nodes
|
109
|
+
end
|
110
|
+
|
69
111
|
action 'delete' do |params|
|
70
112
|
username = params['username']
|
71
113
|
api_key = params['api_key']
|
72
114
|
region = (params['region'] || 'ord').to_sym
|
73
|
-
load_balancer_id = params['
|
115
|
+
load_balancer_id = params['id']
|
74
116
|
|
117
|
+
fail "Load Balancer ID (id) is required" unless load_balancer_id
|
75
118
|
fail "Username is required" unless username
|
76
119
|
fail "API Key is required" unless api_key
|
77
120
|
|
@@ -107,10 +150,14 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
107
150
|
protocol = params['protocol']
|
108
151
|
port = params['port']
|
109
152
|
ip_type = params['ip_type']
|
110
|
-
algorithm
|
153
|
+
algorithm = params['algorithm']
|
154
|
+
wait = params['wait']
|
111
155
|
|
112
|
-
fail "
|
113
|
-
fail "
|
156
|
+
fail "Name (name) is required" unless name
|
157
|
+
fail "Protocol (protocol) is required" unless protocol
|
158
|
+
fail "Port (port) is required" unless port
|
159
|
+
fail "Username (username) is required" unless username
|
160
|
+
fail "API Key (api_key) is required" unless api_key
|
114
161
|
|
115
162
|
balancer_payload = {
|
116
163
|
:rackspace_username => username,
|
@@ -125,7 +172,7 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
125
172
|
fail "Couldn't initialize connection"
|
126
173
|
end
|
127
174
|
|
128
|
-
info "Creating
|
175
|
+
info "Creating Load Balancer"
|
129
176
|
begin
|
130
177
|
load_balancer = fog_wrapper.create_load_balancer(name, protocol, port, virtual_ips = [{'type' => ip_type}], nodes = nil, options = {:algorithm => algorithm })
|
131
178
|
load_balancer_hash = load_balancer.body['loadBalancer']
|
@@ -133,20 +180,41 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
133
180
|
fail "Failed to create LoadBalancer"
|
134
181
|
end
|
135
182
|
|
183
|
+
|
184
|
+
if wait
|
185
|
+
load_balancer_id = load_balancer_hash['id']
|
186
|
+
info "Waiting until load balancer is done building"
|
187
|
+
(0..120).each do
|
188
|
+
lb = fog_wrapper.get_load_balancer(load_balancer_id)
|
189
|
+
break if lb.body['loadBalancer']['status'] != 'BUILD'
|
190
|
+
sleep 5
|
191
|
+
end
|
192
|
+
warn "Waited for 10 minutes but the LB is still building" if lb.body['loadBalancer']['status'] == 'BUILD'
|
193
|
+
end
|
194
|
+
|
136
195
|
action_callback load_balancer_hash
|
137
196
|
end
|
138
197
|
|
139
198
|
action 'add_node' do |params|
|
140
199
|
username = params['username']
|
141
200
|
api_key = params['api_key']
|
142
|
-
region = params['region']
|
143
|
-
load_balancer_id = params['
|
201
|
+
region = (params['region'] || 'ord').to_sym
|
202
|
+
load_balancer_id = params['id']
|
144
203
|
address = params['address']
|
145
204
|
port = params['port']
|
146
|
-
condition = params['condition']
|
205
|
+
condition = params['condition'] || 'ENABLED'
|
206
|
+
weight = params['weight']
|
207
|
+
type = params['type']
|
147
208
|
|
148
|
-
|
149
|
-
|
209
|
+
possible_conditions = %w(ENABLED DISABLED DRAINING)
|
210
|
+
|
211
|
+
fail "Address (address) is required" unless address
|
212
|
+
fail "Port (port) is required" unless port
|
213
|
+
fail "Condition (condition) is required" unless condition
|
214
|
+
fail "Condition must be set to 'ENABLED', 'DISABLED', or 'DRAINING'" unless possible_conditions.include?(condition)
|
215
|
+
fail "Load Balancer ID (id) is required" unless load_balancer_id
|
216
|
+
fail "Username (username) is required" unless username
|
217
|
+
fail "API Key (api_key) is required" unless api_key
|
150
218
|
|
151
219
|
balancer_payload = {
|
152
220
|
:rackspace_username => username,
|
@@ -161,9 +229,12 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
161
229
|
fail "Couldn't initialize connection"
|
162
230
|
end
|
163
231
|
|
164
|
-
info "Adding node"
|
232
|
+
info "Adding node #{address}:#{port} to load balancer #{load_balancer_id}"
|
165
233
|
begin
|
166
|
-
|
234
|
+
options = {}
|
235
|
+
options[:weight] = weight if weight
|
236
|
+
options[:type] = type if type
|
237
|
+
load_balancer = fog_wrapper.create_node(load_balancer_id, address, port, condition, options)
|
167
238
|
load_balancer_hash = load_balancer.body
|
168
239
|
rescue
|
169
240
|
info "Failed to add node"
|
@@ -171,4 +242,40 @@ Factor::Connector.service 'rackspace_load_balancers' do
|
|
171
242
|
|
172
243
|
action_callback load_balancer_hash
|
173
244
|
end
|
245
|
+
|
246
|
+
action 'remove_node' do |params|
|
247
|
+
username = params['username']
|
248
|
+
api_key = params['api_key']
|
249
|
+
region = (params['region'] || 'ord').to_sym
|
250
|
+
load_balancer_id = params['load_balancer_id']
|
251
|
+
node_id = params['id']
|
252
|
+
|
253
|
+
fail "Node ID (id) is required" unless node_id
|
254
|
+
fail "Load Balancer ID (load_balancer_id) is required" unless load_balancer_id
|
255
|
+
fail "Username (username) is required" unless username
|
256
|
+
fail "API Key (api_key) is required" unless api_key
|
257
|
+
|
258
|
+
balancer_payload = {
|
259
|
+
:rackspace_username => username,
|
260
|
+
:rackspace_api_key => api_key,
|
261
|
+
:rackspace_region => region
|
262
|
+
}
|
263
|
+
|
264
|
+
info "Initializing connection settings"
|
265
|
+
begin
|
266
|
+
fog_wrapper = Fog::Rackspace::LoadBalancers.new balancer_payload
|
267
|
+
rescue
|
268
|
+
fail "Couldn't initialize connection"
|
269
|
+
end
|
270
|
+
|
271
|
+
info "Deleting node #{node_id} from load balancer #{load_balancer_id}"
|
272
|
+
begin
|
273
|
+
node_info = fog_wrapper.delete_node(load_balancer_id, node_id)
|
274
|
+
node_info_hash = node_info.body
|
275
|
+
rescue
|
276
|
+
info "Failed to delete node"
|
277
|
+
end
|
278
|
+
|
279
|
+
action_callback node_info_hash
|
280
|
+
end
|
174
281
|
end
|