diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-03-06 21:13:08 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-03-06 21:13:08 +0000 |
commit | a738db564d19184b61d45fca3985dc285ee03ba8 (patch) | |
tree | 925ad2208ffc1cc790118a9e6bbc0aa8efd326c4 /src | |
parent | d60154796408589b68350a34e25ee8d4efb03a78 (diff) | |
download | bcfg2-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')
-rw-r--r-- | src/lib/Server/Admin/Snapshots.py | 10 | ||||
-rw-r--r-- | src/lib/Server/Snapshots/model.py | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/lib/Server/Admin/Snapshots.py b/src/lib/Server/Admin/Snapshots.py index fc3334c11..13897fcd2 100644 --- a/src/lib/Server/Admin/Snapshots.py +++ b/src/lib/Server/Admin/Snapshots.py @@ -2,15 +2,16 @@ import Bcfg2.Server.Admin import sqlalchemy, sqlalchemy.orm import Bcfg2.Server.Snapshots import Bcfg2.Server.Snapshots.model +from Bcfg2.Server.Snapshots.model import Snapshot, Client, Metadata, Base, Group class Snapshots(Bcfg2.Server.Admin.Mode): __shorthelp__ = "Interact with the Snapshots system" __longhelp__ = (__shorthelp__) __usage__ = ("bcfg2-admin snapshots [init|query qtype] ") - q_dispatch = {'client':Bcfg2.Server.Snapshots.model.Client, + q_dispatch = {'client':Client, 'group':Bcfg2.Server.Snapshots.model.Group, - 'snapshot':Bcfg2.Server.Snapshots.model.Snapshot, + 'snapshot':Snapshot, } def __init__(self, configfile): @@ -30,9 +31,12 @@ class Snapshots(Bcfg2.Server.Admin.Mode): elif args[0] == 'init': dbpath = Bcfg2.Server.Snapshots.db_from_config() engine = sqlalchemy.create_engine(dbpath, echo=True) - metadata = Bcfg2.Server.Snapshots.model.Base.metadata + metadata = Base.metadata metadata.create_all(engine) Session = sqlalchemy.orm.sessionmaker() Session.configure(bind=engine) session = Session() session.commit() + elif args[0] == 'dump': + client, etype, ename = args[1:] + snap = Snapshot.get_current(self.session, client) 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() |