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 get_affinity_link(linkname):
89 get_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + linkname
90 rest_method(get_url, "GET")
92 def set_waypoint_address():
95 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/setwaypoint/' + wp
96 rest_method(put_url, "PUT")
98 def unset_waypoint_address():
100 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/unsetwaypoint'
101 rest_method(put_url, "PUT")
103 def set_deny(setflag='deny'):
105 put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/' + al + '/' + setflag + '/'
106 rest_method(put_url, "PUT")
108 #def enable_waypoint():
109 # put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/enable/'
110 # rest_method(put_url, "PUT")
112 #def disable_waypoint():
113 # put_url = 'http://localhost:8080/affinity/nb/v2/affinity/default/link/inflows/disable/'
114 # rest_method(put_url, "PUT")
116 def enable_affinity():
117 put_url = 'http://localhost:8080/affinity/nb/v2/flatl2/default/enableaffinity/'
118 rest_method(put_url, "PUT")
120 def disable_affinity():
121 put_url = 'http://localhost:8080/affinity/nb/v2/flatl2/default/disableaffinity/'
122 rest_method(put_url, "PUT")
124 # Add waypoint IP to an affinity link.
130 get_affinity_group('webservers')
131 get_affinity_group('clients')
132 get_affinity_link('inflows')
134 get_all_affinity_groups()
137 # Set affinity attributes and make sure they are associated with the affinity link.
138 set_waypoint_address()
141 get_affinity_link('inflows')
149 #if __name__ == "__main__":
152 h = httplib2.Http(".cache")
153 h.add_credentials('admin', 'admin')