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-host 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 | hostRequest = requests.get('http://' + node + ':8181/onos/v1/hosts/' + |
| 18 | urllib.quote_plus(id), |
| 19 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 20 | |
| 21 | if hostRequest.status_code != 200: |
| 22 | print hostRequest.text |
| 23 | sys.exit(1) |
| 24 | |
| 25 | hostJson = hostRequest.json() |
| 26 | |
| 27 | print "@stc " + name + "Id=" + hostJson["id"] |
| 28 | print "@stc " + name + "Mac=" + hostJson["mac"] |
| 29 | print "@stc " + name + "IpAddress=" + hostJson["ipAddresses"][0] |
| 30 | |
| 31 | sys.exit(0) |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |