blob: 928531fd1ac8db7d41efb606204d794bd355f889 [file] [log] [blame]
Ray Milkeye0827772015-09-11 16:49:21 -07001#! /usr/bin/env python
2
3import requests
4import sys
5
6from requests.auth import HTTPBasicAuth
7
8if len(sys.argv) != 9:
9 print "usage: find-link-in-cluster onos-node name cluster-id expected-length src-device-id src-port dst-device-id dst-port"
10 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:
27 print linksRequest.text
28 sys.exit(1)
29
30linksJson = linksRequest.json()
31linksLength = len(linksJson["links"])
32
33if linksLength != length:
34 print "Expected length {} but got {}".format(length, linksLength)
35 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"]:
40 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"]
46 sys.exit(0)
47
48print "Could not find link from {}:{} to {}:{}"\
49 .format(srcDeviceId, srcPort, dstDeviceId, dstPort)
50sys.exit(1)
51
52
53
54