Carmelo Cascone | b34d8e1 | 2020-09-28 16:16:59 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env python3 |
Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 2 | import requests |
| 3 | |
| 4 | from requests.auth import HTTPBasicAuth |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | |
| 9 | if len(sys.argv) != 7: |
Carmelo Cascone | b34d8e1 | 2020-09-28 16:16:59 -0700 | [diff] [blame^] | 10 | print("usage: create-intent onos-node name ingressDevice ingressPort egressDevice egressPort") |
Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 11 | sys.exit(1) |
| 12 | |
| 13 | node = sys.argv[1] |
| 14 | name = sys.argv[2] |
| 15 | ingress = sys.argv[3] |
| 16 | ingressPort = sys.argv[4] |
| 17 | egress = sys.argv[5] |
| 18 | egressPort = sys.argv[6] |
| 19 | |
| 20 | intentJsonTemplate = \ |
| 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 | |
| 34 | intentJson = intentJsonTemplate.format(ingress, ingressPort, egress, egressPort) |
| 35 | intentRequest = requests.post('http://' + node + ':8181/onos/v1/intents/', |
| 36 | auth=HTTPBasicAuth('onos', 'rocks'), |
| 37 | data=intentJson) |
| 38 | |
| 39 | if intentRequest.status_code != 201: |
Carmelo Cascone | b34d8e1 | 2020-09-28 16:16:59 -0700 | [diff] [blame^] | 40 | print(intentRequest.text) |
Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 41 | sys.exit(1) |
| 42 | |
| 43 | location = intentRequest.headers["location"] |
Carmelo Cascone | b34d8e1 | 2020-09-28 16:16:59 -0700 | [diff] [blame^] | 44 | print("@stc " + name + "Location=" + location) |
Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 45 | sys.exit(0) |
| 46 | |
| 47 | |
| 48 | |