summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-05-01 17:44:20 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-05-01 17:44:20 +0000
commit0b1e814f89afb560c5d1b3af7ddb2cd2f5f2ab88 (patch)
tree52be3167255e588068d345d0bd4fda8cdeb6e9df
parent220dea241c2ceac979ad7e668e20bf8fb4e2d22a (diff)
downloadbcfg2-0b1e814f89afb560c5d1b3af7ddb2cd2f5f2ab88.tar.gz
bcfg2-0b1e814f89afb560c5d1b3af7ddb2cd2f5f2ab88.tar.bz2
bcfg2-0b1e814f89afb560c5d1b3af7ddb2cd2f5f2ab88.zip
Replace bcfg2-query with bcfg2-admin query
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4582 ce84e21b-d406-0410-9b95-82705330c041
-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)