From af4158afe15a3dc2ce1d98b80836e130b00eac81 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 12 Oct 2012 13:43:02 -0400 Subject: bcfg2-info: added probes subcommand to list probes for a client --- src/sbin/bcfg2-info | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src/sbin/bcfg2-info') diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index d16048df0..16e1e8ca1 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -212,8 +212,7 @@ class InfoCore(cmd.Cmd, Bcfg2.Server.Core.BaseCore): def do_quit(self, _): """ quit|exit - Exit program """ - for plugin in list(self.plugins.values()): - plugin.shutdown() + self.shutdown() os._exit(0) # pylint: disable=W0212 do_EOF = do_quit @@ -497,6 +496,42 @@ Bcfg2 client itself.""") ] print_tabular(output) + def do_probes(self, args): + """ probes [-p] - Get probe list for the given + host, in XML (the default) or human-readable pretty (with -p) + format""" + alist = args.split() + pretty = False + if '-p' in alist: + pretty = True + alist.remove('-p') + if len(alist) != 1: + print 'alist=%s' % alist + print(self._get_usage(self.do_probes)) + return + hostname = alist[0] + if pretty: + probes = [] + else: + probes = lxml.etree.Element('probes') + metadata = self.build_metadata(hostname) + for plugin in self.plugins_by_type(Bcfg2.Server.Plugin.Probing): + for probe in plugin.GetProbes(metadata): + probes.append(probe) + if pretty: + for probe in probes: + pname = probe.get("name") + print("=" * (len(pname) + 2)) + print(" %s" % pname) + print("=" * (len(pname) + 2)) + print("") + print(probe.text) + print("") + else: + print(lxml.etree.tostring(probes, + xml_declaration=False, + pretty_print=True).decode('UTF-8')) + def do_showentries(self, args): """ showentries - Show abstract configuration entries for a given host """ @@ -666,10 +701,13 @@ Bcfg2 client itself.""") display_trace(prof) def run(self, args): # pylint: disable=W0221 - if args: - self.onecmd(" ".join(args)) - else: - self.do_loop() + try: + if args: + self.onecmd(" ".join(args)) + else: + self.do_loop() + finally: + self.shutdown() def _daemonize(self): pass -- cgit v1.2.3-1-g7c22