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)
25 print "list active hosts"
26 put_url = 'http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/active'
27 content = rest_method(put_url, "GET")
28 hostCfg = json.loads(content)
29 for host in hostCfg['hostConfig']:
32 print "list inactive hosts"
33 put_url = 'http://localhost:8080/controller/nb/v2/hosttracker/default/hosts/inactive'
34 rest_method(put_url, "GET")
35 content = rest_method(put_url, "GET")
36 hostCfg = json.loads(content)
37 for host in hostCfg['hostConfig']:
42 # Create two affinity groups
44 print "create web servers group"
45 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/group/webservers'
46 rest_method(put_url, "PUT")
48 print "create external addresses"
49 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/group/clients'
50 rest_method(put_url, "PUT")
52 print "create link inflows"
53 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/create/link/inflows/from/clients/to/webservers'
54 rest_method(put_url, "PUT")
56 # print "add ip to webservers"
57 # put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.1'
58 # rest_method(put_url, "PUT")
60 print "add subnet to webservers"
61 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/addsubnet/ipprefix/10.0.0.1/mask/31'
62 rest_method(put_url, "PUT")
64 # print "add ip to webservers"
65 # put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/webservers/add/ip/10.0.0.2'
66 # rest_method(put_url, "PUT")
68 print "add ip to external"
69 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/clients/add/ip/10.0.0.3'
70 rest_method(put_url, "PUT")
73 def get_all_affinity_groups():
74 print "get all affinity groups"
75 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-groups'
76 rest_method(get_url, "GET")
79 def get_all_affinity_links():
80 print "get all affinity groups"
81 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/affinity-links'
82 rest_method(get_url, "GET")
84 def get_affinity_group(groupname):
85 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/group/' + groupname
86 rest_method(get_url, "GET")
88 def set_waypoint_address():
90 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/setwaypoint/' + wp
91 rest_method(put_url, "PUT")
93 def enable_waypoint():
94 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/enable/'
95 rest_method(put_url, "PUT")
97 def disable_waypoint():
98 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/disable/'
99 rest_method(put_url, "PUT")
101 # Add waypoint IP to an affinity link.
107 get_affinity_group('webservers')
108 get_affinity_group('clients')
110 get_all_affinity_groups()
113 set_waypoint_address()
117 #if __name__ == "__main__":
120 h = httplib2.Http(".cache")
121 h.add_credentials('admin', 'admin')