1 #!/usr/local/bin/python
9 self.http = httplib2.Http(".cache")
10 self.http.add_credentials("admin", "admin")
11 self.url_prefix = "http://localhost:8080/affinity/nb/v2/affinity/default/"
14 def add_affinity_group(self, group_name, **kwargs):
16 resp, content = self.http.request(self.url_prefix + "create/group/%s" % group_name, "PUT")
17 if (resp.status != 201):
18 print "AffinityGroup %s could not be created" % group_name
20 # If a list of IPs is passed, add each one
24 resp, content = self.http.request(self.url_prefix + "group/%s/add/ip/%s" % (group_name, ip), "PUT")
25 if (resp.status != 201):
26 print "IP %s could not be added to AffinityGroup %s" % (ip, group_name)
28 print "AffinityGroup %s added successfully. IPs are %s" % (group_name, ips)
29 # If a subnet is passed, add that
30 elif "subnet" in kwargs:
31 ip, mask = kwargs['subnet'].split("/")
32 resp, content = self.http.request(self.url_prefix + "group/%s/addsubnet/ipprefix/%s/mask/%s" % (group_name, ip, mask), "PUT")
33 if (resp.status != 201):
34 print "AffinityGroup could not be created for subnet %s/%s" % (ip, mask)
36 print "AffinityGroup %s added successfully. Subnet is %s/%s" % (group_name, ip, mask)
39 def add_affinity_link(self, link_name, src_group, dst_group):
40 resp, content = self.http.request(self.url_prefix + "create/link/%s/from/%s/to/%s" % (link_name, src_group, dst_group), "PUT")
41 if (resp.status != 201):
42 print "AffinityLink %s could not be added between %s and %s" % (link_name, src_group, dst_group)
44 print "AffinityLink %s added between %s and %s" % (link_name, src_group, dst_group)
47 def add_waypoint(self, link_name, ip):
48 resp, content = self.http.request(self.url_prefix + "link/%s/setwaypoint/%s" % (link_name, ip), "PUT")
49 if (resp.status != 201):
50 print "Waypoint %s could not be set for link %s" % (ip, link_name)
52 print "Waypoint %s successfully set for link %s" % (ip, link_name)
55 def enable_waypoint(self, link_name):
56 resp, content = self.http.request(self.url_prefix + "link/%s/enable" % link_name, "PUT")
57 if (resp.status != 201):
58 print "Waypoint could not be enabled for link %s" % link_name
61 print "Waypoint enabled for link %s" % link_name