diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-03-25 21:04:04 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-03-25 21:04:04 +0000 |
commit | e1fd3dc8fc34a8d96d354ae5d7057d6de39a26ab (patch) | |
tree | b88235a6cdf2f5bf01cb14f88672a8ca2094e0e1 /src/lib/Server/Admin/Snapshots.py | |
parent | cc21ed6297d51505852d19fb44abd3c7ea66f04c (diff) | |
download | bcfg2-e1fd3dc8fc34a8d96d354ae5d7057d6de39a26ab.tar.gz bcfg2-e1fd3dc8fc34a8d96d354ae5d7057d6de39a26ab.tar.bz2 bcfg2-e1fd3dc8fc34a8d96d354ae5d7057d6de39a26ab.zip |
Snapshots: implement rudimentary reports cmd line interface (partially from SolJ)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5142 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/Snapshots.py')
-rw-r--r-- | src/lib/Server/Admin/Snapshots.py | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/src/lib/Server/Admin/Snapshots.py b/src/lib/Server/Admin/Snapshots.py index 51b7bf6d9..5c1b5215b 100644 --- a/src/lib/Server/Admin/Snapshots.py +++ b/src/lib/Server/Admin/Snapshots.py @@ -14,42 +14,75 @@ from Bcfg2.Server.Snapshots.model import Snapshot, Client, Metadata, Base, \ class Snapshots(Bcfg2.Server.Admin.Mode): __shorthelp__ = "Interact with the Snapshots system" __longhelp__ = (__shorthelp__) - __usage__ = ("bcfg2-admin snapshots [init|query qtype] ") + __usage__ = ("bcfg2-admin snapshots [init|query qtype]") - q_dispatch = {'client':Client, 'group':Group, - 'snapshot':Snapshot,'package': Package, 'metadata':Metadata, - } + q_dispatch = {'client':Client, + 'group':Group, + 'metadata':Metadata, + 'package':Package, + 'snapshot':Snapshot} def __init__(self, configfile): Bcfg2.Server.Admin.Mode.__init__(self, configfile) - self.session = Bcfg2.Server.Snapshots.setup_session(debug=True) + #self.session = Bcfg2.Server.Snapshots.setup_session(debug=True) + self.session = Bcfg2.Server.Snapshots.setup_session() def __call__(self, args): + Bcfg2.Server.Admin.Mode.__call__(self, args) + if len(args) == 0 or args[0] == '-h': + print(self.__usage__) + raise SystemExit(0) + if args[0] == 'query': if args[1] in self.q_dispatch: q_obj = self.q_dispatch[args[1]] - results = self.session.query(q_obj).all() + if q_obj == Client: + print("\nInactive hosts:") + for host in self.session.query(q_obj).filter(q_obj.active == False): + print(" %s" % host.name) + print("\nActive hosts:") + for host in self.session.query(q_obj).filter(q_obj.active == True): + print(" %s" % host.name) + else: + results = self.session.query(q_obj).all() else: print 'error' raise SystemExit, 1 - for result in results: - print result.name elif args[0] == 'init': dbpath = Bcfg2.Server.Snapshots.db_from_config() engine = sqlalchemy.create_engine(dbpath, echo=True) metadata = Base.metadata - metadata.create_all(engine) + 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:] + client = args[1] snap = Snapshot.get_current(self.session, unicode(client)) if not snap: - print "Current snapshot for %s not found" % client + print("Current snapshot for %s not found" % client) sys.exit(1) + print("Client %s last run at %s" % (client, snap.timestamp)) for pkg in snap.packages: - print pkg.correct, pkg.modified - print pkg.start.name, pkg.start.version - print snap.packages + print "C:", pkg.correct, 'M:', pkg.modified + print "start", pkg.start.name, pkg.start.version + print "end", pkg.end.name, pkg.end.version + #print("\nExtra packages:") + #for pkg in snap.extra_packages: + # print(" %s" % pkg.name) + #print("\nExtra services:") + #for svc in snap.extra_services: + # print(" %s" % svc.name) + elif args[0] == 'reports': + if '-a' in args[1:]: + q = self.session.query(Client.name, + Snapshot.correct, + Snapshot.timestamp).filter(Client.id==Snapshot.client_id)\ + .group_by(Client.id) + print "Client\tCorrect\tTime" + print 60* '=' + for item in q.all(): + print "%s\t%s\t%s" % (item) + else: + print "Unknown options: ", args[1:] |