Add appliance table, and probe "location" in that context

This commit is contained in:
Lance Edgar 2018-10-19 17:51:25 -05:00
parent 871a9154da
commit 6be6467f59
2 changed files with 96 additions and 1 deletions

View file

@ -41,6 +41,30 @@ from rattail.db.model.core import ModelBase
Base = declarative_base(cls=ModelBase)
@six.python_2_unicode_compatible
class Appliance(Base):
"""
Represents an appliance which is monitored by tempmon.
"""
__tablename__ = 'appliance'
__table_args__ = (
sa.UniqueConstraint('name', name='appliance_uq_name'),
)
uuid = uuid_column()
name = sa.Column(sa.String(length=255), nullable=False, doc="""
Human-friendly (and unique) name for the appliance.
""")
location = sa.Column(sa.String(length=255), nullable=True, doc="""
Description of the appliance's physical location.
""")
def __str__(self):
return self.name
@six.python_2_unicode_compatible
class Client(Base):
"""
@ -107,6 +131,7 @@ class Probe(Base):
__tablename__ = 'probe'
__table_args__ = (
sa.ForeignKeyConstraint(['client_uuid'], ['client.uuid'], name='probe_fk_client'),
sa.ForeignKeyConstraint(['appliance_uuid'], ['appliance.uuid'], name='probe_fk_appliance'),
sa.UniqueConstraint('config_key', name='probe_uq_config_key'),
)
@ -126,8 +151,29 @@ class Probe(Base):
"""))
config_key = sa.Column(sa.String(length=50), nullable=False)
appliance_type = sa.Column(sa.Integer(), nullable=False)
description = sa.Column(sa.String(length=255), nullable=False)
appliance_uuid = sa.Column(sa.String(length=32), nullable=True)
appliance = orm.relationship(
Appliance,
doc="""
Reference to the appliance which this probe monitors.
""",
backref=orm.backref(
'probes',
doc="""
List of probes which monitor this appliance.
"""))
description = sa.Column(sa.String(length=255), nullable=False, doc="""
General human-friendly description for the probe.
""")
location = sa.Column(sa.String(length=255), nullable=True, doc="""
Description of the probe's physical location, relative to the appliance.
""")
device_path = sa.Column(sa.String(length=255), nullable=True)
enabled = sa.Column(sa.Boolean(), nullable=False, default=True)