blob: f6d419a969d7fd2ec46ca74e447eb211f36bac8b [file] [log] [blame]
Andrea Campanella6d774232018-12-21 12:18:21 +01001#! /usr/bin/env python
2
Andrea Campanella6d774232018-12-21 12:18:21 +01003import sys
4import tapiHelper
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -08005import json
Andrea Campanella6d774232018-12-21 12:18:21 +01006
7if len(sys.argv) < 4:
Boyuan Yan528fdba2019-02-15 12:24:43 -08008 print "usage: execute-tapi-post-call <onos-node> <context> <empty> [uuid]."
Boyuan Yan1c27bc72019-02-15 19:22:19 +00009 print "\t- If <empty> is \"empty\", it measn that it should be no devices, links or ports"
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -080010 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 Campanella6d774232018-12-21 12:18:21 +010014 sys.exit(1)
15
16node = sys.argv[1]
17context = sys.argv[2]
18empty = sys.argv[3]
19
20if len(sys.argv) == 4:
21 uuid = ""
22else:
23 uuid = sys.argv[4]
Boyuan Yan41036782019-02-24 16:28:01 -080024# request example:
25# python execute-tapi-post-call.py localhost tapi-common:get-service-interface-point-list empty
Andrea Campanella6d774232018-12-21 12:18:21 +010026if "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 Yan1c27bc72019-02-15 19:22:19 +000033 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 Yan528fdba2019-02-15 12:24:43 -080040 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 Campanella6d774232018-12-21 12:18:21 +010054 sys.exit(0)
55
Boyuan Yan41036782019-02-24 16:28:01 -080056# 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 Campanella6d774232018-12-21 12:18:21 +010059if "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 Yan41036782019-02-24 16:28:01 -080062 if empty == "line-side":
63 tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request)
64 elif empty == "client-side":
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -080065 tapi_connection = tapiHelper.create_client_connection(context_request, connectivity_request)
Boyuan Yan41036782019-02-24 16:28:01 -080066 else:
67 raise NotImplementedError("Not Implementation for option %s." % empty)
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -080068 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 Campanella6d774232018-12-21 12:18:21 +010070 sys.exit(0)
71
72sys.exit(1)