blob: 9ac6e358dd3db868463b8dc5cd12db58f5ab6e6f [file] [log] [blame]
Ray Milkey4ff514c2015-09-01 09:02:03 -07001#! /usr/bin/env python
2
3import requests
4import sys
5
6from requests.auth import HTTPBasicAuth
7
8if len(sys.argv) != 7:
9 print "usage: find-link onos-node name src-device-id src-port dst-device-id dst-port"
10 sys.exit(1)
11
12node = sys.argv[1]
13name = sys.argv[2]
14srcDeviceId = sys.argv[3]
15srcPort = sys.argv[4]
16dstDeviceId = sys.argv[5]
17dstPort = sys.argv[6]
18
19
20linksRequest = requests.get('http://' + node + ':8181/onos/v1/links?device=' +
21 srcDeviceId + '&port=' + srcPort,
22 auth=HTTPBasicAuth('onos', 'rocks'))
23
24if linksRequest.status_code != 200:
25 print linksRequest.text
26 sys.exit(1)
27
28linksJson = linksRequest.json()
29
30for link in linksJson["links"]:
31 if srcDeviceId == link["src"]["device"]:
32 if dstDeviceId == link["dst"]["device"]:
33 print "@stc " + name + "SrcDevice=" + link["src"]["device"]
34 print "@stc " + name + "SrcPort=" + link["src"]["port"]
35 print "@stc " + name + "DstDevice=" + link["dst"]["device"]
36 print "@stc " + name + "DstPort=" + link["dst"]["port"]
37 print "@stc " + name + "Type=" + link["type"]
38 print "@stc " + name + "State=" + link["state"]
39 sys.exit(0)
40
41sys.exit(1)
42
43
44
45