-
Notifications
You must be signed in to change notification settings - Fork 9
/
lb-member-add
executable file
·42 lines (29 loc) · 962 Bytes
/
lb-member-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
#!/usr/bin/env python
import getopt
import sys
from libcloud.loadbalancer.base import LoadBalancer, Member
from lctools.lc import get_lc
def usage(prog):
sys.stdout.write(("%s [-p <profile> ] -i <id> addr:port\n\n") % prog)
if __name__ == "__main__":
profile = "default"
lb_id = None
try:
opts, args = getopt.getopt(sys.argv[1:], "p:i:")
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 == "-i":
lb_id = a
conn = get_lc(profile, resource='loadbalancer')
if lb_id is None and len(args) != 1:
usage(sys.argv[0])
sys.exit(1)
balancer = LoadBalancer(lb_id, None, None, None, None, None)
node_addr, node_port = args[0].split(":")
sys.exit(int(not conn.balancer_attach_member(balancer,
Member(None, ip=node_addr, port=node_port))
))