-
Notifications
You must be signed in to change notification settings - Fork 19
/
README.html
518 lines (435 loc) · 13.4 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" />
<title>Python interface to Rackspace Load Balancer as a Service product</title>
<style type="text/css">
/*
:Authors: Ian Bicking, Michael Foord
:Contact: [email protected]
:Date: 2005/08/26
:Version: 0.1.0
:Copyright: This stylesheet has been placed in the public domain.
Stylesheet for Docutils.
Based on ``blue_box.css`` by Ian Bicking
and ``default.css`` revision 3442
*/
@import url(default.css);
@import url(pygments.css);
body {
font-family: Arial, sans-serif;
}
em, i {
/* Typically serif fonts have much nicer italics */
font-family: Times New Roman, Times, serif;
}
a.target {
color: blue;
}
a.toc-backref {
text-decoration: none;
color: black;
}
a.toc-backref:hover {
background-color: inherit;
}
a:hover {
background-color: #cccccc;
}
div.attention, div.caution, div.danger, div.error, div.hint,
div.important, div.note, div.tip, div.warning {
background-color: #cccccc;
padding: 3px;
width: 80%;
}
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
text-align: center;
background-color: #999999;
display: block;
margin: 0;
}
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: #cc0000;
font-family: sans-serif;
text-align: center;
background-color: #999999;
display: block;
margin: 0;
}
h1, h2, h3, h4, h5, h6 {
font-family: Helvetica, Arial, sans-serif;
border: thin solid black;
/* This makes the borders rounded on Mozilla, which pleases me */
-moz-border-radius: 8px;
padding: 4px;
}
h1 {
background-color: #444499;
color: #ffffff;
border: medium solid black;
}
h1 a.toc-backref, h2 a.toc-backref {
color: #ffffff;
}
h2 {
background-color: #666666;
color: #ffffff;
border: medium solid black;
}
h3, h4, h5, h6 {
background-color: #cccccc;
color: #000000;
}
h3 a.toc-backref, h4 a.toc-backref, h5 a.toc-backref,
h6 a.toc-backref {
color: #000000;
}
h1.title {
text-align: center;
background-color: #444499;
color: #eeeeee;
border: thick solid black;
-moz-border-radius: 20px;
}
table.footnote {
padding-left: 0.5ex;
}
table.citation {
padding-left: 0.5ex
}
pre.literal-block, pre.doctest-block {
border: thin black solid;
padding: 5px;
}
.image img { border-style : solid;
border-width : 2px;
}
img.align-center {
display: block;
margin: auto;
text-align: center;
}
h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
font-size: 100%;
}
code, tt {
color: #000066;
}
</style>
</head>
<body>
<div class="document" id="python-interface-to-rackspace-load-balancer-as-a-service-product">
<h1 class="title">Python interface to Rackspace Load Balancer as a Service product</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr class="field"><th class="docinfo-name">Homepage:</th><td class="field-body"><a class="reference external" href="https://github.com/chmouel/python-cloudlb">https://github.com/chmouel/python-cloudlb</a></td>
</tr>
<tr class="field"><th class="docinfo-name">Credits:</th><td class="field-body">Copyright 2011 Chmouel Boudjnah <<a class="reference external" href="mailto:chmouel@chmouel.com">chmouel@chmouel.com</a>></td>
</tr>
<tr class="field"><th class="docinfo-name">Licence:</th><td class="field-body">BSD</td>
</tr>
</tbody>
</table>
<div class="section" id="usage">
<h1>Usage</h1>
<p>Not much documentation at the moment but just some quick typical usage
scripts you can do with this library. This is based on the latest version from :</p>
<p><a class="reference external" href="http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf">http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf</a></p>
<p>Create a LoadBalancer:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
node1 = cloudlb.Node(address="10.180.160.131",
port=80,
condition="ENABLED")
virtualIP1 = cloudlb.VirtualIP(
type="PUBLIC")
clb.loadbalancers.create(name="mytestinglb",
port=80,
protocol="HTTP",
nodes=[node1],
virtualIps=[virtualIp1])
</pre>
<p>List LoadBalancers:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
for lb in lbs:
print "%s has %s node attached with IP addresses:" % (lb.name, len(lb.nodes))
for ip in lb.virtualIps:
print "%s/%s" % (ip.ipVersion, ip.address)
</pre>
<p>Get LB by ID:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
clb.authenticate()
lb = clb.loadbalancers.get(LoadBalancerID)
</pre>
<p>Delete LB:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lb = clb.loadbalancers.get(LoadBalancerID)
lb.delete()
</pre>
<p>List deleted LBs:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list_deleted()
for x in lbs:
print x.name
</pre>
<p>List nodes of a LB:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list_deleted()
lb = lbs[0] #get the first one
for node in lb.nodes:
print node.address
</pre>
<p>Add a node to a LB:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
newnode = cloudlb.Node(address="10.180.160.131",
port=80,
condition="ENABLED")
lbs = clb.loadbalancers.list()
lb = lbs[0] #add to the first one
lb.add_nodes([newnode])
</pre>
<p>Delete a node from a LB:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
lb = lbs[0] #add to the first one
node = lb.nodes[0] #get the first node
node.delete() #delete it
</pre>
<p>Update attributes of a node:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #add to the first one
nodeid = 14106
nodes = mylb.nodes
node = mylb.nodes.get(nodeid)
toggle_status = node.condition == "ENABLED" and "DISABLED" or "ENABLED"
node.condition = toggle_status
node.update()
</pre>
<p>Get weight of a node by using .get():</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #add to the first one
nodeid = 14106
nodes = mylb.nodes
node = mylb.nodes.get(nodeid)
print node.weight
</pre>
<p>Update attributes on LoadBalancer:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
mylb.protocol = "FTP"
mylb.name = "APrettyNewName"
mylb.update()
</pre>
<p>Get usage statitiscs on all LoadBalancers:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
print clb.get_usage()
</pre>
<p>Get usage statitiscs on a specfic LoadBalancer:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
print mylb.get_usage()
</pre>
<p>Get limits on all LoadBalancers:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
print clb.get_limits()
</pre>
<p>Get Load Balancing Algorithms:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
print clb.get_algorithms()
</pre>
<p>Get Load Balancing Protocols:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
print clb.get_protocols()
</pre>
<p>Get current Health Monitor:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
hm_monitor = mylb.healthmonitor()
print hm_monitor.get()
</pre>
<p>Monitor loadbalancer using simple TCP Connect:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
hm_monitor = mylb.healthmonitor()
hm = cloudlb.healthmonitor.HealthMonitor(
type="CONNECT",
delay=10,
timeout=10,
attemptsBeforeDeactivation=3)
hm_monitor.add(hm)
</pre>
<p>Monitor loadbalancer using HTTP(s):</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
hm_monitor = mylb.healthmonitor()
hm = cloudlb.healthmonitor.HealthMonitor(
type="HTTP", #or HTTPS
delay=10,
timeout=10,
attemptsBeforeDeactivation=3,
path="/",
statusRegex="",
bodyRegex="testing")
hm_monitor.add(hm)
</pre>
<p>Delete Health Monitor rule:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
hm_monitor = mylb.healthmonitor()
hm_monitor.delete()
</pre>
<p>Add http cookie session persistense:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
ss = cloudlb.sessionpersistense.SessionPersistense(persistenceType="HTTP_COOKIE")
ssp = mylb.session_persistense()
ssp.add(ss)
</pre>
<p>Get session persistense:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
ssp = mylb.session_persistense()
print ssp.get()
</pre>
<p>Delete session persistense configuration:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
ssp = mylb.session_persistense()
ssp.delete()
</pre>
<p>Enable/Disable Connection Logging:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
cl = mylb.connection_logging()
#Get connection logging status
print cl.get()
#Enable connection logging
cl.enable()
#Disable connection logging
cl.disable()
</pre>
<p>Access Lists:</p>
<pre class="literal-block">
#!/usr/bin/python
import cloudlb
clb = cloudlb.CloudLoadBalancer("username", "apikey","chicago")
lbs = clb.loadbalancers.list()
mylb = lbs[0] #first lb
accesslist = mylb.accesslist()
networkItem1 = cloudlb.accesslist.NetworkItem(
address="10.20.30.40", type="ALLOW")
networkItem2 = cloudlb.accesslist.NetworkItem(
address="0.0.0.0/0", type="DENY")
# Allow only 10.20.30.40
accesslist.add([networkItem1, networkItem2])
# List accesslists
print accesslist.list()
# Delete all accesslist
accesslist.delete()
# Delete accesslist by ID (TODO: Not working ATM)
# accesslist.delete(id=62)
</pre>
</div>
<div class="section" id="license">
<h1>LICENSE</h1>
<p>See COPYING for license information. Copyright © 2011, Rackspace US, Inc.</p>
</div>
<div class="section" id="author">
<h1>Author</h1>
<p>Chmouel Boudjnah <<a class="reference external" href="mailto:chmouel@chmouel.com">chmouel@chmouel.com</a>></p>
</div>
</div>
</body>
</html>