Ray Milkey | f16975b | 2018-05-15 14:14:24 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import requests |
| 4 | |
| 5 | from requests.auth import HTTPBasicAuth |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | |
| 10 | if len(sys.argv) != 5: |
| 11 | print "usage: change-device-portstate onos-node device-id port new_enabled_state" |
| 12 | sys.exit(1) |
| 13 | |
| 14 | node = sys.argv[1] |
| 15 | device_id = sys.argv[2] |
| 16 | port = sys.argv[3] |
| 17 | new_enabled_state = sys.argv[4] |
| 18 | |
| 19 | payload = '{ "enabled": ' + new_enabled_state + ' }' |
| 20 | |
| 21 | change_request = requests.post('http://' + node + ':8181/onos/v1/devices/' + device_id + '/portstate/' + port, |
| 22 | auth=HTTPBasicAuth('onos', 'rocks'), |
| 23 | data=payload) |
| 24 | |
| 25 | if change_request.status_code != 200: |
| 26 | print change_request.text |
| 27 | sys.exit(1) |
| 28 | |
| 29 | sys.exit(0) |
| 30 | |
| 31 | |
| 32 | |