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 | |
| 14 | cfgRequest = requests.get('http://' + node + ':8181/onos/v1/network/configuration', |
| 15 | auth=HTTPBasicAuth('onos', 'rocks')) |
| 16 | |
| 17 | if cfgRequest.status_code != 200: |
| 18 | print cfgRequest.text |
| 19 | sys.exit(1) |
| 20 | |
| 21 | cfgJson = cfgRequest.json() |
| 22 | appFound = False |
| 23 | |
| 24 | |
| 25 | for index in range(2, len(sys.argv)): |
| 26 | pair = sys.argv[index].split("=") |
| 27 | for app in cfgJson["apps"]: |
| 28 | if app == "org.onosproject.dhcp": |
| 29 | dhcp = cfgJson["apps"][app]["dhcp"] |
| 30 | appFound = True |
| 31 | |
| 32 | name = pair[0] |
| 33 | value = pair[1] |
| 34 | |
| 35 | if dhcp[name] != value: |
| 36 | print name + " differs: expected " + value + " but found " + dhcp[name] |
| 37 | print cfgJson |
| 38 | sys.exit(1) |
| 39 | |
| 40 | if appFound: |
| 41 | sys.exit(0) |
| 42 | |
| 43 | print "DHCP app not found" |
| 44 | print cfgJson |
| 45 | sys.exit(2) |
| 46 | |
| 47 | |
| 48 | |
| 49 | |