summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Snapshots/model.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-03-06 21:13:08 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-03-06 21:13:08 +0000
commita738db564d19184b61d45fca3985dc285ee03ba8 (patch)
tree925ad2208ffc1cc790118a9e6bbc0aa8efd326c4 /src/lib/Server/Snapshots/model.py
parentd60154796408589b68350a34e25ee8d4efb03a78 (diff)
downloadbcfg2-a738db564d19184b61d45fca3985dc285ee03ba8.tar.gz
bcfg2-a738db564d19184b61d45fca3985dc285ee03ba8.tar.bz2
bcfg2-a738db564d19184b61d45fca3985dc285ee03ba8.zip
Snapshots: Add some convenience functions for getting access to latest snapshot
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5109 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Snapshots/model.py')
-rw-r--r--src/lib/Server/Snapshots/model.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lib/Server/Snapshots/model.py b/src/lib/Server/Snapshots/model.py
index ea9c6b811..a913a25de 100644
--- a/src/lib/Server/Snapshots/model.py
+++ b/src/lib/Server/Snapshots/model.py
@@ -1,4 +1,4 @@
-from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Boolean, DateTime, UnicodeText
+from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Boolean, DateTime, UnicodeText, desc
import datetime
import sqlalchemy.exceptions
from sqlalchemy.orm import relation, backref
@@ -232,3 +232,10 @@ class Snapshot(Base):
getattr(snap, dest).append(ecls.from_record(session, edata))
return snap
+ @classmethod
+ def by_client(cls, session, clientname):
+ return session.query(cls).join(cls.client_metadata, Metadata.client).filter(Client.name==clientname)
+
+ @classmethod
+ def get_current(cls, session, clientname):
+ return session.query(Snapshot).join(Snapshot.client_metadata, Metadata.client).filter(Client.name==clientname).order_by(desc(Snapshot.timestamp)).first()