blob: 3536791cb54376ed4462de775be36f7a8613ca80 [file] [log] [blame]
Andrea Campanella6d774232018-12-21 12:18:21 +01001#! /usr/bin/env python
2
3import requests
4import sys
5import tapiHelper
6
7from requests.auth import HTTPBasicAuth
8
9if len(sys.argv) < 4:
Boyuan Yan528fdba2019-02-15 12:24:43 -080010 print "usage: execute-tapi-post-call <onos-node> <context> <empty> [uuid]."
11 print "\t- If <empty> is \"empty\", it measn that it shoudl be no devices, links or ports\n\t- Uuid is optional and defaults to empty"
Andrea Campanella6d774232018-12-21 12:18:21 +010012 sys.exit(1)
13
14node = sys.argv[1]
15context = sys.argv[2]
16empty = sys.argv[3]
17
18if len(sys.argv) == 4:
19 uuid = ""
20else:
21 uuid = sys.argv[4]
22
23if "get-connectivity-service-list" in context:
24 connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
25 tapi_connection = tapiHelper.get_connection(connectivity_request, uuid)
26 tapi_connection_json = tapi_connection.json()
27 print tapi_connection_json
28 if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty":
29 print "No connection was established"
30 sys.exit(1)
Boyuan Yan528fdba2019-02-15 12:24:43 -080031 if uuid == "":
32 # verify empty connection
33 print tapi_connection_json
34 elif uuid != "":
35 # verify correct connection
36 servs = tapi_connection_json["tapi-connectivity:output"]["service"]
37 for s in range(len(servs)):
38 if servs[s]['uuid'] == uuid:
39 print "Find service with uuid %s" % uuid
40 print servs[s]
41 sys.exit(0)
42 else:
43 print "Invalid input for 3rd and 4th parameters."
44 sys.exit(1)
Andrea Campanella6d774232018-12-21 12:18:21 +010045 sys.exit(0)
46
Boyuan Yan528fdba2019-02-15 12:24:43 -080047# test succeeds by using cmd: python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service empty
Andrea Campanella6d774232018-12-21 12:18:21 +010048if "create-connectivity-service" in context:
49 context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context'
50 connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
51 tapi_connection = tapiHelper.create_connection(context_request, connectivity_request)
52 print context
53 print tapi_connection.json()
54 sys.exit(0)
55
56sys.exit(1)
57
58
59
60