Ray Milkey | e082777 | 2015-09-11 16:49:21 -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) != 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 | |
| 12 | node = sys.argv[1] |
| 13 | name = sys.argv[2] |
| 14 | cluster = sys.argv[3] |
| 15 | length = int(sys.argv[4]) |
| 16 | srcDeviceId = sys.argv[5] |
| 17 | srcPort = sys.argv[6] |
| 18 | dstDeviceId = sys.argv[7] |
| 19 | dstPort = sys.argv[8] |
| 20 | |
| 21 | |
| 22 | linksRequest = requests.get('http://' + node + ':8181/onos/v1/topology/clusters/' |
| 23 | + cluster + '/links', |
| 24 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 25 | |
| 26 | if linksRequest.status_code != 200: |
| 27 | print linksRequest.text |
| 28 | sys.exit(1) |
| 29 | |
| 30 | linksJson = linksRequest.json() |
| 31 | linksLength = len(linksJson["links"]) |
| 32 | |
| 33 | if linksLength != length: |
| 34 | print "Expected length {} but got {}".format(length, linksLength) |
| 35 | sys.exit(1) |
| 36 | |
| 37 | for 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 | |
| 48 | print "Could not find link from {}:{} to {}:{}"\ |
| 49 | .format(srcDeviceId, srcPort, dstDeviceId, dstPort) |
| 50 | sys.exit(1) |
| 51 | |
| 52 | |
| 53 | |
| 54 | |