diff options
Diffstat (limited to 'src/sbin/bcfg2-info')
-rwxr-xr-x | src/sbin/bcfg2-info | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index cfcc95be2..133e1ccb3 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -120,7 +120,6 @@ class InfoCore(cmd.Cmd, Bcfg2.Server.Core.BaseCore): Bcfg2.Server.Core.BaseCore.__init__(self, setup=setup) self.prompt = '> ' self.cont = True - self.fam.handle_events_in_interval(4) def _get_client_list(self, hostglobs): """ given a host glob, get a list of clients that match it """ @@ -232,10 +231,14 @@ class InfoCore(cmd.Cmd, Bcfg2.Server.Core.BaseCore): print("Refusing to write files outside of /tmp without -f " "option") return - lxml.etree.ElementTree(self.BuildConfiguration(client)).write( - ofile, - encoding='UTF-8', xml_declaration=True, - pretty_print=True) + try: + lxml.etree.ElementTree(self.BuildConfiguration(client)).write( + ofile, + encoding='UTF-8', xml_declaration=True, + pretty_print=True) + except IOError: + err = sys.exc_info()[1] + print("Failed to write File %s: %s" % (ofile, err)) else: print(self._get_usage(self.do_build)) @@ -380,7 +383,7 @@ Bcfg2 client itself.""") xml_declaration=False).decode('UTF-8') except Exception: print("Failed to build entry %s for host %s: %s" % - (fname, client, traceback.format_exc().splitlines()[-1])) + (fname, client, traceback.format_exc().splitlines()[-1])) raise try: if outfile: @@ -458,9 +461,7 @@ Bcfg2 client itself.""") def do_clients(self, _): """ clients - Print out client/profile info """ data = [('Client', 'Profile')] - clist = self.metadata.clients - clist.sort() - for client in clist: + for client in sorted(self.metadata.list_clients()): imd = self.metadata.get_initial_metadata(client) data.append((client, imd.profile)) print_tabular(data) @@ -468,19 +469,17 @@ Bcfg2 client itself.""") def do_config(self, _): """ config - Print out the current configuration of Bcfg2""" output = [ - ('Description', 'Value'), - ('Path Bcfg2 repository', self.setup['repo']), - ('Plugins', self.setup['plugins']), - ('Password', self.setup['password']), - ('Server Metadata Connector', self.setup['mconnect']), - ('Filemonitor', self.setup['filemonitor']), - ('Server address', self.setup['location']), - ('Path to key', self.setup['key']), - ('Path to SSL certificate', self.setup['cert']), - ('Path to SSL CA certificate', self.setup['ca']), - ('Protocol', self.setup['protocol']), - ('Logging', self.setup['logging']) - ] + ('Description', 'Value'), + ('Path Bcfg2 repository', self.setup['repo']), + ('Plugins', self.setup['plugins']), + ('Password', self.setup['password']), + ('Filemonitor', self.setup['filemonitor']), + ('Server address', self.setup['location']), + ('Path to key', self.setup['key']), + ('Path to SSL certificate', self.setup['cert']), + ('Path to SSL CA certificate', self.setup['ca']), + ('Protocol', self.setup['protocol']), + ('Logging', self.setup['logging'])] print_tabular(output) def do_probes(self, args): @@ -607,7 +606,7 @@ Bcfg2 client itself.""") # Dump all mappings unless type specified data = [('Plugin', 'Type', 'Name')] arglen = len(args.split()) - for generator in self.generators: + for generator in self.plugins_by_type(Bcfg2.Server.Plugin.Generator): if arglen == 0: etypes = list(generator.Entries.keys()) else: @@ -631,30 +630,34 @@ Bcfg2 client itself.""") self.fam.debug = True def do_packageresolve(self, args): - """ packageresolve <hostname> <package> [<package>...] - - Resolve the specified set of packages """ + """ packageresolve <hostname> [<package> [<package>...]] - + Resolve packages for the given host, optionally specifying a + set of packages """ arglist = args.split(" ") - if len(arglist) < 2: + if len(arglist) < 1: print(self._get_usage(self.do_packageresolve)) return - if 'Packages' not in self.plugins: + try: + pkgs = self.plugins['Packages'] + except KeyError: print("Packages plugin not enabled") return - self.plugins['Packages'].toggle_debug() - - indep = lxml.etree.Element("Independent") - structures = [lxml.etree.Element("Bundle", name="packages")] - for arg in arglist[1:]: - lxml.etree.SubElement(structures[0], "Package", name=arg) + pkgs.toggle_debug() hostname = arglist[0] metadata = self.build_metadata(hostname) - # pylint: disable=W0212 - self.plugins['Packages']._build_packages(metadata, indep, structures) - # pylint: enable=W0212 + indep = lxml.etree.Element("Independent") + if len(arglist) > 1: + structures = [lxml.etree.Element("Bundle", name="packages")] + for arg in arglist[1:]: + lxml.etree.SubElement(structures[0], "Package", name=arg) + else: + structures = self.GetStructures(metadata) + pkgs._build_packages(metadata, indep, # pylint: disable=W0212 + structures) print("%d new packages added" % len(indep.getchildren())) if len(indep.getchildren()): print(" %s" % "\n ".join(lxml.etree.tostring(p) @@ -713,6 +716,8 @@ Bcfg2 client itself.""") def run(self, args): # pylint: disable=W0221 try: + self.load_plugins() + self.fam.handle_events_in_interval(1) if args: self.onecmd(" ".join(args)) else: @@ -739,7 +744,7 @@ def build_usage(): # shim for python 2.4, __func__ is im_func funcattr = getattr(attr, "__func__", getattr(attr, "im_func", None)) - if (funcattr != None and + if (funcattr is not None and funcattr.func_name not in cmd_blacklist and funcattr.func_name.startswith("do_") and funcattr.func_doc): @@ -754,8 +759,7 @@ def main(): optinfo = dict(profile=Bcfg2.Options.CORE_PROFILE, interactive=Bcfg2.Options.INTERACTIVE, interpreter=Bcfg2.Options.INTERPRETER) - optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS) - optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS) + optinfo.update(Bcfg2.Options.INFO_COMMON_OPTIONS) setup = Bcfg2.Options.OptionParser(optinfo) setup.hm = "\n".join([" bcfg2-info [options] [command <command args>]", "Options:", |