From fa25b112ec93f96eee47e7522047bafe29d2e92f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 12 Sep 2012 16:53:53 -0400 Subject: bcfg2-info: added "automatch" command to perform Properties automatching --- doc/server/plugins/connectors/properties.txt | 11 ++++++++ src/lib/Bcfg2/Server/Plugins/Properties.py | 5 ++-- src/sbin/bcfg2-info | 38 ++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/doc/server/plugins/connectors/properties.txt b/doc/server/plugins/connectors/properties.txt index b56c2a488..b1f92c3d2 100644 --- a/doc/server/plugins/connectors/properties.txt +++ b/doc/server/plugins/connectors/properties.txt @@ -116,6 +116,17 @@ simply:: You can also enable automatch for individual Property files by setting the attribute ``automatch="true"`` in the top-level ```` tag. +If you want to see what ``XMLMatch()``/automatch would produce for a +given client on a given Properties file, you can use :ref:`bcfg2-info +`:: + + bcfg2-info automatch props.xml foo.example.com + +If automatch is not enabled, you can force ``bcfg2-info`` to perform +it anyway with ``-f``:: + + bcfg2-info automatch -f props.xml foo.example.com + .. _server-plugins-connectors-properties-write-back: Writing to Properties files diff --git a/src/lib/Bcfg2/Server/Plugins/Properties.py b/src/lib/Bcfg2/Server/Plugins/Properties.py index 49500e915..5b48a2b8f 100644 --- a/src/lib/Bcfg2/Server/Plugins/Properties.py +++ b/src/lib/Bcfg2/Server/Plugins/Properties.py @@ -16,6 +16,7 @@ logger = logging.getLogger(__name__) SETUP = None + class PropertyFile(Bcfg2.Server.Plugin.StructFile): """Class for properties files.""" def write(self): @@ -124,11 +125,11 @@ class Properties(Bcfg2.Server.Plugin.Plugin, SETUP = core.setup def get_additional_data(self, metadata): - autowatch = self.core.setup.cfp.getboolean("properties", "automatch", + automatch = self.core.setup.cfp.getboolean("properties", "automatch", default=False) rv = dict() for fname, pfile in self.store.entries.items(): - if (autowatch or + if (automatch or pfile.xdata.get("automatch", "false").lower() == "true"): rv[fname] = pfile.XMLMatch(metadata) else: diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 9ee02fd71..4725e05a3 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -42,6 +42,7 @@ buildall [] - Build configs for all clients in directory buildallfile [] - Build config file for all clients in directory buildfile - Build config file for hostname (not written to disk) buildbundle - Render a templated bundle for hostname (not written to disk) +automatch - Perform automatch on a Properties file bundles - Print out group/bundle information clients - Print out client/profile information config - Print out the configuration of the Bcfg2 server @@ -427,6 +428,43 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.BaseCore): else: print('Usage: buildbundle filename hostname') + def do_automatch(self, args): + alist = args.split() + force = False + for arg in alist: + if arg == '-f': + alist.remove('-f') + force = True + if len(alist) != 2: + print("Usage: automatch [-f] ") + return + + if 'Properties' not in self.plugins: + print("Properties plugin not enabled") + return + + pname, client = alist + try: + automatch = self.core.setup.cfp.getboolean("properties", + "automatch", + default=False) + + pfile = self.plugins['Properties'].store.entries[pname] + if (not force and + not automatch and + pfile.xdata.get("automatch", "false").lower() != "true"): + print("Automatch not enabled on %s" % pname) + else: + metadata = self.build_metadata(client) + print(lxml.etree.tostring(pfile.XMLMatch(metadata), + xml_declaration=False, + pretty_print=True).decode('UTF-8')) + except: + err = sys.exc_info()[1] + print("Failed to automatch %s for host %s: %s" % (pname, + client, + err)) + def do_bundles(self, _): """Print out group/bundle info.""" data = [('Group', 'Bundles')] -- cgit v1.2.3-1-g7c22