Add appliance table, and probe "location" in that context
This commit is contained in:
		
							parent
							
								
									871a9154da
								
							
						
					
					
						commit
						6be6467f59
					
				
					 2 changed files with 96 additions and 1 deletions
				
			
		| 
						 | 
					@ -0,0 +1,49 @@
 | 
				
			||||||
 | 
					# -*- coding: utf-8; -*-
 | 
				
			||||||
 | 
					"""add appliance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Revision ID: 796084026e5b
 | 
				
			||||||
 | 
					Revises: b02c531caca5
 | 
				
			||||||
 | 
					Create Date: 2018-10-19 17:28:34.146307
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from __future__ import unicode_literals, absolute_import
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# revision identifiers, used by Alembic.
 | 
				
			||||||
 | 
					revision = '796084026e5b'
 | 
				
			||||||
 | 
					down_revision = u'b02c531caca5'
 | 
				
			||||||
 | 
					branch_labels = None
 | 
				
			||||||
 | 
					depends_on = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from alembic import op
 | 
				
			||||||
 | 
					import sqlalchemy as sa
 | 
				
			||||||
 | 
					import rattail.db.types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def upgrade():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # appliance
 | 
				
			||||||
 | 
					    op.create_table('appliance',
 | 
				
			||||||
 | 
					                    sa.Column('uuid', sa.String(length=32), nullable=False),
 | 
				
			||||||
 | 
					                    sa.Column('name', sa.String(length=255), nullable=False),
 | 
				
			||||||
 | 
					                    sa.Column('location', sa.String(length=255), nullable=True),
 | 
				
			||||||
 | 
					                    sa.PrimaryKeyConstraint('uuid'),
 | 
				
			||||||
 | 
					                    sa.UniqueConstraint('name', name=u'appliance_uq_name')
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # probe
 | 
				
			||||||
 | 
					    op.add_column(u'probe', sa.Column('appliance_uuid', sa.String(length=32), nullable=True))
 | 
				
			||||||
 | 
					    op.add_column(u'probe', sa.Column('location', sa.String(length=255), nullable=True))
 | 
				
			||||||
 | 
					    op.create_foreign_key(u'probe_fk_appliance', 'probe', 'appliance', ['appliance_uuid'], ['uuid'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def downgrade():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # probe
 | 
				
			||||||
 | 
					    op.drop_constraint(u'probe_fk_appliance', 'probe', type_='foreignkey')
 | 
				
			||||||
 | 
					    op.drop_column(u'probe', 'location')
 | 
				
			||||||
 | 
					    op.drop_column(u'probe', 'appliance_uuid')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # appliance
 | 
				
			||||||
 | 
					    op.drop_table('appliance')
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,30 @@ from rattail.db.model.core import ModelBase
 | 
				
			||||||
Base = declarative_base(cls=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
 | 
					@six.python_2_unicode_compatible
 | 
				
			||||||
class Client(Base):
 | 
					class Client(Base):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					@ -107,6 +131,7 @@ class Probe(Base):
 | 
				
			||||||
    __tablename__ = 'probe'
 | 
					    __tablename__ = 'probe'
 | 
				
			||||||
    __table_args__ = (
 | 
					    __table_args__ = (
 | 
				
			||||||
        sa.ForeignKeyConstraint(['client_uuid'], ['client.uuid'], name='probe_fk_client'),
 | 
					        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'),
 | 
					        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)
 | 
					    config_key = sa.Column(sa.String(length=50), nullable=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    appliance_type = sa.Column(sa.Integer(), 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)
 | 
					    device_path = sa.Column(sa.String(length=255), nullable=True)
 | 
				
			||||||
    enabled = sa.Column(sa.Boolean(), nullable=False, default=True)
 | 
					    enabled = sa.Column(sa.Boolean(), nullable=False, default=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue