-
Notifications
You must be signed in to change notification settings - Fork 9
/
lb-add
executable file
·48 lines (35 loc) · 1.07 KB
/
lb-add
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
#!/usr/bin/env python
import getopt
import sys
from libcloud.loadbalancer.base import LoadBalancer, Member
from lctools.lc import get_lc
from lctools.printer import Printer
def usage(prog):
sys.stdout.write(("%s -n <name> [-p <profile> ]"
" [ -P <port> ] addr1:port1 add2:port2 ...\n\n") % prog)
if __name__ == "__main__":
profile = "default"
port = 80
name = None
try:
opts, args = getopt.getopt(sys.argv[1:], "p:P:n:")
except getopt.GetoptError, err:
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
for o, a in opts:
if o == "-p":
profile = a
elif o == "-P":
port = a
elif o == "-n":
name = a
conn = get_lc(profile, resource='loadbalancer')
members = []
for member in args:
addr, port = member.split(":")
members.append(Member(None, addr, port))
if name is None or len(members) == 0:
usage(sys.argv[0])
sys.exit(1)
balancer = conn.create_balancer(name=name, port=port, members=members)
print balancer