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 | import urllib |
| 6 | |
| 7 | from requests.auth import HTTPBasicAuth |
| 8 | |
| 9 | if len(sys.argv) != 5: |
| 10 | print "usage: verify-topo-links onos-node cluster-id first-index last-index" |
| 11 | sys.exit(1) |
| 12 | |
| 13 | node = sys.argv[1] |
| 14 | cluster = sys.argv[2] |
| 15 | first = int(sys.argv[3]) |
| 16 | last = int(sys.argv[4]) |
| 17 | |
| 18 | found = 0 |
| 19 | |
| 20 | topoRequest = requests.get('http://' + node + ':8181/onos/v1/topology/clusters/' |
| 21 | + cluster |
| 22 | + "/devices", |
| 23 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 24 | |
| 25 | if topoRequest.status_code != 200: |
| 26 | print topoRequest.text |
| 27 | sys.exit(1) |
| 28 | |
| 29 | topoJson = topoRequest.json() |
| 30 | |
| 31 | for deviceIndex in range(first, last+1): |
| 32 | lookingFor = "of:" + format(deviceIndex, '016x') |
| 33 | print lookingFor |
| 34 | for arrayIndex in range(0, len(topoJson["devices"])): |
| 35 | device = topoJson["devices"][arrayIndex] |
| 36 | if device == lookingFor: |
| 37 | found = found + 1 |
| 38 | print "Match found for " + device |
| 39 | break |
| 40 | |
| 41 | |
| 42 | if found == last - first: |
| 43 | sys.exit(0) |
| 44 | |
| 45 | print "Found " + str(found) + " matches, need " + str(last - first) |
| 46 | sys.exit(2) |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |