pyfarm.models.core.types module

Custom Columns and Type Generators

Special column types used by PyFarm’s models.

class pyfarm.models.core.types.AgentStateEnum(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.EnumType

custom column type for working with AgentState

enum = AgentState(OFFLINE=Values(201, 'offline'), RUNNING=Values(203, 'running'), DISABLED=Values(200, 'disabled'), ONLINE=Values(202, 'online'))
class pyfarm.models.core.types.EnumType(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Special column type which handles translation from a human readable enum into an integer that the database can use.

Variables:enum – required class level variable which defines what enum this custom column handles
Raises AssertionError:
 raised if enum is not set on the class
enum = NotImplemented
impl

alias of Integer

json_types = (<class 'str'>, <class 'int'>)
process_bind_param(value, dialect)[source]

Takes value and maps it to the internal integer.

Raises ValueError:
 raised if value is not part of the class level enum mapping
process_result_value(value, dialect)[source]
pyfarm.models.core.types.IDTypeAgent

alias of UUIDType

class pyfarm.models.core.types.IPAddress(addr, version=None, flags=0)[source]

Bases: netaddr.ip.IPAddress

Custom version of netaddr.IPAddress which can match itself against other instance of the same class, a string, or an integer.

class pyfarm.models.core.types.IPv4Address(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Column type which can store and retrieve IPv4 addresses in a more efficient manner

MAX_INT = 4294967295
checkInteger(value)[source]
impl

alias of BigInteger

json_types = (<class 'str'>, <class 'int'>)
process_bind_param(value, dialect)[source]
process_result_value(value, dialect)[source]
class pyfarm.models.core.types.JSONDict(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.JSONSerializable

Column type for storing dictionary objects as json

json_types

alias of dict

serialize_types = (<class 'dict'>, <class 'collections.UserDict'>)
class pyfarm.models.core.types.JSONList(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.JSONSerializable

Column type for storing list objects as json

json_types

alias of list

serialize_types = (<class 'list'>, <class 'tuple'>, <class 'collections.UserList'>)
class pyfarm.models.core.types.JSONSerializable(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Base of all custom types which process json data to and from the database.

Variables:
  • serialize_types (tuple) – the kinds of objects we expect to serialize to and from the database
  • serialize_none (bool) – if True then return None instead of converting it to its json value
  • allow_blank (bool) – if True, do not raise a ValueError for empty data
  • allow_empty (bool) – if True, do not raise ValueError if the input data itself is empty
dumps(value)[source]

Performs the process of dumping value to json. For classes such as UserDict or UserList this will dump the underlying data instead of the object itself.

impl

alias of UnicodeText

process_bind_param(value, dialect)[source]

Converts the value being assigned into a json blob

process_result_value(value, dialect)[source]

Converts data from the database into a Python object

serialize_none = False
serialize_types = None
class pyfarm.models.core.types.MACAddress(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Column type which can store and retrieve MAC addresses in a more efficient manner

MAX_INT = 281474976710655
impl

alias of BigInteger

json_types = (<class 'str'>, <class 'int'>)
process_bind_param(value, dialect)[source]
process_result_value(value, dialect)[source]
class pyfarm.models.core.types.OperatingSystemEnum(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.EnumType

custom column type for working with AgentState

enum = OperatingSystem(BSD=Values(304, 'bsd'), WINDOWS=Values(301, 'windows'), OTHER=Values(303, 'other'), MAC=Values(302, 'mac'), LINUX=Values(300, 'linux'))
class pyfarm.models.core.types.UUIDType(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Custom column type which handles UUIDs in the appropriate manner for various databases.

impl

alias of TypeEngine

json_types

alias of UUID

load_dialect_impl(dialect)[source]
process_bind_param(value, dialect)[source]
process_result_value(value, dialect)[source]
class pyfarm.models.core.types.UseAgentAddressEnum(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.EnumType

custom column type for working with UseAgentAddress

enum = UseAgentAddress(LOCAL=Values(310, 'local'), REMOTE=Values(311, 'remote'), PASSIVE=Values(313, 'passive'), HOSTNAME=Values(312, 'hostname'))
class pyfarm.models.core.types.WorkStateEnum(*args, **kwargs)[source]

Bases: pyfarm.models.core.types.EnumType

custom column type for working with WorkState

enum = WorkState(RUNNING=Values(105, 'running'), PAUSED=Values(100, 'paused'), FAILED=Values(107, 'failed'), DONE=Values(106, 'done'))
pyfarm.models.core.types.id_column(column_type=None, **kwargs)[source]

Produces a column used for id on each table. Typically this is done using a class in pyfarm.models.mixins however because of the ORM and the table relationships it’s cleaner to have a function produce the column.