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