Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | |
| 5 | from requests.auth import HTTPBasicAuth |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | |
| 10 | if len(sys.argv) != 7: |
| 11 | print "usage: create-intent onos-node name ingressDevice ingressPort egressDevice egressPort" |
| 12 | sys.exit(1) |
| 13 | |
| 14 | node = sys.argv[1] |
| 15 | name = sys.argv[2] |
| 16 | ingress = sys.argv[3] |
| 17 | ingressPort = sys.argv[4] |
| 18 | egress = sys.argv[5] |
| 19 | egressPort = sys.argv[6] |
| 20 | |
| 21 | intentJsonTemplate = \ |
| 22 | '{{' + \ |
| 23 | '"type": "PointToPointIntent",' + \ |
| 24 | '"appId": "org.onosproject.cli",' + \ |
| 25 | '"ingressPoint": {{' + \ |
| 26 | ' "device": "{}",' + \ |
| 27 | ' "port": "{}"' + \ |
| 28 | '}},' + \ |
| 29 | '"egressPoint": {{' + \ |
| 30 | ' "device": "{}",' + \ |
| 31 | ' "port": "{}"' + \ |
| 32 | '}}' + \ |
| 33 | '}}' |
| 34 | |
| 35 | intentJson = intentJsonTemplate.format(ingress, ingressPort, egress, egressPort) |
| 36 | intentRequest = requests.post('http://' + node + ':8181/onos/v1/intents/', |
| 37 | auth=HTTPBasicAuth('onos', 'rocks'), |
| 38 | data=intentJson) |
| 39 | |
| 40 | if intentRequest.status_code != 201: |
| 41 | print intentRequest.text |
| 42 | sys.exit(1) |
| 43 | |
| 44 | location = intentRequest.headers["location"] |
| 45 | print "@stc " + name + "Location=" + location |
| 46 | sys.exit(0) |
| 47 | |
| 48 | |
| 49 | |