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 | import urllib |
| 6 | |
| 7 | from requests.auth import HTTPBasicAuth |
| 8 | |
| 9 | if len(sys.argv) != 4: |
| 10 | print "usage: find-device onos-node name device-id" |
| 11 | sys.exit(1) |
| 12 | |
| 13 | node = sys.argv[1] |
| 14 | name = sys.argv[2] |
| 15 | id = sys.argv[3] |
| 16 | |
| 17 | deviceRequest = requests.get('http://' + node + ':8181/onos/v1/devices/' + |
| 18 | urllib.quote_plus(id), |
| 19 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 20 | |
| 21 | if deviceRequest.status_code != 200: |
| 22 | print deviceRequest.text |
| 23 | sys.exit(1) |
| 24 | |
| 25 | deviceJson = deviceRequest.json() |
| 26 | |
| 27 | print "@stc " + name + "Id=" + deviceJson["id"] |
| 28 | print "@stc " + name + "Type=" + deviceJson["type"] |
| 29 | print "@stc " + name + "Available=" + str(deviceJson["available"]) |
| 30 | channelId = deviceJson["annotations"]["channelId"] |
| 31 | channelIdWords = channelId.split(':') |
| 32 | print "@stc " + name + "IpAddress=" + channelIdWords[0] |
| 33 | |
| 34 | sys.exit(0) |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |