try: # pylint: disable=undefined-variable range_ = xrange except NameError: range_ = range __all__ = ("Job", ) logger = getLogger("models.job") JobTagAssociation = db.Table( config.get("table_job_tag_assoc"), db.metadata, db.Column("job_id", IDTypeWork, db.ForeignKey("%s.id" % config.get("table_job")), primary_key=True, doc="The id of the job associated with this task"), db.Column("tag_id", db.Integer, db.ForeignKey("%s.id" % config.get("table_tag")), primary_key=True, doc="The id of the tag being associated with the job")) JobDependency = db.Table( config.get("table_job_dependency"), db.metadata, db.Column("parentid", IDTypeWork, db.ForeignKey("%s.id" % config.get("table_job")), primary_key=True, doc="The parent job id of the job dependency"), db.Column("childid", IDTypeWork,
from pyfarm.core.logger import getLogger from pyfarm.core.enums import STRING_TYPES, PY3 from pyfarm.master.application import app, db, login_serializer from pyfarm.models.core.mixins import ReprMixin from pyfarm.models.core.functions import split_and_extend from pyfarm.models.core.cfg import ( TABLE_USERS_USER, TABLE_USERS_ROLE, TABLE_USERS_USER_ROLES, MAX_USERNAME_LENGTH, SHA256_ASCII_LENGTH, MAX_EMAILADDR_LENGTH, MAX_ROLE_LENGTH, TABLE_USERS_PROJECTS, TABLE_PROJECT) logger = getLogger("models.users") # roles the user is a member of UserRoles = db.Table( TABLE_USERS_USER_ROLES, db.Column("user_id", db.Integer, db.ForeignKey("%s.id" % TABLE_USERS_USER)), db.Column("role_id", db.Integer, db.ForeignKey("%s.id" % TABLE_USERS_ROLE))) # projects the user is a member of UserProjects = db.Table( TABLE_USERS_PROJECTS, db.Column("user_id", db.Integer, db.ForeignKey("%s.id" % TABLE_USERS_USER), primary_key=True), db.Column("project_id", db.Integer, db.ForeignKey("%s.id" % TABLE_PROJECT), primary_key=True)) class User(db.Model, UserMixin, ReprMixin): """ Stores information about a user including the roles they belong to
from pyfarm.core.enums import WorkState from pyfarm.master.application import db from pyfarm.models.core.types import IDTypeAgent, IDTypeWork from pyfarm.models.core.functions import work_columns, repr_enum from pyfarm.models.core.cfg import (TABLE_JOB, TABLE_TASK, TABLE_AGENT, TABLE_TASK_DEPENDENCIES, TABLE_PROJECT) from pyfarm.models.core.mixins import (ValidatePriorityMixin, WorkStateChangedMixin, UtilityMixins, ReprMixin) TaskDependencies = db.Table( TABLE_TASK_DEPENDENCIES, db.metadata, db.Column("parent_id", IDTypeWork, db.ForeignKey("%s.id" % TABLE_TASK), primary_key=True), db.Column("child_id", IDTypeWork, db.ForeignKey("%s.id" % TABLE_TASK), primary_key=True)) class Task(db.Model, ValidatePriorityMixin, WorkStateChangedMixin, UtilityMixins, ReprMixin): """ Defines a task which a child of a :class:`Job`. This table represents rows which contain the individual work unit(s) for a job. """ __tablename__ = TABLE_TASK STATE_ENUM = WorkState STATE_DEFAULT = STATE_ENUM.QUEUED
from pyfarm.core.enums import WorkState, DBWorkState from pyfarm.master.application import db from pyfarm.models.core.functions import work_columns from pyfarm.models.core.types import id_column, JSONDict, JSONList, IDTypeWork from pyfarm.models.core.cfg import ( TABLE_JOB, TABLE_JOB_SOFTWARE_DEP, TABLE_JOB_TYPE, TABLE_TAG, TABLE_JOB_TAG_ASSOC, MAX_COMMAND_LENGTH, MAX_TAG_LENGTH, MAX_USERNAME_LENGTH, TABLE_SOFTWARE, TABLE_JOB_DEPENDENCIES, TABLE_PROJECT) from pyfarm.models.core.mixins import ( ValidatePriorityMixin, WorkStateChangedMixin, ReprMixin) from pyfarm.models.jobtype import JobType # required for a relationship JobSoftwareDependency = db.Table( TABLE_JOB_SOFTWARE_DEP, db.metadata, db.Column("job_id", IDTypeWork, db.ForeignKey("%s.id" % TABLE_JOB), primary_key=True), db.Column("software_id", db.Integer, db.ForeignKey("%s.id" % TABLE_SOFTWARE), primary_key=True)) JobTagAssociation = db.Table( TABLE_JOB_TAG_ASSOC, db.metadata, db.Column("job_id", IDTypeWork, db.ForeignKey("%s.id" % TABLE_JOB), primary_key=True), db.Column("tag_id", db.Integer, db.ForeignKey("%s.id" % TABLE_TAG), primary_key=True)) JobDependencies = db.Table( TABLE_JOB_DEPENDENCIES, db.metadata, db.Column("parentid", IDTypeWork,
from pyfarm.models.job import Job __all__ = ("Agent", ) ALLOW_AGENT_LOOPBACK = config.get("allow_agents_from_loopback") REGEX_HOSTNAME = re.compile("^(?!-)[A-Z\d-]{1,63}(?<!-)" "(\.(?!-)[A-Z\d-]{1,63}(?<!-))*\.?$", re.IGNORECASE) AgentSoftwareVersionAssociation = db.Table( config.get("table_agent_software_version_assoc"), db.metadata, db.Column( "agent_id", IDTypeAgent, db.ForeignKey("%s.id" % config.get("table_agent")), primary_key=True), db.Column( "software_version_id", db.Integer, db.ForeignKey("%s.id" % config.get("table_software_version")), primary_key=True)) AgentTagAssociation = db.Table( config.get("table_agent_tag_assoc"), db.metadata, db.Column( "agent_id", IDTypeAgent, db.ForeignKey("%s.id" % config.get("table_agent")), primary_key=True), db.Column( "tag_id", db.Integer, db.ForeignKey("%s.id" % config.get("table_tag")),
from pyfarm.core.enums import STRING_TYPES, PY3 from pyfarm.master.application import app, db, login_serializer from pyfarm.master.config import config from pyfarm.models.core.mixins import ReprMixin from pyfarm.models.core.functions import split_and_extend __all__ = ("User", "Role") SHA256_ASCII_LENGTH = 64 # static length of a sha256 string # roles the user is a member of UserRole = db.Table( config.get("table_user_role"), db.Column("user_id", db.Integer, db.ForeignKey("%s.id" % config.get("table_user")), doc="The id of the associated user"), db.Column("role_id", db.Integer, db.ForeignKey("%s.id" % config.get("table_role")), doc="The id of the associated role")) class User(db.Model, UserMixin, ReprMixin): """ Stores information about a user including the roles they belong to """ __tablename__ = config.get("table_user") REPR_COLUMNS = ("id", "username") id = db.Column(db.Integer, primary_key=True, nullable=False)
class WorkStateChangedModel(db.Model, WorkStateChangedMixin): __tablename__ = "%s_state_change_test" % config.get("table_prefix") id = db.Column(Integer, primary_key=True, autoincrement=True) state = db.Column(WorkStateEnum) attempts = db.Column(Integer, nullable=False, default=0) time_started = db.Column(DateTime) time_finished = db.Column(DateTime) event.listen(WorkStateChangedModel.state, "set", WorkStateChangedModel.state_changed) MixinModelRelation1 = db.Table( "%s_mixin_rel_test1" % config.get("table_prefix"), db.metadata, db.Column("mixin_id", db.Integer, db.ForeignKey("%s.id" % "%s_mixin_test" % config.get("table_prefix")), primary_key=True)) MixinModelRelation2 = db.Table( "%s_mixin_rel_test2" % config.get("table_prefix"), db.metadata, db.Column("mixin_id", db.Integer, db.ForeignKey("%s.id" % "%s_mixin_test" % config.get("table_prefix")), primary_key=True)) class MixinModel(db.Model, UtilityMixins): __tablename__ = "%s_mixin_test" % config.get("table_prefix")
id_column, IPv4Address, IDTypeAgent, IDTypeTag, UseAgentAddressEnum, AgentStateEnum) from pyfarm.models.core.cfg import ( TABLE_AGENT, TABLE_SOFTWARE, TABLE_TAG, TABLE_AGENT_TAG_ASSOC, MAX_HOSTNAME_LENGTH, MAX_TAG_LENGTH, TABLE_AGENT_SOFTWARE_ASSOC, TABLE_PROJECT_AGENTS, TABLE_PROJECT) PYFARM_REQUIRE_PRIVATE_IP = read_env_bool("PYFARM_REQUIRE_PRIVATE_IP", False) REGEX_HOSTNAME = re.compile("^(?!-)[A-Z\d-]{1,63}(?<!-)" "(\.(?!-)[A-Z\d-]{1,63}(?<!-))*\.?$" , re.IGNORECASE) AgentSoftwareAssociation = db.Table( TABLE_AGENT_SOFTWARE_ASSOC, db.metadata, db.Column("agent_id", IDTypeAgent, db.ForeignKey("%s.id" % TABLE_AGENT), primary_key=True), db.Column("software_id", db.Integer, db.ForeignKey("%s.id" % TABLE_SOFTWARE), primary_key=True)) AgentTagAssociation = db.Table( TABLE_AGENT_TAG_ASSOC, db.metadata, db.Column("agent_id", IDTypeAgent, db.ForeignKey("%s.id" % TABLE_AGENT), primary_key=True), db.Column("tag_id", db.Integer, db.ForeignKey("%s.id" % TABLE_TAG), primary_key=True)) AgentProjects = db.Table( TABLE_PROJECT_AGENTS, db.metadata, db.Column("agent_id", IDTypeAgent,