blob: 430e18ad36c1a9ab71cce26e50888d648d2c4306 [file] [log] [blame]
Ray Milkey4ff514c2015-09-01 09:02:03 -07001#! /usr/bin/env python
2
3import requests
4import sys
5import urllib
6
7from requests.auth import HTTPBasicAuth
8
9if len(sys.argv) != 4:
10 print "usage: find-device onos-node name device-id"
11 sys.exit(1)
12
13node = sys.argv[1]
14name = sys.argv[2]
15id = sys.argv[3]
16
17deviceRequest = requests.get('http://' + node + ':8181/onos/v1/devices/' +
18 urllib.quote_plus(id),
19 auth=HTTPBasicAuth('onos', 'rocks'))
20
21if deviceRequest.status_code != 200:
22 print deviceRequest.text
23 sys.exit(1)
24
25deviceJson = deviceRequest.json()
26
27print "@stc " + name + "Id=" + deviceJson["id"]
28print "@stc " + name + "Type=" + deviceJson["type"]
29print "@stc " + name + "Available=" + str(deviceJson["available"])
30channelId = deviceJson["annotations"]["channelId"]
31channelIdWords = channelId.split(':')
32print "@stc " + name + "IpAddress=" + channelIdWords[0]
33
34sys.exit(0)
35
36
37
38
39