Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 3 | import sys |
| 4 | import tapiHelper |
Boyuan Yan | f7f5054 | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 5 | import json |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 6 | |
| 7 | if len(sys.argv) < 4: |
Boyuan Yan | 863db91 | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 8 | print "usage: execute-tapi-post-call <onos-node> <context> <empty> [uuid]." |
Boyuan Yan | ed2ea357 | 2019-04-02 15:38:42 -0700 | [diff] [blame] | 9 | print "\t- If <empty> is \"empty\", it measn that it should be no devices, links or ports" |
Boyuan Yan | f7f5054 | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 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 | 50c0c4c | 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 | 2313d7d | 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 | 50c0c4c | 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" |
Boyuan Yan | ed2ea357 | 2019-04-02 15:38:42 -0700 | [diff] [blame] | 33 | sys.exit(0) |
| 34 | if empty == "empty": |
| 35 | if not tapi_connection_json["tapi-connectivity:output"]: |
| 36 | sys.exit(0) |
| 37 | else: |
| 38 | print "There exist some connectivities!!!" |
| 39 | sys.exit(1) |
Boyuan Yan | 863db91 | 2019-02-15 12:24:43 -0800 | [diff] [blame] | 40 | if uuid == "": |
| 41 | # verify empty connection |
| 42 | print tapi_connection_json |
| 43 | elif uuid != "": |
| 44 | # verify correct connection |
| 45 | servs = tapi_connection_json["tapi-connectivity:output"]["service"] |
| 46 | for s in range(len(servs)): |
| 47 | if servs[s]['uuid'] == uuid: |
| 48 | print "Find service with uuid %s" % uuid |
| 49 | print servs[s] |
| 50 | sys.exit(0) |
| 51 | else: |
| 52 | print "Invalid input for 3rd and 4th parameters." |
| 53 | sys.exit(1) |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 54 | sys.exit(0) |
| 55 | |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 56 | # test succeeds by using cmd: |
| 57 | # python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service line-side |
| 58 | # 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] | 59 | if "create-connectivity-service" in context: |
| 60 | context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context' |
| 61 | connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 62 | if empty == "line-side": |
| 63 | tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request) |
| 64 | elif empty == "client-side": |
Boyuan Yan | f7f5054 | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 65 | tapi_connection = tapiHelper.create_client_connection(context_request, connectivity_request) |
Boyuan Yan | 2313d7d | 2019-02-24 16:28:01 -0800 | [diff] [blame] | 66 | else: |
| 67 | raise NotImplementedError("Not Implementation for option %s." % empty) |
Boyuan Yan | f7f5054 | 2019-02-25 12:16:09 -0800 | [diff] [blame] | 68 | print "\nThe request context is:\t%s." % context |
| 69 | print "\nThe return message of the request is:\n\t\t%s " % json.dumps(tapi_connection.json()) |
Andrea Campanella | 50c0c4c | 2018-12-21 12:18:21 +0100 | [diff] [blame] | 70 | sys.exit(0) |
| 71 | |
| 72 | sys.exit(1) |