Ray Milkey | 4ff514c | 2015-09-01 09:02:03 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | import sys |
| 5 | |
| 6 | from requests.auth import HTTPBasicAuth |
| 7 | |
| 8 | if 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 | |
| 12 | node = sys.argv[1] |
| 13 | name = sys.argv[2] |
| 14 | srcDeviceId = sys.argv[3] |
| 15 | srcPort = sys.argv[4] |
| 16 | dstDeviceId = sys.argv[5] |
| 17 | dstPort = sys.argv[6] |
| 18 | |
| 19 | |
| 20 | linksRequest = requests.get('http://' + node + ':8181/onos/v1/links?device=' + |
| 21 | srcDeviceId + '&port=' + srcPort, |
| 22 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 23 | |
| 24 | if linksRequest.status_code != 200: |
| 25 | print linksRequest.text |
| 26 | sys.exit(1) |
| 27 | |
| 28 | linksJson = linksRequest.json() |
| 29 | |
| 30 | for 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 | |
| 41 | sys.exit(1) |
| 42 | |
| 43 | |
| 44 | |
| 45 | |