summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-query
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbin/bcfg2-query')
-rwxr-xr-xsrc/sbin/bcfg2-query76
1 files changed, 42 insertions, 34 deletions
diff --git a/src/sbin/bcfg2-query b/src/sbin/bcfg2-query
index 3f0209192..61fd37aee 100755
--- a/src/sbin/bcfg2-query
+++ b/src/sbin/bcfg2-query
@@ -1,41 +1,49 @@
#!/usr/bin/python
-import lxml.etree, sys, ConfigParser
+import Bcfg2.Server.Core, Bcfg2.Logging
+import lxml.etree, sys, ConfigParser, time
-CP = ConfigParser.ConfigParser()
-CP.read(['/etc/bcfg2.conf'])
-try:
- prefix = CP.get('server', 'repository')
-except:
- prefix = "/var/lib/bcfg2"
+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 -d|u|p <profile name>"
- print "\t -d\t\t shows the clients that are currently down"
- print "\t -u\t\t shows the clients that are currently up"
- 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 -p <profile name>\t shows all the clients of that profile"
- print "\t -a\t shows all clients"
- sys.exit(1)
+ 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)
-xml = lxml.etree.parse('%s/Metadata/clients.xml'%prefix)
-if '-p' in sys.argv:
- profile = sys.argv[sys.argv.index('-p') + 1]
- clients = xml.xpath(".//Client[@profile='%s']" % (profile))
-elif '-d' in sys.argv:
- clients = xml.xpath(".//Client[@pingable='N']")
-elif '-u' in sys.argv:
- clients = xml.xpath(".//Client[@pingable='Y']")
-elif '-a' in sys.argv:
- clients = xml.xpath(".//Client")
+ ''' 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']
-cnames = [client.get('name') for client in clients]
-if '-c' in sys.argv:
- print ",".join(cnames)
-elif '-s' in sys.argv:
- print " ".join(cnames)
-else:
- print "\n".join(cnames)
+ ''' 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)