Functionality for the Hades command-line utilities in hades.bin
.
Bases: ArgumentParser
ArgumentParser subclass that exists with os.EX_USAGE
exit code if
parsing fails.
Bases: Action
Setup logging for CLI applications, that do not configure logging themselves.
Set log level using command-line options parsed with parser
, the
HADES_VERBOSITY
environment variable or finally the default
value DEFAULT_VERBOSITY
.
Messages are logged to stderr by default, but can also be logged to syslog.
The possible log level settings are:
logging.ERROR
is the minimum log level.
logging.CRITICAL
will always also be logged to STDERR even if
logging to syslog.
logging.WARNING
is the default logging level, but can be
suppressed with -q
/--quiet
or HADES_VERBOSITY=0
.
Each -v
/--verbose
increases the verbosity by one level.
When the log level is lower than or equal to logging.DEBUG
also the
time, the log level and the filename are logged in addition to log message.
Flask and Celery have their own opinionated logging mechanisms. Logging
should probably be reset via reset_cli_logging()
before handing over
control to them.
program -- The name of the program
args -- The parsed arguments of the program with parser
or a
subparser.
Database utilities.
This module contains
the sqlalchemy Table
schema definitions
structures related to the former, like TypeDecorators
functions interacting with the database (both for reading and manipulating)
Create a copy of a table definition with a different name
original_table -- The table to copy
new_name -- Name of the new table
temporary -- Should the new table be marked as temporary
A new table
Bases: TypeDecorator
Custom SQLAlchemy type for MAC addresses.
Use the PostgreSQL macaddr
type on the database side and
netaddr.EUI
on the Python side.
alias of EUI
Receive a bound parameter value to be converted.
Subclasses override this method to return the
value that should be passed along to the underlying
TypeEngine
object, and from there to the
DBAPI execute()
method.
The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
value -- Data to operate upon, of any type expected by
this method in the subclass. Can be None
.
dialect -- the Dialect
in use.
Receive a literal parameter value to be rendered inline within a statement.
This method is used when the compiler renders a literal value without using binds, typically within DDL such as in the "server default" of a column or an expression within a CHECK constraint.
The returned string will be rendered into the output string.
New in version 0.9.0.
Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the
value that should be passed back to the application,
given a value that is already processed by
the underlying TypeEngine
object, originally
from the DBAPI cursor method fetchone()
or similar.
The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
value -- Data to operate upon, of any type expected by
this method in the subclass. Can be None
.
dialect -- the Dialect
in use.
This operation should be designed to be reversible by the "process_bind_param" method of this class.
Represent a mac address as itself with the netaddr.mac_unix_expanded dialect set.
This causes the string representation to be the colon-separated 00:de:ad:be:ef:00
which is used in most other places in hades.
This normalization is useful to keep the representations of MAC addresses in the journal consistent.
Bases: TypeDecorator
Custom SQLAlchemy type for IP addresses.
Use the PostgreSQL inet
type on the database side and
netaddr.IPAddress
on the Python side.
alias of IPAddress
Receive a bound parameter value to be converted.
Subclasses override this method to return the
value that should be passed along to the underlying
TypeEngine
object, and from there to the
DBAPI execute()
method.
The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
value -- Data to operate upon, of any type expected by
this method in the subclass. Can be None
.
dialect -- the Dialect
in use.
Receive a literal parameter value to be rendered inline within a statement.
This method is used when the compiler renders a literal value without using binds, typically within DDL such as in the "server default" of a column or an expression within a CHECK constraint.
The returned string will be rendered into the output string.
New in version 0.9.0.
Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the
value that should be passed back to the application,
given a value that is already processed by
the underlying TypeEngine
object, originally
from the DBAPI cursor method fetchone()
or similar.
The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
value -- Data to operate upon, of any type expected by
this method in the subclass. Can be None
.
dialect -- the Dialect
in use.
This operation should be designed to be reversible by the "process_bind_param" method of this class.
Bases: ARRAY
Convenience subclass for ARRAY
for zero-indexed tuples.
materialized view
The table containing the DHCP host reservations.
materialized view
The table representing the auth leases. Synced from dnsmasq state via the --dhcp-script
hook.
table
The table representing the unauth leases. Synced from dnsmasq state via the --dhcp-script
hook.
table
The table network access switches
materialized view
radius accounting information
table
materialized view
materialized view
materialized view
Radius Authorization logs
table
materialized view
materialized view
Bases: FunctionElement
Bases: tzinfo
A tzinfo factory compatible with psycopg2.tz.FixedOffsetTimezone
,
that checks if the provided UTC offset is zero and returns
datetime.timezone.utc
. If the offset is not zero an
psycopg2.DataError
is raised.
This class is implemented as a singleton that always returns the same instance.
Bases: cursor
A Cursor factory that sets the
psycopg2.extensions.cursor.tzinfo_factory
to
UTCTZInfoFactory
.
The C implementation of the cursor class does not use the proper Python attribute lookup, therefore we have to set the instance variable rather than use a class attribute.
Set up an engine.
UsageError -- if engine fails with sqlalchemy.exc.ArgumentError
.
Manually remove pyroute2 registrations to psycopg2.extensions.adapters.
a certain version of pyroute2 pollutes the psycopg2 adapters at import time. In particular, lists were forcefully rendered as strings, breaking ARRAY[] usage. We ensure the module is imported and throw out the aforementioned adapters.
Lock a table using a PostgreSQL advisory lock
The OID of the table in the pg_class relation is used as lock id.
connection -- DB connection
target_table -- Table object
Create a temporary table as a copy of a source table that will be dropped at the end of the running transaction.
connection -- DB connection
source -- Source table
destination -- Destination table
Bases: Generic
[T
]
Compute the differences in the contents of two tables with identical columns.
The master table must have at least one PrimaryKeyConstraint
or
UniqueConstraint
with only non-null columns defined.
If there are multiple constraints defined the constraints that contains the least number of columns are used.
connection -- DB connection
master -- Master table
copy -- Copy of master table
result_columns -- columns to return
unique_columns -- The columns on which to base the diff. If not specified, will try to make a meaningful decision based on existing table constraints.
True, if the contents differ, otherwise False
Execute REFRESH MATERIALIZED VIEW CONCURRENTLY
for the given
view.
connection -- A valid SQLAlchemy connection
view -- The view to refresh
Lock the given view with an advisory lock, create a temporary table of the view, refresh the view and compute the difference.
connection -- A valid SQLAlchemy connection
view -- The view to refresh and diff
copy -- A temporary table to create and diff
result_columns -- The columns to return
unique_columns -- The columns on which to base the diff. If not specified, will try to make a meaningful decision based on existing table constraints.
A 3-tuple containing three lists of tuples of the result_columns of added, deleted and modified records due to the refresh.
Delete old session from the radacct
table.
Delete old authentication results from the radpostauth
table.
Get the groups of a user.
connection -- A SQLAlchemy connection
mac -- MAC address
An iterator that yields (NAS-IP-Address, NAS-Port-Id, Group-Name)- tuples
Get the latest auth attempt of a MAC address that occurred within twice the reauthentication interval.
connection -- A SQLAlchemy connection
mac (str) -- MAC address
A (NAS-IP-Address, NAS-Port-Id, Packet-Type, Groups, Reply, Auth-Date) tuple or None if no attempt was found. Groups is an tuple of group names and Reply is a tuple of (Attribute, Value)-pairs that were sent in Access-Accept responses.
Return all DHCP host configurations.
connection -- A SQLAlchemy connection
An iterator that yields (mac, ip, hostname)-tuples
Return all NAS clients.
connection -- A SQLAlchemy connection
An iterator that yields (shortname, nasname, type, ports, secret, server, community, description)-tuples
Return accounting sessions of a particular MAC address ordered by Session-Start-Time descending.
connection -- A SQLAlchemy connection
mac (str) -- MAC address
when -- Range in which Session-Start-Time must be within
limit -- Maximum number of records
An iterator that yields (NAS-IP-Address, NAS-Port-Id, Session-Start-Time, Session-Stop-Time)-tuples ordered by Session-Start-Time descending
Return auth attempts of a particular MAC address order by Auth-Date descending.
connection -- A SQLAlchemy connection
mac -- MAC address
when -- Range in which Auth-Date must be within
limit -- Maximum number of records
An iterator that yields (NAS-IP-Address, NAS-Port-Id, Packet-Type, Groups, Reply, Auth-Date)-tuples ordered by Auth-Date descending
Return auth attempts at a particular port of an NAS ordered by Auth-Date descending.
connection -- A SQLAlchemy connection
nas_ip_address -- NAS IP address
nas_port_id -- NAS Port ID
when -- Range in which Auth-Date must be within
limit -- Maximum number of records
An iterator that yields (User-Name, Packet-Type, Groups, Reply, Auth-Date)-tuples ordered by Auth-Date descending
Return all IPs for alternative DNS configuration.
connection -- A SQLAlchemy connection
An iterator that yields ip addresses
Return all dhcp leases.
dhcp_lease_table -- DHCP lease table
connection -- A SQLAlchemy connection
subnet -- Limit leases to subnet
limit -- Maximum number of leases
interval -- If set, only return leases older than now - interval
.
An iterator that yields (Expires-At, MAC, IP-Address, Hostname, Client-ID)-tuples
Get basic lease information for a given IP.
dhcp_lease_table -- DHCP lease table
connection -- A SQLAlchemy connection
ip -- IP address
An (Expiry-Time, MAC, Hostname, Client-ID)-tuple or None
Get basic information about all leases of a given MAC.
dhcp_lease_table -- DHCP lease table
connection -- A SQLAlchemy connection
mac -- MAC address
An iterator of (Expiry-Time, IP-Address, Hostname, Client-ID)-tuples ordered by Expiry-Time descending
Return all auth leases.
connection -- A SQLAlchemy connection
subnet -- Limit leases to subnet
limit -- Maximum number of leases
interval -- If set, only return leases older than now - interval
.
An iterator that yields (Expires-At, MAC, IP-Address, Hostname, Client-ID)-tuples
Get basic auth lease information for a given IP.
connection -- A SQLAlchemy connection
ip -- IP address
An iterator of (Expiry-Time, MAC, Hostname, Client-ID)-tuples or None
Get basic information about all auth leases of a given MAC.
connection -- A SQLAlchemy connection
mac -- MAC address
An iterator of (Expiry-Time, IP-Address, Hostname, Client-ID)-tuples ordered by Expiry-Time descending
Return all unauth leases
connection -- A SQLAlchemy connection
subnet -- Limit leases to subnet
limit -- Maximum number of leases
interval -- If set, only return leases older than now - interval
.
An iterator that yields (Expires-At, MAC, IP-Address, Hostname, Client-ID)-tuples
Get basic unauth lease information for a given IP.
connection -- A SQLAlchemy connection
ip -- IP address
An (Expiry-Time, MAC, Hostname, Client-ID)-tuple or None
Get basic information about all unauth leases of a given MAC.
connection -- A SQLAlchemy connection
mac -- MAC address
An iterator of (Expiry-Time, IP-Address, Hostname, Client-ID) tuples ordered by Expiry-Time descending
Bases: object
Get all auth DHCP leases which do not belong to a host reservation
as given in auth_dhcp_lease
.
connection -- A SQLAlchemy connection
an iterator of (IPAddress, MAC) tuples.
Bases: TypedGLibError
Indicates an error during a DBus operation.
Bases: DBusError
, DBusTimeout
Bases: DBusError
The bus doesn't know how to launch a service to supply the bus name you wanted.
Bases: DBusError
, DBusTimeout
Bases: DBusError
, DBusTimeout
Bases: DBusError
Object you invoked a method on isn’t known.
Bases: Exception
Indicates a timeout during a DBus operation.
Bases: Exception
Base GLib exception