libgs entrypoints¶
date: | 2018-01-01 |
---|---|
author: | Kjetil Wormnes |
libgs-db¶
libgs-db is a command-line tool to interact with any libgs-compatible database. It can connect to mysql databases, and to sqlite files, and in fact, to any other database permitted by SQLAlchemy.
For full reference:
$ libgs-db --help
The most common use of libgs-db is to prune the databases to not get out of control. To do so, you should add a cron job to a script that runs libgs-db to prune the database. It will look something like:
libgs-db mysql+pymysql://uname:pwd@localhost/libgs[comms] --prune 1000 -d "sqlite:////backup/path/db.sqlite[comms]" --delete -f
libgs-db mysql+pymysql://uname:pwd@localhost/libgs[passes] --prune 1000 -d "sqlite:////backup/path/db.sqlite[passes]" --delete -f
libgs-db mysql+pymysql://uname:pwd@localhost/libgs[monitor] --prune 1000 -d "sqlite:////backup/path/db.sqlite[monitor]" --delete -f
This would prune the comms and passes tables to 1000 rows, backing up the excess rows into db.sqlite.
Another ommon use is to just quickly inspect the database to see the available tables. (This will work on non-libgs databases too):
$ libgs-db mysql+pymysql://uname:pwd@localhost/libgs
No table specified. Do so by adding it in square brackets: mysql+pymysql://adfags:@dfags@localhost/adfags[table_name]
I found the following tables in mysql+pymysql://adfags:@dfags@localhost/adfags:
* passes ( 7374 rows )
- _id INTEGER(11)
- _tstamp DECIMAL(20, 12)
- key VARCHAR(1024)
- value TEXT
- pass_id VARCHAR(1024)
- module VARCHAR(1024)
* monitor ( 224834 rows )
- _id INTEGER(11)
- _tstamp DECIMAL(20, 12)
- key VARCHAR(1024)
- value TEXT
- pass_id VARCHAR(1024)
- alert VARCHAR(1024)
* comms ( 10008 rows )
- _id INTEGER(11)
- _tstamp DECIMAL(20, 12)
- nid VARCHAR(1024)
- pass_id VARCHAR(1024)
- orig VARCHAR(1024)
- dest VARCHAR(1024)
- msg TEXT
Of course, you could do the same with a sqlite file. For example, to inspect the structure of the backup file created in above:
$ libgs-db sqlite:////backup/path/db.sqlite
You could then inspect the contents of the specific tables, export to CSV, etc by specifying the table in square brackets. For example, show the 3 most recent rows of the comms table:
$ libgs-db mysql+pymysql://adfags:@dfags@localhost/adfags[comms] -l 3 -n
_tstamp nid pass_id orig dest msg
_id
19302 2018-10-29 04:10:56.150400 43014 20181029041407 Sat GS [0, 0, 182, 0, 17, 15, 167, 66, 186, 10, 18, 0...
19301 2018-10-29 04:09:05.731200 43014 20181029041407 Sat GS [211, 1, 128, 0, 32, 59, 170, 84, 150, 165, 19...
19300 2018-10-29 04:08:08.707200 43014 20181029041407 Sat GS [211, 1, 128, 0, 194, 97, 212, 76, 209, 74, 73...
See the --help
reference for full details on the available arguments.
libgs-restapi¶
libgs-restapi is the command-line tool to start a libgs
restapi
.For a full reference:
$ libgs-restapi --helpExample Create a restapi and connect it to the mysql database at localhost/libgs with username uname and password pwd, and use the binary path (where to store files that are too big for the database, see the disk_path in
database.Database
) as /libgs-db-bib. Bind publicly (0.0.0.0) on port 10001:$ libgs-restapi -a 0.0.0.0 -p 10001 --db mysql+pymysql://uname:pwd@localhost/libgs --db-bin-path /libgs-db-binExample Map RPC APIs.
libgs-restapi has the ability to map an arbitrary XMLRPC api. See
restapi
for details. In order to set it up using the libgs-restapi command-line tool use the -r parametr. For example:$ libgs-restapi -r rpc/gs http://localhost:10001 -r rpc/sch http://localhost:8000will create two additional api endpoints on
/api/rpc/gs
and/api/rpc/sch
to which it will map thelibgs.groundstation.GroundStation
andlibgs.rpc.RPCSchedulerServer
XMLRPC API interfaces respectively.Note that any XMLRPC interface can be mapped this way so long as it has registered introspection functions. See SimpleXMLRPCServer.
register_introspection_functions()
. (you can of course also uselibgs.rpc.RPCServer
as a drop-in replacement for SimpleXMLRPCServer anytime you make such an api)See the –help for detailed reference on avialable arguments
libgs-emulate¶
libgs-emulate is a console script thar can emulate certain hardware.
Currently, it can emulate:
- radio
- rotctld
For a full reference on available arguments run:
$ libgs-emulate --helpFor emulator specific help run:
$ libgs-emulate radio --help $ libgs-emulate rotctld --help