ait.core.db module

AIT Database

The ait.db module provides a general database storage layer for commands and telemetry with several backends.

class ait.core.db.GenericBackend

Bases: object

Generic database backend abstraction

GenericBackend attempts to adequately abstract database operations into a small set of common methods. Not all methods will be useful for every database type and additional methods may need to be added for future database support.

Generally, the expected method functionality should be

connect

Connect to instance of the database via the backend driver. Five configuration options are respected by convention in AIT built-in backend implementations if they’re applicable to the given backend

database.host
The host to connect to. Defaults to localhost
database.port
The port to connect to. Defaults to technology specific value.
database.un
The username to use when connecting to the database. Defaults to a technology specific value.
database.pw
The password to use when connecting to the database. Defaults to a technology specific value.
database.dbname
The name of the database to create/use. Defaults to ait.
create
Create a database in the database instance
insert
Insert a packet into the database
query
Take a string defining a database query and return the results. The format of the results is backend specific.
close
Close the connection to the database instance and handle any cleanup
__init__()

x.__init__(…) initializes x; see help(type(x)) for signature

close(**kwargs)

Close connection to the database instance.

connect(**kwargs)

Connect to a backend’s database instance.

create(**kwargs)

Create a database in the instance.

insert(packet, **kwargs)

Insert a record into the database.

query(query, **kwargs)

Query the database instance and return results.

class ait.core.db.InfluxDBBackend

Bases: ait.core.db.GenericBackend

InfluxDB Backend Abstraction

This requires the InfluxDB Python library to be installed and InfluxDB to be installed. Note, the InfluxDB Python library is only supports up to version 1.2.4. As such, this is only tested against 1.2.4. Newer versions may work but are not officially supported by AIT.

https://github.com/influxdata/influxdb-python https://docs.influxdata.com/influxdb

__init__()
close(**kwargs)

Close the database connection

connect(**kwargs)

Connect to an InfluxDB instance

Connects to an InfluxDB instance and switches to a given database. If the database doesn’t exist it is created first via create().

Configuration Parameters

host
The host for the connection. Passed as either the config key database.host or the kwargs argument host. Defaults to localhost.
port
The port for the connection. Passed as either the config key database.port or the kwargs argument port. Defaults to 8086.
un
The un for the connection. Passed as either the config key database.un or the kwargs argument un. Defaults to root.
pw
The pw for the connection. Passed as either the config key database.pw or the kwargs argument pw. Defaults to pw.
database name
The database name for the connection. Passed as either the config key database.dbname or the kwargs argument database. Defaults to ait.
create(**kwargs)

Create a database in a connected InfluxDB instance

Configuration Parameters

database name
The database name to create. Passed as either the config key database.dbname or the kwargs argument database. Defaults to ait.
Raises:
AttributeError:
If a connection to the database doesn’t exist
classmethod create_packets_from_results(packet_name, result_set)

Generate AIT Packets from a InfluxDB query ResultSet

Extract Influx DB query results into one packet per result entry. This assumes that telemetry data was inserted in the format generated by InfluxDBBackend.insert(). Complex types such as CMD16 and EVR16 are evaluated if they can be properly encoded from the raw value in the query result. If there is no opcode / EVR-code for a particular raw value the value is skipped (and thus defaulted to 0).

Arguments
packet_name (string)
The name of the AIT Packet to create from each result entry
result_set (influxdb.resultset.ResultSet)
The query ResultSet object to convert into packets
Returns
A list of packets extracted from the ResultSet object or None if an invalid packet name is supplied.
insert(packet, time=None, **kwargs)

Insert a packet into the database

Arguments
packet
The ait.core.tlm.Packet instance to insert into the database
time
Optional parameter specifying the time value to use when inserting the record into the database. Default case does not provide a time value so Influx defaults to the current time when inserting the record.
tags
Optional kwargs argument for specifying a dictionary of tags to include when adding the values. Defaults to nothing.
query(query, **kwargs)

Query the database and return results

Queries the Influx instance and returns a ResultSet of values. For API documentation for InfluxDB-Python check out the project documentation. https://github.com/influxdata/influxdb-python

Arguments
query
The query string to send to the database
class ait.core.db.SQLiteBackend

Bases: ait.core.db.GenericBackend

__init__()
close(**kwargs)

Close the database connection.

connect(**kwargs)

Connect to a SQLite instance

Configuration Parameters

database
The database name or file to “connect” to. Defaults to ait.
create(**kwargs)

Create a database for the current telemetry dictionary

Connects to a SQLite instance via connect() and creates a skeleton database for future data inserts.

Configuration Parameters

tlmdict
The ait.core.tlm.TlmDict instance to use. Defaults to the currently configured telemetry dictionary.
insert(packet, **kwargs)

Insert a packet into the database

Arguments
packet
The ait.core.tlm.Packet instance to insert into the database
query(query, **kwargs)

Query the database and return results

Queries the SQLite instance and returns a list of tuples of values.

Arguments
query
The query string to send to the database