summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/bcfg2-query.849
-rw-r--r--src/lib/Server/Admin/Query.py27
-rwxr-xr-xsrc/sbin/bcfg2-query49
3 files changed, 17 insertions, 108 deletions
diff --git a/man/bcfg2-query.8 b/man/bcfg2-query.8
deleted file mode 100644
index a306ba049..000000000
--- a/man/bcfg2-query.8
+++ /dev/null
@@ -1,49 +0,0 @@
-.TH "bcfg2-query" 8
-.SH NAME
-bcfg2-query \- Print client names by characteristic
-.SH SYNOPSIS
-.B bcfg2-query
-.I [\-g group]
-.I [\-p profile]
-.I [\-a]
-
-.SH DESCRIPTION
-.PP
-.B bcfg2-query
-bcfg2-query produces streams of newline delimited client names based
-on client characteristics.
-.SH OPTIONS
-.PP
-.B "\-a"
-.RS
-Display all clients
-.RE
-.B "\-c"
-.RS
-Displays nodes in a comma delimited list
-.RE
-.B "\-s"
-.RS
-Display nodes in a space delimited list
-.RE
-.B "\-n"
-.RS
-Display nodes in a newline delimited list
-.RE
-.B "\-v"
-.RS
-Turns on debugging
-.RE
-.B "\-p <profile>"
-.RS
-Display all clients that are a part of the specified profile
-.RE
-.B "\-g <group>"
-.RS
-Display all clients that are members of the specified group
-.RE
-.SH "SEE ALSO"
-.BR bcfg2(1),
-.BR bcfg2-server(8)
-.SH "BUGS"
-None currently known
diff --git a/src/lib/Server/Admin/Query.py b/src/lib/Server/Admin/Query.py
index 6d37f6371..0c0659213 100644
--- a/src/lib/Server/Admin/Query.py
+++ b/src/lib/Server/Admin/Query.py
@@ -1,8 +1,8 @@
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'
+ __shorthelp__ = 'bcfg2-admin query [-n] [-c] g=group p=profile'
+ __longhelp__ = __shorthelp__ + '\n\tQuery clients'
def __init__(self, cfile):
logging.root.setLevel(100)
Bcfg2.Logging.setup_logging(100, to_console=False, to_syslog=False)
@@ -21,18 +21,25 @@ class Query(Bcfg2.Server.Admin.Mode):
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
- clients = None
+ clients = self.meta.clients.keys()
for arg in args:
- k, v = arg.split('=')
+ if arg in ['-n', '-c']:
+ continue
+ try:
+ k, v = arg.split('=')
+ except:
+ print "Unknown argument %s" % arg
+ continue
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)
+ clients = [c for c in clients if c in nc]
+
+ if '-n' in args:
+ for client in clients:
+ print client
+ else:
+ print ','.join(clients)
diff --git a/src/sbin/bcfg2-query b/src/sbin/bcfg2-query
deleted file mode 100755
index 61fd37aee..000000000
--- a/src/sbin/bcfg2-query
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/python
-
-import Bcfg2.Server.Core, Bcfg2.Logging
-import lxml.etree, sys, ConfigParser, time
-
-if __name__ == "__main__":
- CP = ConfigParser.ConfigParser()
- CP.read(['/etc/bcfg2.conf'])
- try:
- prefix = CP.get('server', 'repository')
- except:
- prefix = "/var/lib/bcfg2"
-
- if len(sys.argv) < 2:
- print "Usage bcfg2-query -a|-c|-s|-n|-g <group name> -p <profile name>"
- print "\t -a\t\t shows all clients"
- print "\t -c\t\t prints node names in a comma delimited list"
- print "\t -s\t\t prints node names in a space delimited list"
- print "\t -n\t\t prints node names in a newline delimited list (default)"
- print "\t -v\t\t turn on debugging messages"
- print "\t -g <group name>\t shows all the clients that are members of that group"
- print "\t -p <profile name>\t shows all the clients of that profile"
- sys.exit(1)
-
- ''' Create the metadata object '''
- bcore = Bcfg2.Server.Core.Core('%s'%prefix, [], ['Metadata'], None, False)
- while(bcore.fam.Service()):
- time.sleep(1)
- mdata = bcore.plugins['Metadata']
-
- ''' Turn on debugging '''
- if '-v' in sys.argv:
- Bcfg2.Logging.setup_logging(0, to_console=True)
-
- if '-a' in sys.argv:
- cnames = [key for key in mdata.clients.keys()]
- elif '-g' in sys.argv:
- group = sys.argv[sys.argv.index('-g') + 1]
- cnames = mdata.GetClientByGroup('%s' % group)
- elif '-p' in sys.argv:
- profile = sys.argv[sys.argv.index('-p') + 1]
- cnames = mdata.GetClientByProfile('%s' % profile)
-
- if '-c' in sys.argv:
- print ",".join(cnames)
- elif '-s' in sys.argv:
- print " ".join(cnames)
- else:
- print "\n".join(cnames)