4 from requests.auth import HTTPBasicAuth
5 from subprocess import call
18 OPER_NODES='/restconf/operational/opendaylight-inventory:nodes/'
19 CONF_TENANT='/restconf/config/policy:tenants'
21 def get(host, port, uri):
22 url='http://'+host+":"+port+uri
24 r = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD))
25 jsondata=json.loads(r.text)
28 def put(host, port, uri, data, debug=False):
29 '''Perform a PUT rest operation, using the URL and data provided'''
31 url='http://'+host+":"+port+uri
33 headers = {'Content-type': 'application/yang.data+json',
34 'Accept': 'application/yang.data+json'}
37 print json.dumps(data, indent=4, sort_keys=True)
38 r = requests.put(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
43 def post(host, port, uri, data, debug=False):
44 '''Perform a POST rest operation, using the URL and data provided'''
46 url='http://'+host+":"+port+uri
47 headers = {'Content-type': 'application/yang.data+json',
48 'Accept': 'application/yang.data+json'}
51 print json.dumps(data, indent=4, sort_keys=True)
52 r = requests.post(url, data=json.dumps(data), headers=headers, auth=HTTPBasicAuth(USERNAME, PASSWORD))
58 def get_tenant_data():
65 "name": "allow-http-clause",
72 "id": "icmp-http-contract",
75 "name": "allow-http-subject",
82 "instance-name" : "http-dest",
87 "instance-name" : "http-src"
97 "name": "allow-http-rule"
102 "name": "allow-icmp-subject",
108 "instance-name" : "icmp"
118 "name": "allow-icmp-rule"
127 "consumer-named-selector": [
132 "name": "webservers-clients-icmp-http-contract"
136 "provider-named-selector": []
139 "consumer-named-selector": [],
141 "provider-named-selector": [
146 "name": "webservers-clients-icmp-http-contract"
151 "id": "tenant-dobre",
152 "l2-bridge-domain": [
154 "id": "bridge-domain1",
155 "parent": "l3-context-vrf-red"
160 "id": "flood-domain-1",
161 "parent": "bridge-domain1"
164 "id": "flood-domain1",
165 "parent": "bridge-domain1"
170 "id": "l3-context-vrf-red"
174 "subject-feature-instances": {
175 "classifier-instance": [
177 "classifier-definition-id": "Classifier-L4",
191 "classifier-definition-id": "Classifier-L4",
205 "classifier-definition-id": "Classifier-IP-Protocol",
218 "action-definition-id": "Action-Allow"
224 "id": "subnet-10.0.35.0/24",
225 "ip-prefix": "10.0.35.1/24",
226 "parent": "flood-domain-1",
227 "virtual-router-ip": "10.0.35.1"
230 "id": "subnet-10.0.36.0/24",
231 "ip-prefix": "10.0.36.1/24",
232 "parent": "flood-domain1",
233 "virtual-router-ip": "10.0.36.1"
239 # Main definition - constants
241 # =======================
243 # =======================
247 # =======================
249 # =======================
253 def get_tenant_uri():
254 return "/restconf/config/policy:tenants/policy:tenant/tenant-dobre"
256 def get_tunnel_data():
258 "opendaylight-inventory:nodes": {
262 "ofoverlay:tunnel": [
264 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
265 "node-connector-id": "openflow:1:1",
266 "ip": "192.168.50.70",
270 "tunnel-type": "overlay:tunnel-type-vxlan",
271 "node-connector-id": "openflow:1:2",
272 "ip": "192.168.50.70",
279 "ofoverlay:tunnel": [
281 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
282 "node-connector-id": "openflow:2:1",
283 "ip": "192.168.50.71",
287 "tunnel-type": "overlay:tunnel-type-vxlan",
288 "node-connector-id": "openflow:2:2",
289 "ip": "192.168.50.71",
296 "ofoverlay:tunnel": [
298 "tunnel-type": "overlay:tunnel-type-vxlan-gpe",
299 "node-connector-id": "openflow:3:1",
300 "ip": "192.168.50.72",
304 "tunnel-type": "overlay:tunnel-type-vxlan",
305 "node-connector-id": "openflow:3:2",
306 "ip": "192.168.50.72",
316 def get_tunnel_uri():
317 return "/restconf/config/opendaylight-inventory:nodes"
319 def get_endpoint_data():
323 "endpoint-group": "clients",
325 "network-containment" : "subnet-10.0.35.0/24",
327 "l2-context": "bridge-domain1",
328 "mac-address": "00:00:00:00:35:02",
332 "ip-address": "10.0.35.2",
333 "l3-context": "l3-context-vrf-red"
336 "port-name": "vethl-h35_2",
337 "tenant": "tenant-dobre"
343 "endpoint-group": "clients",
345 "network-containment" : "subnet-10.0.35.0/24",
347 "l2-context": "bridge-domain1",
348 "mac-address": "00:00:00:00:35:03",
352 "ip-address": "10.0.35.3",
353 "l3-context": "l3-context-vrf-red"
356 "port-name": "vethl-h35_3",
357 "tenant": "tenant-dobre"
363 "endpoint-group": "clients",
365 "network-containment" : "subnet-10.0.35.0/24",
367 "l2-context": "bridge-domain1",
368 "mac-address": "00:00:00:00:35:04",
372 "ip-address": "10.0.35.4",
373 "l3-context": "l3-context-vrf-red"
376 "port-name": "vethl-h35_4",
377 "tenant": "tenant-dobre"
383 "endpoint-group": "clients",
385 "network-containment" : "subnet-10.0.35.0/24",
387 "l2-context": "bridge-domain1",
388 "mac-address": "00:00:00:00:35:05",
392 "ip-address": "10.0.35.5",
393 "l3-context": "l3-context-vrf-red"
396 "port-name": "vethl-h35_5",
397 "tenant": "tenant-dobre"
403 "endpoint-group": "webservers",
405 "network-containment" : "subnet-10.0.36.0/24",
407 "l2-context": "bridge-domain1",
408 "mac-address": "00:00:00:00:36:02",
412 "ip-address": "10.0.36.2",
413 "l3-context": "l3-context-vrf-red"
416 "port-name": "vethl-h36_2",
417 "tenant": "tenant-dobre"
423 "endpoint-group": "webservers",
425 "network-containment" : "subnet-10.0.36.0/24",
427 "l2-context": "bridge-domain1",
428 "mac-address": "00:00:00:00:36:03",
432 "ip-address": "10.0.36.3",
433 "l3-context": "l3-context-vrf-red"
436 "port-name": "vethl-h36_3",
437 "tenant": "tenant-dobre"
443 "endpoint-group": "webservers",
445 "network-containment" : "subnet-10.0.36.0/24",
447 "l2-context": "bridge-domain1",
448 "mac-address": "00:00:00:00:36:04",
452 "ip-address": "10.0.36.4",
453 "l3-context": "l3-context-vrf-red"
456 "port-name": "vethl-h36_4",
457 "tenant": "tenant-dobre"
462 "endpoint-group": "webservers",
464 "network-containment" : "subnet-10.0.36.0/24",
466 "l2-context": "bridge-domain1",
467 "mac-address": "00:00:00:00:36:05",
471 "ip-address": "10.0.36.5",
472 "l3-context": "l3-context-vrf-red"
475 "port-name": "vethl-h36_5",
476 "tenant": "tenant-dobre"
480 def get_endpoint_uri():
481 return "/restconf/operations/endpoint:register-endpoint"
483 if __name__ == "__main__":
487 # Some sensible defaults
488 controller=os.environ.get('ODL')
489 if controller == None:
490 sys.exit("No controller set.")
494 tenants=get(controller,DEFAULT_PORT,CONF_TENANT)
497 print "sending tenant"
498 put(controller, DEFAULT_PORT, get_tenant_uri(), get_tenant_data(),True)
499 print "sending tunnel"
500 put(controller, DEFAULT_PORT, get_tunnel_uri(), get_tunnel_data(), True)
501 print "registering endpoints"
502 for endpoint in get_endpoint_data():
503 post(controller, DEFAULT_PORT, get_endpoint_uri(),endpoint,True)