summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-02-17 03:29:02 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-02-17 03:29:02 +0000
commit6100d3b64b21fb0d31d1479785a69b20d74e8b31 (patch)
treed1afa302dbafc28136363937e1296e2f7aad02d9
parent65355e11b840687c6e1076fe5a7ce6d35d5de2fc (diff)
downloadbcfg2-6100d3b64b21fb0d31d1479785a69b20d74e8b31.tar.gz
bcfg2-6100d3b64b21fb0d31d1479785a69b20d74e8b31.tar.bz2
bcfg2-6100d3b64b21fb0d31d1479785a69b20d74e8b31.zip
Snapshots: put finishing touches on the model
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5080 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Snapshots/model.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/lib/Server/Snapshots/model.py b/src/lib/Server/Snapshots/model.py
index 4076bed9f..c15370162 100644
--- a/src/lib/Server/Snapshots/model.py
+++ b/src/lib/Server/Snapshots/model.py
@@ -4,11 +4,6 @@ import sqlalchemy.exceptions
from sqlalchemy.orm import relation, backref, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
-# TODO pingtime?
-# backlinks Client -> Snapshot
-# entry missing fields
-# extra entries
-
class Uniquer(object):
@classmethod
def by_value(cls, session, **kwargs):
@@ -35,6 +30,8 @@ class Client(Uniquer, Base):
name = Column(Unicode(64), unique=True)
admins = relation("Administrator", secondary=admin_client)
active = Column(Boolean, default=True)
+ online = Column(Boolean, default=True)
+ online_ts = Column(DateTime)
class Group(Uniquer, Base):
__tablename__ = 'group'
@@ -63,6 +60,7 @@ class Metadata(Base):
client = relation(Client)
groups = relation("Group", secondary=meta_group)
keyvals = relation(ConnectorKeyVal, secondary=meta_conn)
+ timestamp = Column(DateTime)
@classmethod
def from_metadata(cls, session, metadata):
@@ -147,6 +145,18 @@ file_snap = Table('file_snap', Base.metadata,
Column('fpair_id', Integer, ForeignKey('file_pair.id')),
Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+extra_pkg_snap = Table('extra_pkg_snap', Base.metadata,
+ Column('package_id', Integer, ForeignKey('package.id')),
+ Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
+extra_file_snap = Table('extra_file_snap', Base.metadata,
+ Column('file_id', Integer, ForeignKey('file.id')),
+ Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
+extra_service_snap = Table('extra_service_snap', Base.metadata,
+ Column('service_id', Integer, ForeignKey('service.id')),
+ Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class Action(Base):
__tablename__ = 'action'
id = Column(Integer, primary_key=True)
@@ -154,6 +164,10 @@ class Action(Base):
return_code = Column(Integer)
output = Column(UnicodeText)
+action_snap = Table('action_snap', Base.metadata,
+ Column('action_id', Integer, ForeignKey('action.id')),
+ Column('snapshot_id', Integer, ForeignKey('snapshot.id')))
+
class Snapshot(Base):
__tablename__ = 'snapshot'
id = Column(Integer, primary_key=True)
@@ -161,14 +175,19 @@ class Snapshot(Base):
client_metadata = relation(Metadata, primaryjoin=metadata_id==Metadata.id)
timestamp = Column(DateTime)
client_id = Column(Integer, ForeignKey('client.id'))
- client = relation(Client, backref=backref('snapshots', order_by=timestamp))
+ client = relation(Client, backref=backref('snapshots'))
packages = relation(PackageCorrespondence, secondary=package_snap)
services = relation(ServiceCorrespondence, secondary=service_snap)
files = relation(FileCorrespondence, secondary=file_snap)
-
-engine = create_engine('sqlite:///:memory:', echo=True)
-metadata = Base.metadata
-metadata.create_all(engine)
-Session = sessionmaker()
-Session.configure(bind=engine)
-session = Session()
+ actions = relation(Action, secondary=action_snap)
+ extra_packages = relation(Package, secondary=extra_pkg_snap)
+ extra_services = relation(Service, secondary=extra_service_snap)
+ extra_files = relation(File, secondary=extra_file_snap)
+
+if __name__ == '__main__':
+ engine = create_engine('sqlite:///:memory:', echo=True)
+ metadata = Base.metadata
+ metadata.create_all(engine)
+ Session = sessionmaker()
+ Session.configure(bind=engine)
+ session = Session()