Andrea Campanella | 6d77423 | 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: |
Boyuan Yan | 528fdba | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 10 | print "usage: execute-tapi-post-call <onos-node> <context> <empty> [uuid]." |
| 11 | print "\t- If <empty> is \"empty\", it measn that it shoudl be no devices, links or ports\n\t- Uuid is optional and defaults to empty" |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 12 | sys.exit(1) |
| 13 | |
| 14 | node = sys.argv[1] |
| 15 | context = sys.argv[2] |
| 16 | empty = sys.argv[3] |
| 17 | |
| 18 | if len(sys.argv) == 4: |
| 19 | uuid = "" |
| 20 | else: |
| 21 | uuid = sys.argv[4] |
| 22 | |
| 23 | if "get-connectivity-service-list" in context: |
| 24 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 25 | tapi_connection = tapiHelper.get_connection(connectivity_request, uuid) |
| 26 | tapi_connection_json = tapi_connection.json() |
| 27 | print tapi_connection_json |
| 28 | if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty": |
| 29 | print "No connection was established" |
| 30 | sys.exit(1) |
Boyuan Yan | 528fdba | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 31 | if uuid == "": |
| 32 | # verify empty connection |
| 33 | print tapi_connection_json |
| 34 | elif uuid != "": |
| 35 | # verify correct connection |
| 36 | servs = tapi_connection_json["tapi-connectivity:output"]["service"] |
| 37 | for s in range(len(servs)): |
| 38 | if servs[s]['uuid'] == uuid: |
| 39 | print "Find service with uuid %s" % uuid |
| 40 | print servs[s] |
| 41 | sys.exit(0) |
| 42 | else: |
| 43 | print "Invalid input for 3rd and 4th parameters." |
| 44 | sys.exit(1) |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 45 | sys.exit(0) |
| 46 | |
Boyuan Yan | 528fdba | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 47 | # test succeeds by using cmd: python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service empty |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 48 | if "create-connectivity-service" in context: |
| 49 | context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 50 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 51 | tapi_connection = tapiHelper.create_connection(context_request, connectivity_request) |
| 52 | print context |
| 53 | print tapi_connection.json() |
| 54 | sys.exit(0) |
| 55 | |
| 56 | sys.exit(1) |
| 57 | |
| 58 | |
| 59 | |
| 60 | |