blob: 512049e33b3cc0a863a568f9c680027e95570ff0 [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]
Boyuan Yan41036782019-02-24 16:28:01 -080022# request example:
23# python execute-tapi-post-call.py localhost tapi-common:get-service-interface-point-list empty
Andrea Campanella6d774232018-12-21 12:18:21 +010024if "get-connectivity-service-list" in context:
25 connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
26 tapi_connection = tapiHelper.get_connection(connectivity_request, uuid)
27 tapi_connection_json = tapi_connection.json()
28 print tapi_connection_json
29 if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty":
30 print "No connection was established"
31 sys.exit(1)
Boyuan Yan528fdba2019-02-15 12:24:43 -080032 if uuid == "":
33 # verify empty connection
34 print tapi_connection_json
35 elif uuid != "":
36 # verify correct connection
37 servs = tapi_connection_json["tapi-connectivity:output"]["service"]
38 for s in range(len(servs)):
39 if servs[s]['uuid'] == uuid:
40 print "Find service with uuid %s" % uuid
41 print servs[s]
42 sys.exit(0)
43 else:
44 print "Invalid input for 3rd and 4th parameters."
45 sys.exit(1)
Andrea Campanella6d774232018-12-21 12:18:21 +010046 sys.exit(0)
47
Boyuan Yan41036782019-02-24 16:28:01 -080048# test succeeds by using cmd:
49# python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service line-side
50# python execute-tapi-post-call.py 127.0.0.1 tapi-connectivity:create-connectivity-service client-side
Andrea Campanella6d774232018-12-21 12:18:21 +010051if "create-connectivity-service" in context:
52 context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context'
53 connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
Boyuan Yan41036782019-02-24 16:28:01 -080054 if empty == "line-side":
55 tapi_connection = tapiHelper.create_line_connection(context_request, connectivity_request)
56 elif empty == "client-side":
57 tapi_connection = tapiHelper.create_connection(context_request, connectivity_request)
58 else:
59 raise NotImplementedError("Not Implementation for option %s." % empty)
Andrea Campanella6d774232018-12-21 12:18:21 +010060 print context
61 print tapi_connection.json()
62 sys.exit(0)
63
64sys.exit(1)
65
66
67
68