X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-database.git/blobdiff_plain/76dd52dcc0e221aa2ffcf3f4ce874ed9a3130ae1..8ff8bfe4ba94dd1ed0a89a06d528c1b48072f2dd:/python/database/models.py diff --git a/python/database/models.py b/python/database/models.py index f93557c..420c1ae 100644 --- a/python/database/models.py +++ b/python/database/models.py @@ -5,7 +5,7 @@ from sqlalchemy.orm import create_session, relation from sqlalchemy.ext.sessioncontext import SessionContext from sqlalchemy.ext.assignmapper import assign_mapper -from owner import Owner +from invirt.database import record __all__ = ['meta', 'session', @@ -52,7 +52,8 @@ nic_table = Table('nics', meta, Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=True), Column('mac_addr', String, nullable=False, primary_key=True), Column('ip', String, nullable=False, unique=True), - Column('hostname', String, nullable=True)) + Column('hostname', String, nullable=True), + Column('reusable', Boolean, nullable=False, default=True)) disk_table = Table('disks', meta, Column('machine_id', Integer, ForeignKey('machines.machine_id'), nullable=False), @@ -100,37 +101,31 @@ machine_access_table = Table('machine_access', meta, Column('user', String, nullable=False, index=True), PrimaryKeyConstraint('machine_id', 'user')) -class Machine(object): - def __repr__(self): - return "" % (self.machine_id, self.name, self.owner) +class Machine(record.Record): + _identity_field = 'name' -class MachineAccess(object): - def __repr__(self): - return "" % (self.machine, self.user) +class MachineAccess(record.Record): + pass -class NIC(object): - def __repr__(self): - return "" % (self.mac_addr, self.machine_id, self.ip, self.hostname) +class NIC(record.Record): + pass -class Disk(object): - def __repr__(self): - return "" % (self.machine_id, self.guest_device_name, self.size) +class Disk(record.Record): + pass -class Type(object): - def __repr__(self): - return "" % (self.type_id, self.description) +class Type(record.Record): + _identity_field = 'type_id' -class Mirror(object): - def __repr__(self): - return "" % (self.mirror_id) +class Mirror(record.Record): + _identity_field = 'mirror_id' -class CDROM(object): - def __repr__(self): - return "" % (self.cdrom_id, self.description) +class CDROM(record.Record): + _identity_field = 'cdrom_id' -class Autoinstall(object): - def __repr__(self): - return "" % (self.autoinstall_id, self.description, self.type.type_id) +class Autoinstall(record.Record): + _identity_field = 'autoinstall_id' + +from invirt.database.owner import Owner session.mapper(Machine, machine_table, properties={'nics': relation(NIC, backref="machine"),