3
"""A utility to control the USB relay's in the QA lab."""
10
def set_relay(urlbase, bank, relay, on):
11
# the values 100/108 came from the JavaScript of our web-based management
12
# system for the relays. The meaning of the values isn't documented.
17
cmd = '254,{},{}'.format(relay, bank + 1)
18
url = '{}/cgi-bin/runcommand.sh?1:cmd={}'.format(urlbase, cmd)
19
resp = urllib2.urlopen(url)
22
print('ERROR: bad response: {}'.format(resp))
27
parser = argparse.ArgumentParser(
28
description='Toggles an NCD relay connected to a USB cable on/off')
29
parser.add_argument('-u', '--url',
30
default='http://qa-relay-control.ubuntu-ci',
31
help='NCD relay URL. default=%(default)s')
32
parser.add_argument('-b', '--bank', type=int, required=True,
33
help='NCD relay 0-based bank ID.')
34
parser.add_argument('-r', '--relay', type=int, required=True,
35
help='NCD relay 0-based relay ID.')
36
parser.add_argument('action', metavar='action',
37
choices=('on', 'off'),
38
help='action to perform on|off')
42
if __name__ == '__main__':
43
args = _get_parser().parse_args()
45
# NOTE: when the relay is ON usb is actually OFF. ie the logic
46
# is backwards between them, thus action=off actually turns
48
set_relay(args.url, args.bank, args.relay, args.action == 'off')