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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c7fd97ba1f4dcfffff47b62ea024fa7c6ab5bf0
4
- data.tar.gz: f0a851fa2a1b8fe08a558a6b5dfc2b608e434fe1
3
+ metadata.gz: 5f330385bcfc4ca737e21561f5c53db7642086b7
4
+ data.tar.gz: c96973523b5e0ad345f59ef37c2af3f55cca52e0
5
5
  SHA512:
6
- metadata.gz: 6809c7e4f1492ad193580dbd68cfb04a3c4866a383e32363694b0a18ec2bbcf454020d9d05780331d222184d61db006e3cd9cd8f5e755dfe70034199dca7994a
7
- data.tar.gz: 55ccf88e5e73ad0447f5842e8e8233466245c3142aeb877416c0713de437031c9b1176087fffb1f824809e582ea1ce160836e7e0742ed8bb47a6d6063464098d
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['load_balancer_id']
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['load_balancer_id']
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 = params['algorithm']
153
+ algorithm = params['algorithm']
154
+ wait = params['wait']
111
155
 
112
- fail "Username is required" unless username
113
- fail "API Key is required" unless api_key
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 LoadBalancer"
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['load_balancer_id']
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
- fail "Username is required" unless username
149
- fail "API Key is required" unless api_key
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
- load_balancer = fog_wrapper.create_node(load_balancer_id, address, port, condition, options = {})
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor-connector-rackspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski