blob: 59f535ff00e24e2d240894e81d465f080f6da5f8 [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 Yan6b5d4fd2019-02-25 12:16:09 -08009 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 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"
33 sys.exit(1)
Boyuan Yan528fdba2019-02-15 12:24:43 -080034 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 Campanella6d774232018-12-21 12:18:21 +010048 sys.exit(0)
49
Boyuan Yan41036782019-02-24 16:28:01 -080050# 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 Campanella6d774232018-12-21 12:18:21 +010053if "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 Yan41036782019-02-24 16:28:01 -080056 if empty == "line-side":
57 tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request)
58 elif empty == "client-side":
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -080059 tapi_connection = tapiHelper.create_client_connection(context_request, connectivity_request)
Boyuan Yan41036782019-02-24 16:28:01 -080060 else:
61 raise NotImplementedError("Not Implementation for option %s." % empty)
Boyuan Yan6b5d4fd2019-02-25 12:16:09 -080062 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 Campanella6d774232018-12-21 12:18:21 +010064 sys.exit(0)
65
66sys.exit(1)