blob: 1eb68320b3a495c634361a96debe1706a9c45942 [file] [log] [blame]
Carmelo Casconeb34d8e12020-09-28 16:16:59 -07001#! /usr/bin/env python3
Ray Milkeye0827772015-09-11 16:49:21 -07002
3import requests
4import sys
5
6from requests.auth import HTTPBasicAuth
7
8if len(sys.argv) != 9:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -07009 print("usage: find-link-in-cluster onos-node name cluster-id expected-length src-device-id src-port dst-device-id dst-port")
Ray Milkeye0827772015-09-11 16:49:21 -070010 sys.exit(1)
11
12node = sys.argv[1]
13name = sys.argv[2]
14cluster = sys.argv[3]
15length = int(sys.argv[4])
16srcDeviceId = sys.argv[5]
17srcPort = sys.argv[6]
18dstDeviceId = sys.argv[7]
19dstPort = sys.argv[8]
20
21
22linksRequest = requests.get('http://' + node + ':8181/onos/v1/topology/clusters/'
23 + cluster + '/links',
24 auth=HTTPBasicAuth('onos', 'rocks'))
25
26if linksRequest.status_code != 200:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070027 print(linksRequest.text)
Ray Milkeye0827772015-09-11 16:49:21 -070028 sys.exit(1)
29
30linksJson = linksRequest.json()
31linksLength = len(linksJson["links"])
32
33if linksLength != length:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070034 print("Expected length {} but got {}".format(length, linksLength))
Ray Milkeye0827772015-09-11 16:49:21 -070035 sys.exit(1)
36
37for link in linksJson["links"]:
38 if srcDeviceId == link["src"]["device"] and srcPort == link["src"]["port"]:
39 if dstDeviceId == link["dst"]["device"] and dstPort == link["dst"]["port"]:
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070040 print("@stc " + name + "SrcDevice=" + link["src"]["device"])
41 print("@stc " + name + "SrcPort=" + link["src"]["port"])
42 print("@stc " + name + "DstDevice=" + link["dst"]["device"])
43 print("@stc " + name + "DstPort=" + link["dst"]["port"])
44 print("@stc " + name + "Type=" + link["type"])
45 print("@stc " + name + "State=" + link["state"])
Ray Milkeye0827772015-09-11 16:49:21 -070046 sys.exit(0)
47
Carmelo Casconeb34d8e12020-09-28 16:16:59 -070048print("Could not find link from {}:{} to {}:{}"\
49 .format(srcDeviceId, srcPort, dstDeviceId, dstPort))
Ray Milkeye0827772015-09-11 16:49:21 -070050sys.exit(1)
51
52
53
54