1 #!/usr/local/bin/python
8 # Configure an affinity link and set its waypoint address.
11 def rest_method(url, verb):
14 print "REST call " + url
15 resp, content = h.request(url, verb)
18 print "return code %d" % (resp.status)
24 print "list all hosts"
25 put_url = 'http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/active'
26 rest_method(put_url, "GET")
30 # Create two affinity groups
32 print "create web servers group"
33 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/group/webservers'
34 rest_method(put_url, "PUT")
36 print "create external addresses"
37 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/group/clients'
38 rest_method(put_url, "PUT")
40 print "create link inflows"
41 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/link/inflows/from/clients/to/webservers'
42 rest_method(put_url, "PUT")
44 print "add ip to webservers"
45 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/192.168.1.1'
46 rest_method(put_url, "PUT")
48 print "add ip to webservers"
49 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/192.168.1.2'
50 rest_method(put_url, "PUT")
52 print "add ip to external"
53 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.10.0.0'
54 rest_method(put_url, "PUT")
57 def get_all_affinity_groups():
58 print "get all affinity groups"
59 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-groups'
60 rest_method(get_url, "GET")
62 def get_all_affinity_links():
63 print "get all affinity groups"
64 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-links'
65 rest_method(get_url, "GET")
67 def get_affinity_group(groupname):
68 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/' + groupname
69 rest_method(get_url, "GET")
71 def set_waypoint_address():
73 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/setwaypoint/' + wp
74 rest_method(put_url, "PUT")
76 def demo_set_waypoint_address():
78 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/testAL/setwaypoint/' + wp
79 rest_method(put_url, "PUT")
81 # Add waypoint IP to an affinity link.
84 h = httplib2.Http(".cache")
85 h.add_credentials('admin', 'admin')
88 demo_set_waypoint_address()
89 # unset_waypoint_address()
91 # get_affinity_group('webservers')
92 # get_affinity_group('clients')
94 # get_all_affinity_groups()
97 # get_all_affinity_links()
99 if __name__ == "__main__":