Ray Milkey | a0f983b | 2016-06-23 19:39:55 -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) < 3: |
| 9 | print "usage: find-dhcp-netcfg onos-node name1=value1 ..." |
| 10 | sys.exit(1) |
| 11 | |
| 12 | node = sys.argv[1] |
| 13 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 14 | cfgRequest = requests.get('http://' + node + |
| 15 | ':8181/onos/v1/network/configuration/apps/org.onosproject.dhcp', |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 16 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 17 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 18 | print cfgRequest.text |
| 19 | |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 20 | if cfgRequest.status_code != 200: |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 21 | sys.exit(1) |
| 22 | |
| 23 | cfgJson = cfgRequest.json() |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 24 | |
| 25 | for index in range(2, len(sys.argv)): |
| 26 | pair = sys.argv[index].split("=") |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 27 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 28 | dhcp = cfgJson["dhcp"] |
| 29 | appFound = True |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 30 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 31 | name = pair[0] |
| 32 | value = pair[1] |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 33 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 34 | if dhcp[name] != value: |
| 35 | print name + " differs: expected " + value + " but found " + dhcp[name] |
| 36 | print cfgJson |
| 37 | sys.exit(1) |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 38 | |
Ray Milkey | e685d7d | 2016-08-04 17:00:14 -0700 | [diff] [blame] | 39 | |
| 40 | sys.exit(0) |
| 41 | |
Ray Milkey | a0f983b | 2016-06-23 19:39:55 -0700 | [diff] [blame] | 42 | |
| 43 | |
| 44 | |
| 45 | |