diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb12ee7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# Created by https://www.gitignore.io + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c04a403 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# IBOOTPY +A simple tool that to replace the perl script provided with first generation iboot devices. Has been tested with an iBoot G2 and demonstrated to work. + +## Installation +In a virtual env, anaconda env, or other Python 3.x install you can simply run `python setup.py install`. + +This will add a iboot module to the site-packages as well as an ibootpy binary to the path + +### Files Created + * ibootpy - located in python environments 'bin' directory. + * iboot-0.1.0-py.egg - located (for anaconda) inside the environments lib/pythonX/site-packages/ folder. + + +## Inspiration +During an expansion of our lab management infrastructure we discovered the older perl script no longer functioned due to the move to the DxP protocol on newer devices. Fortunately the basic infrastructure for making DxP work via python existed, since the provided C libraries rely on winsock and are windows only. This expands the original library to provide a full tool for ease of use. + +## Usage +This update provides a basic command-line tool for using the DxP protocol allowing status checks, toggling relays, and setting all relays to on or off. It can be run using the command `ibootpy`. + +``` +ibootpy [-h] [--port PORT] [-v] [-q] [--debug] IP USER PASSWORD ACTION + +ibootpy - iBoot DxP Tool + +positional arguments: + IP IP you wish to interact with + USER User Name + PASSWORD Device Password + ACTION Action to perform on list of iBoot Devices (default status) + +optional arguments: + -h, --help show this help message and exit + --port PORT Port to communicate with device + -v, --verbose verbose output + -q, --quiet silence output, simply return success or failure. + --debug Enable Debug Output + +``` + +## Alterations From Base Package + +### Python Version +This module is now adjusted to be compliant with Python 3. + +### Get Relays +This now returns a dictionary of the relays correctly formatted for toggling and setting updates by updating the individual relay entries and feeding the dictionary back to the interface. + +### Logging +No longer institutes default DEBUG output, simply provides a logger called 'iBootInterface', when running ibootpy this defaults to INFO level output with flags to enable DEBUG or silence all output. + +### iBootDevice Interface Setup +The interface will now directly accept strings for username and password instead of requiring you to use str.encode() on them. It does this by simply checking for string types and converting them during `__init__` of the interface. + +### Normalization of Indexing +I've tried to step through the system and make sure that ranges are used the same everywhere, the relays are 1 indexed (this is not documented in the protocol sheet) so I've tried to make sure all indexing is done correctly vs. a 1 index instead of having to manipulate relay numbers mid code. + +## Future Work + * Properly formatted output instead of relying solely on log output. + * This may actually be easiest to do with a second logger that just handles formatted standard output, this would allow quiet to work relatively trivially. + * Refactoring of seq_num updates to easily readable code paths. There's updates in some odd places, they work but they make following code flow difficult. diff --git a/iboot/iboot.py b/iboot/iboot.py old mode 100644 new mode 100755 index 97e34f2..a31ef3b --- a/iboot/iboot.py +++ b/iboot/iboot.py @@ -3,9 +3,22 @@ import logging import socket import struct +import sys +import argparse + +logging.getLogger('iBootInterface').addHandler(logging.NullHandler()) HELLO_STR = 'hello-000' +"""struct format: +little-endian +unsigned char command +21 char array username +21 char array password +unsigned char description +unsigned char parameters (should be padding byte or 'B' as unused) +unsigned short sequence number (uint16) - was H-2byte, set to I-4byte +""" HEADER_STRUCT = struct.Struct('