Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | import sys |
| 5 | import tapiHelper |
| 6 | |
| 7 | from requests.auth import HTTPBasicAuth |
| 8 | |
| 9 | if len(sys.argv) < 4: |
| 10 | print "usage: execute-tapi-post-call onos-node context empty uuid. Uuid is optional and defaults to empty" |
| 11 | sys.exit(1) |
| 12 | |
| 13 | node = sys.argv[1] |
| 14 | context = sys.argv[2] |
| 15 | empty = sys.argv[3] |
| 16 | |
| 17 | if len(sys.argv) == 4: |
| 18 | uuid = "" |
| 19 | else: |
| 20 | uuid = sys.argv[4] |
| 21 | |
| 22 | if "get-connectivity-service-list" in context: |
| 23 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 24 | tapi_connection = tapiHelper.get_connection(connectivity_request, uuid) |
| 25 | tapi_connection_json = tapi_connection.json() |
| 26 | print tapi_connection_json |
| 27 | if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty": |
| 28 | print "No connection was established" |
| 29 | sys.exit(1) |
| 30 | #TODO verify empty connection if uuid is empty |
| 31 | #TODO verify correct connection if uuid is not empty |
| 32 | sys.exit(0) |
| 33 | |
| 34 | if "create-connectivity-service" in context: |
| 35 | context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 36 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 37 | tapi_connection = tapiHelper.create_connection(context_request, connectivity_request) |
| 38 | print context |
| 39 | print tapi_connection.json() |
| 40 | sys.exit(0) |
| 41 | |
| 42 | sys.exit(1) |
| 43 | |
| 44 | |
| 45 | |
| 46 | |