diff options
-rw-r--r-- | doc/help/troubleshooting.txt | 1 | ||||
-rw-r--r-- | doc/server/bcfg2-info.txt | 6 | ||||
-rw-r--r-- | doc/server/plugins/structures/bundler/index.txt | 20 | ||||
-rwxr-xr-x | src/sbin/bcfg2-info | 26 |
4 files changed, 38 insertions, 15 deletions
diff --git a/doc/help/troubleshooting.txt b/doc/help/troubleshooting.txt index cb68a02c5..b0eeca33e 100644 --- a/doc/help/troubleshooting.txt +++ b/doc/help/troubleshooting.txt @@ -71,6 +71,7 @@ operations * groups - Current group metadata values * mappings - Configuration entries provided by plugins * buildfile <filename> <hostname> - Build a config file for a client +* buildbundle <bundle> <hostname> - Render a templated bundle for a client * showentries <client> <type> - Build the abstract configuration (list of entries) for a client * build <hostname> <output-file> - Build the complete configuration diff --git a/doc/server/bcfg2-info.txt b/doc/server/bcfg2-info.txt index 201900ba9..912cb73ab 100644 --- a/doc/server/bcfg2-info.txt +++ b/doc/server/bcfg2-info.txt @@ -92,6 +92,12 @@ commands. displays a list of entries (optionally filtered by type) that appear in a client's configuration specification +**buildbundle** + Render a single bundle template. This only performs the template + rendering step; it does not fully bind all entries in the + bundle. This command is very useful when developing bundle + templates. + **buildfile** Perform the entry binding process on a single entry, displaying its results. This command is very useful when developing diff --git a/doc/server/plugins/structures/bundler/index.txt b/doc/server/plugins/structures/bundler/index.txt index ad0c0c7f1..0cc2a0e55 100644 --- a/doc/server/plugins/structures/bundler/index.txt +++ b/doc/server/plugins/structures/bundler/index.txt @@ -169,24 +169,14 @@ has an additional `xmlns:py` attribute. See the examples. Troubleshooting --------------- -There is no :ref:`bcfg2-info <server-bcfg2-info>` command like -``buildfile`` for Bundler templates, so if you want to generate a -Bundler template for a given client, you have to do so manually by -first invoking ``bcfg2-info debug``, then run:: +To render a bundle for a given client, you can run:: - metadata = self.build_metadata("<hostname>") - path = "<full path to template file>" - from genshi.template import TemplateLoader, MarkupTemplate - template = TemplateLoader().load(path, cls=MarkupTemplate) - print template.generate(metadata=metadata).render('xml') + bcfg2-info buildbundle <bundle name> <hostname> -``path`` needs to be the full path to the template file on the -filesystem, not just within the Bcfg2 repo. +This will render the template; it will not fully bind all of the +entries in the bundle. -If you are making changes to your template and you want to tell your -filemonitor to process any pending changes, you can do the following:: - - self.fam.handle_events_in_interval(0.1) +See :ref:`bcfg2-info <server-bcfg2-info>` for more details. Altsrc ====== diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 951a5df58..1a5859cc3 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -24,6 +24,7 @@ import Bcfg2.Logger import Bcfg2.Options import Bcfg2.Server.Core import Bcfg2.Server.Plugins.Metadata +import Bcfg2.Server.Plugins.SGenshi import Bcfg2.Server.Plugin logger = logging.getLogger('bcfg2-info') @@ -32,6 +33,7 @@ build <hostname> <filename> - Build config for hostname, writing to filename builddir <hostname> <dirname> - Build config for hostname, writing separate files to dirname buildall <directory> - Build configs for all clients in directory buildfile <filename> <hostname> - Build config file for hostname (not written to disk) +buildbundle <bundle> <hostname> - Render a templated bundle for hostname (not written to disk) bundles - Print out group/bundle information clients - Print out client/profile information config - Print out the configuration of the Bcfg2 server @@ -272,6 +274,30 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): else: print('Usage: buildfile filename hostname') + def do_buildbundle(self, args): + """Render a bundle for client.""" + if len(args.split()) == 2: + bname, client = args.split() + try: + metadata = self.build_metadata(client) + if bname in self.plugins['Bundler'].entries: + bundle = self.plugins['Bundler'].entries[bname] + if isinstance(bundle, + Bcfg2.Server.Plugins.SGenshi.SGenshiTemplateFile): + stream = bundle.template.generate(metadata=metadata) + print(stream.render("xml")) + else: + print(bundle.data) + else: + print("No such bundle %s" % bname) + except: + err = sys.exc_info()[1] + print("Failed to render bundle %s for host %s: %s" % (bname, + client, + err)) + else: + print('Usage: buildfile filename hostname') + def do_bundles(self, _): """Print out group/bundle info.""" data = [('Group', 'Bundles')] |