From 5340852fbedc95c120aba3c7fcaddaf8b4a919c6 Mon Sep 17 00:00:00 2001 From: Andrew Brestick Date: Thu, 26 Jun 2008 16:37:15 +0000 Subject: Completed bcfg2-admin minestruct mode git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4718 ce84e21b-d406-0410-9b95-82705330c041 --- man/bcfg2-admin.8 | 12 ++++++- src/lib/Server/Admin/Minestruct.py | 72 +++++++++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/man/bcfg2-admin.8 b/man/bcfg2-admin.8 index 5762de59b..c25c14e1c 100644 --- a/man/bcfg2-admin.8 +++ b/man/bcfg2-admin.8 @@ -4,8 +4,10 @@ bcfg2-admin \- Perform repository administration tasks .SH SYNOPSIS .B bcfg2-admin .I init +.I client +.I query [g=group] [p=profile] [-f output-file] [-n] [-c] .I compare -.I minestruct +.I minestruct [-g groups] [-f output-file] .I pull .I tidy .I viz [-h] [-b] [-k] [-o output.png] [-r] @@ -20,6 +22,14 @@ Perform bcfg2 repository administration .RS Initialize a new repository (interactive) .RE +.B client +.RS +Add or remove clients from metadata +.RE +.B query +.RS +Search for clients based on group or profile +.RE .B compare .RS Compare two client configurations. Can be used to verify consistent diff --git a/src/lib/Server/Admin/Minestruct.py b/src/lib/Server/Admin/Minestruct.py index 9e91ff33e..61a277d2d 100644 --- a/src/lib/Server/Admin/Minestruct.py +++ b/src/lib/Server/Admin/Minestruct.py @@ -1,29 +1,77 @@ +'''Minestruct Admin Mode''' import Bcfg2.Server.Admin +import lxml.etree class Minestruct(Bcfg2.Server.Admin.Mode): '''Pull extra entries out of statistics''' - __shorthelp__ = 'bcfg2-admin minestruct ' + __shorthelp__ = 'bcfg2-admin minestruct [-f file-name] [-g groups]' __longhelp__ = __shorthelp__ + '\n\tExtract extra entry lists from statistics' def __init__(self, cfile): - Bcfg2.Server.Admin.Mode.__init__(self, cfile) + Bcfg2.Server.Admin.Mode.__init__(self, cfile) def __call__(self, args): Bcfg2.Server.Admin.Mode.__call__(self, args) - if len(args) != 1: - self.errExit("minestruct must be called with a client name") - extra = self.MineStruct(args[0]) - self.log.info("Found %d extra entries" % (len(extra))) - self.log.info(["%s: %s" % (entry.tag, entry.get('name')) for entry in extra]) - - def MineStruct(self, client): - '''Pull client entries into structure''' + if len(args) == 0: + self.errExit("No hostname specified (see bcfg2-admin minestruct -h for help)") + if "-h" in args: + print "Usage:" + print self.__shorthelp__ + raise SystemExit(1) + write_to_file = False + file_arg = False + output_file = None + client = None + groups_arg = False + groups = [] + for arg in args: + if arg == "-f": + file_arg = True + groups_arg = False + continue + elif arg == "-g": + groups_arg = True + file_arg = False + continue + elif file_arg == True: + output_file = arg + file_arg = False + write_to_file = True + continue + elif groups_arg == True: + groups.append(arg) + continue + else: + client = arg stats = self.load_stats(client) if len(stats.getchildren()) == 2: - # FIXME this is busted # client is dirty current = [ent for ent in stats.getchildren() if ent.get('state') == 'dirty'][0] else: current = stats.getchildren()[0] - return current.find('Extra').getchildren() + extra = current.find('Extra').getchildren() + root = lxml.etree.Element("Base") + self.log.info("Found %d extra entries" % (len(extra))) + if len(groups) == 0: + for entry in extra: + self.log.info("%s: %s" % (entry.tag, entry.get('name'))) + root.append(lxml.etree.Element(entry.tag, name=entry.get('name'))) + else: + groups_root = lxml.etree.Element("Group", name=groups[0]) + root.append(groups_root) + for i in range (1, len(groups)): + temp = lxml.etree.Element("Group", name=groups[i]) + groups_root.append(temp) + groups_root = temp + for entry in extra: + self.log.info("%s: %s" % (entry.tag, entry.get('name'))) + groups_root.append(lxml.etree.Element(entry.tag, name=entry.get('name'))) + tree = lxml.etree.ElementTree(root) + if write_to_file == True: + try: + f = open(output_file, 'w') + except IOError: + self.log.info("Failed to write to file: %s" % (output_file)) + raise SystemExit(1) + tree.write(f) -- cgit v1.2.3-1-g7c22