blob: aeb2492c273317544ea66efd769d85b76b33b1df [file] [log] [blame]
Carmelo Casconeb34d8e12020-09-28 16:16:59 -07001#! /usr/bin/env python3
Ray Milkey4ff514c2015-09-01 09:02:03 -07002import requests
3
4from requests.auth import HTTPBasicAuth
5import sys
6
7
8
9if len(sys.argv) != 7:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070010 print("usage: create-intent onos-node name ingressDevice ingressPort egressDevice egressPort")
Ray Milkey4ff514c2015-09-01 09:02:03 -070011 sys.exit(1)
12
13node = sys.argv[1]
14name = sys.argv[2]
15ingress = sys.argv[3]
16ingressPort = sys.argv[4]
17egress = sys.argv[5]
18egressPort = sys.argv[6]
19
20intentJsonTemplate = \
21 '{{' + \
22 '"type": "PointToPointIntent",' + \
23 '"appId": "org.onosproject.cli",' + \
24 '"ingressPoint": {{' + \
25 ' "device": "{}",' + \
26 ' "port": "{}"' + \
27 '}},' + \
28 '"egressPoint": {{' + \
29 ' "device": "{}",' + \
30 ' "port": "{}"' + \
31 '}}' + \
32 '}}'
33
34intentJson = intentJsonTemplate.format(ingress, ingressPort, egress, egressPort)
35intentRequest = requests.post('http://' + node + ':8181/onos/v1/intents/',
36 auth=HTTPBasicAuth('onos', 'rocks'),
37 data=intentJson)
38
39if intentRequest.status_code != 201:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070040 print(intentRequest.text)
Ray Milkey4ff514c2015-09-01 09:02:03 -070041 sys.exit(1)
42
43location = intentRequest.headers["location"]
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070044print("@stc " + name + "Location=" + location)
Ray Milkey4ff514c2015-09-01 09:02:03 -070045sys.exit(0)
46
47
48