Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 3 | import sys |
| 4 | import tapiHelper |
Boyuan Yan | 6b5d4fd | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 5 | import json |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 6 | |
| 7 | if len(sys.argv) < 4: |
Boyuan Yan | 528fdba | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 8 | print "usage: execute-tapi-post-call <onos-node> <context> <empty> [uuid]." |
Boyuan Yan | 6b5d4fd | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 9 | print "\t- If <empty> is \"empty\", it measn that it shoudl be no devices, links or ports" |
| 10 | print "\t- Uuid is optional and defaults to empty" |
| 11 | print "\t- For example:\n\t\t- line-side connectivity creation: %s\n\t\t- client-side connectivity creation: %s" % \ |
| 12 | ("python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service line-side", |
| 13 | "python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service client-side") |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 14 | sys.exit(1) |
| 15 | |
| 16 | node = sys.argv[1] |
| 17 | context = sys.argv[2] |
| 18 | empty = sys.argv[3] |
| 19 | |
| 20 | if len(sys.argv) == 4: |
| 21 | uuid = "" |
| 22 | else: |
| 23 | uuid = sys.argv[4] |
Boyuan Yan | 4103678 | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 24 | # request example: |
| 25 | # python execute-tapi-post-call.py localhost tapi-common:get-service-interface-point-list empty |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 26 | if "get-connectivity-service-list" in context: |
| 27 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
| 28 | tapi_connection = tapiHelper.get_connection(connectivity_request, uuid) |
| 29 | tapi_connection_json = tapi_connection.json() |
| 30 | print tapi_connection_json |
| 31 | if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty": |
| 32 | print "No connection was established" |
| 33 | sys.exit(1) |
Boyuan Yan | 528fdba | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 34 | if uuid == "": |
| 35 | # verify empty connection |
| 36 | print tapi_connection_json |
| 37 | elif uuid != "": |
| 38 | # verify correct connection |
| 39 | servs = tapi_connection_json["tapi-connectivity:output"]["service"] |
| 40 | for s in range(len(servs)): |
| 41 | if servs[s]['uuid'] == uuid: |
| 42 | print "Find service with uuid %s" % uuid |
| 43 | print servs[s] |
| 44 | sys.exit(0) |
| 45 | else: |
| 46 | print "Invalid input for 3rd and 4th parameters." |
| 47 | sys.exit(1) |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 48 | sys.exit(0) |
| 49 | |
Boyuan Yan | 4103678 | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 50 | # test succeeds by using cmd: |
| 51 | # python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service line-side |
| 52 | # python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service client-side |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 53 | if "create-connectivity-service" in context: |
| 54 | context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 55 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
Boyuan Yan | 4103678 | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 56 | if empty == "line-side": |
| 57 | tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request) |
| 58 | elif empty == "client-side": |
Boyuan Yan | 6b5d4fd | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 59 | tapi_connection = tapiHelper.create_client_connection(context_request, connectivity_request) |
Boyuan Yan | 4103678 | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 60 | else: |
| 61 | raise NotImplementedError("Not Implementation for option %s." % empty) |
Boyuan Yan | 6b5d4fd | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 62 | print "\nThe request context is:\t%s." % context |
| 63 | print "\nThe return message of the request is:\n\t\t%s " % json.dumps(tapi_connection.json()) |
Andrea Campanella | 6d77423 | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 64 | sys.exit(0) |
| 65 | |
| 66 | sys.exit(1) |