from sqlalchemy.ext.sessioncontext import SessionContext
from sqlalchemy.ext.assignmapper import assign_mapper
+import datetime
+
from invirt.database import record
__all__ = ['meta',
'mirrors_table',
'autoinstalls_table',
'owners_table',
+ 'admins_table',
+ 'builds_table',
'Machine',
'MachineAccess',
'NIC',
'Mirror',
'Autoinstall',
'Owner',
+ 'Admin',
+ 'Build',
'or_',
]
machine_table = Table('machines', meta,
Column('machine_id', Integer, primary_key=True, nullable=False),
- Column('name', String, nullable=False),
+ Column('name', String, nullable=False, unique=True),
Column('description', String, nullable=False),
Column('memory', Integer, nullable=False),
Column('owner', String, nullable=False),
Column('vms_quota_total', Integer, nullable=True, default=None),
Column('vms_quota_active', Integer, nullable=True, default=None))
+builds_table = Table('builds', meta,
+ Column('build_id', Integer, primary_key=True, nullable=False),
+ Column('package', String, nullable=False),
+ Column('pocket', String, nullable=False),
+ Column('commit', String, nullable=False),
+ Column('version', String, nullable=True, default=None),
+ Column('principal', String, nullable=False),
+ Column('succeeded', Boolean, nullable=False),
+ Column('failed_stage', String, nullable=True, default=None),
+ Column('traceback', String, nullable=True, default=None),
+ Column('inserted_at', DateTime, nullable=False, default=datetime.datetime.utcnow))
+
machine_access_table = Table('machine_access', meta,
Column('machine_id', Integer, ForeignKey('machines.machine_id', ondelete='CASCADE'), nullable=False, index=True),
Column('user', String, nullable=False, index=True),
PrimaryKeyConstraint('machine_id', 'user'))
+admins_table = Table('admins', meta,
+ Column('user', String, nullable=False, index=True, primary_key=True))
+
class Machine(record.Record):
_identity_field = 'name'
class Autoinstall(record.Record):
_identity_field = 'autoinstall_id'
+class Admin(record.Record):
+ _identity_field = 'user'
+
+class Build(record.Record):
+ _identity_field = 'build_id'
+
from invirt.database.owner import Owner
session.mapper(Machine, machine_table,
properties={'mirror': relation(Mirror, backref="cdroms")})
session.mapper(Autoinstall, autoinstalls_table)
session.mapper(Owner, owners_table)
+session.mapper(Admin, admins_table)
+session.mapper(Build, builds_table)
def clear_cache():
"""Clear sqlalchemy's cache