diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2008-04-30 20:28:00 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2008-04-30 20:28:00 +0000 |
commit | 220dea241c2ceac979ad7e668e20bf8fb4e2d22a (patch) | |
tree | 4184740ecb05d6c33512ff82f99e2f683dbdd5ad | |
parent | 966fb755dfa55b1f6b5e395607d5680f7daf83fe (diff) | |
download | bcfg2-220dea241c2ceac979ad7e668e20bf8fb4e2d22a.tar.gz bcfg2-220dea241c2ceac979ad7e668e20bf8fb4e2d22a.tar.bz2 bcfg2-220dea241c2ceac979ad7e668e20bf8fb4e2d22a.zip |
Initial bcfg2-admin query implementation
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4576 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r-- | src/lib/Server/Admin/Query.py | 38 | ||||
-rw-r--r-- | src/lib/Server/Admin/__init__.py | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/Server/Admin/Query.py b/src/lib/Server/Admin/Query.py new file mode 100644 index 000000000..6d37f6371 --- /dev/null +++ b/src/lib/Server/Admin/Query.py @@ -0,0 +1,38 @@ +import Bcfg2.Server.Admin, Bcfg2.Logging, logging + +class Query(Bcfg2.Server.Admin.Mode): + __shorthelp__ = 'bcfg2-admin query <pattern>' + __longhelp__ = __shorthelp__ + '\n\tCreate or delete client entries' + def __init__(self, cfile): + logging.root.setLevel(100) + Bcfg2.Logging.setup_logging(100, to_console=False, to_syslog=False) + Bcfg2.Server.Admin.Mode.__init__(self, cfile) + try: + self.bcore = Bcfg2.Server.Core.Core(self.get_repo_path(), + [], ['Metadata'], + 'foo', False) + except Bcfg2.Server.Core.CoreInitError, msg: + self.errExit("Core load failed because %s" % msg) + [self.bcore.fam.Service() for _ in range(1)] + self.meta = self.bcore.metadata + self.meta.load_probedata() + while self.bcore.fam.Service(): + pass + + def __call__(self, args): + Bcfg2.Server.Admin.Mode.__call__(self, args) + clients = None + for arg in args: + k, v = arg.split('=') + if k == 'p': + nc = [c for c, p in self.meta.clients.iteritems() if p == v] + elif k == 'g': + nc = [c for c in self.meta.clients if v in + self.meta.groups[self.meta.clients[c]][1] or + v in self.meta.cgroups.get(c, [])] + if clients == None: + clients = nc + else: + clients = [c for c in clients if c in nc] + + print ','.join(clients) diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py index 39d0655c0..cff9eec6a 100644 --- a/src/lib/Server/Admin/__init__.py +++ b/src/lib/Server/Admin/__init__.py @@ -1,7 +1,7 @@ __revision__ = '$Revision$' __all__ = ['Mode', 'Client', 'Compare', 'Fingerprint', 'Init', 'Minestruct', - 'Pull', 'Tidy', 'Viz'] + 'Pull', 'Query', 'Tidy', 'Viz'] import ConfigParser, lxml.etree, logging |