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: |
Boyuan Yan | 863db91 | 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 | 50c0c4c | 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] |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame^] | 22 | # request example: |
| 23 | # python execute-tapi-post-call.py localhost tapi-common:get-service-interface-point-list empty |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 24 | if "get-connectivity-service-list" in context: |
| 25 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 26 | tapi_connection = tapiHelper.get_connection(connectivity_request, uuid) |
| 27 | tapi_connection_json = tapi_connection.json() |
| 28 | print tapi_connection_json |
| 29 | if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty": |
| 30 | print "No connection was established" |
| 31 | sys.exit(1) |
Boyuan Yan | 863db91 | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 32 | if uuid == "": |
| 33 | # verify empty connection |
| 34 | print tapi_connection_json |
| 35 | elif uuid != "": |
| 36 | # verify correct connection |
| 37 | servs = tapi_connection_json["tapi-connectivity:output"]["service"] |
| 38 | for s in range(len(servs)): |
| 39 | if servs[s]['uuid'] == uuid: |
| 40 | print "Find service with uuid %s" % uuid |
| 41 | print servs[s] |
| 42 | sys.exit(0) |
| 43 | else: |
| 44 | print "Invalid input for 3rd and 4th parameters." |
| 45 | sys.exit(1) |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 46 | sys.exit(0) |
| 47 | |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame^] | 48 | # test succeeds by using cmd: |
| 49 | # python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service line-side |
| 50 | # python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service client-side |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 51 | if "create-connectivity-service" in context: |
| 52 | context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 53 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame^] | 54 | if empty == "line-side": |
| 55 | tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request) |
| 56 | elif empty == "client-side": |
| 57 | tapi_connection = tapiHelper.create_connection(context_request, connectivity_request) |
| 58 | else: |
| 59 | raise NotImplementedError("Not Implementation for option %s." % empty) |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 60 | print context |
| 61 | print tapi_connection.json() |
| 62 | sys.exit(0) |
| 63 | |
| 64 | sys.exit(1) |
| 65 | |
| 66 | |
| 67 | |
| 68 | |