From c4de45d84a95ec7e3b61780eae6a591885fc9bbf Mon Sep 17 00:00:00 2001 From: Andrew Brestick Date: Thu, 19 Jun 2008 15:11:06 +0000 Subject: Resolves ticket #541 and fixes client adding/deleting git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4701 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Admin/Query.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/lib/Server/Admin/Query.py') diff --git a/src/lib/Server/Admin/Query.py b/src/lib/Server/Admin/Query.py index 0c0659213..a5e2a977e 100644 --- a/src/lib/Server/Admin/Query.py +++ b/src/lib/Server/Admin/Query.py @@ -1,7 +1,7 @@ import Bcfg2.Server.Admin, Bcfg2.Logging, logging class Query(Bcfg2.Server.Admin.Mode): - __shorthelp__ = 'bcfg2-admin query [-n] [-c] g=group p=profile' + __shorthelp__ = 'bcfg2-admin query [-n] [-c] [-f filename] g=group p=profile' __longhelp__ = __shorthelp__ + '\n\tQuery clients' def __init__(self, cfile): logging.root.setLevel(100) @@ -22,9 +22,18 @@ class Query(Bcfg2.Server.Admin.Mode): def __call__(self, args): Bcfg2.Server.Admin.Mode.__call__(self, args) clients = self.meta.clients.keys() + filename_arg = False + filename = None for arg in args: + if filename_arg == True: + filename = arg + filename_arg = False + continue if arg in ['-n', '-c']: continue + if arg in ['-f']: + filename_arg = True + continue try: k, v = arg.split('=') except: @@ -37,9 +46,14 @@ class Query(Bcfg2.Server.Admin.Mode): self.meta.groups[self.meta.clients[c]][1] or v in self.meta.cgroups.get(c, [])] clients = [c for c in clients if c in nc] - if '-n' in args: for client in clients: print client else: print ','.join(clients) + if '-f' in args: + f = open(filename, "w") + for client in clients: + f.write(client + "\n") + f.close() + print "Wrote results to %s" % (filename) -- cgit v1.2.3-1-g7c22