summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2011-08-18 12:06:54 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2011-08-18 12:06:54 -0400
commit81e936424b9f2a9ada20a83ca9353b5c0609b28c (patch)
treedddd0f57343eea8ccf5aa6108e79d709564a2743
parent8289840bf162f079de678abca5144f97bf491c13 (diff)
downloadbcfg2-81e936424b9f2a9ada20a83ca9353b5c0609b28c.tar.gz
bcfg2-81e936424b9f2a9ada20a83ca9353b5c0609b28c.tar.bz2
bcfg2-81e936424b9f2a9ada20a83ca9353b5c0609b28c.zip
added --altsrc flag to bcfg2-info buildfile
-rw-r--r--doc/help/troubleshooting.txt3
-rw-r--r--doc/server/plugins/generators/tgenshi/index.txt23
-rw-r--r--man/bcfg2-info.82
-rwxr-xr-xsrc/sbin/bcfg2-info17
4 files changed, 29 insertions, 16 deletions
diff --git a/doc/help/troubleshooting.txt b/doc/help/troubleshooting.txt
index b0eeca33e..7aeb0f247 100644
--- a/doc/help/troubleshooting.txt
+++ b/doc/help/troubleshooting.txt
@@ -70,7 +70,8 @@ operations
* clients - Current client metadata (profile and group) settings
* groups - Current group metadata values
* mappings - Configuration entries provided by plugins
-* buildfile <filename> <hostname> - Build a config file for a client
+* buildfile [--altsrc=<altsrc>] <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
diff --git a/doc/server/plugins/generators/tgenshi/index.txt b/doc/server/plugins/generators/tgenshi/index.txt
index d7e0b3bf2..c5392dcc4 100644
--- a/doc/server/plugins/generators/tgenshi/index.txt
+++ b/doc/server/plugins/generators/tgenshi/index.txt
@@ -106,29 +106,31 @@ E.g.::
bcfg2-info buildfile /etc/foo.conf foo.example.com
+To generate a file with an altsrc attribute, you can run::
+
+ bcfg2-info buildfile /etc/foo/foo.conf --altsrc=/etc/foo.conf \
+ foo.example.com
+
Sometimes, it's useful to be able to do more in-depth troubleshooting
-by running the template manually. (This is also necessary if you want
-to generate a template that depends on an :ref:`altsrc
-<server-plugins-structures-altsrc>` tag.) To do this, run ``bcfg2-info
+by running the template manually. To do this, run ``bcfg2-info
debug``, and, once in the Python interpreter, run::
metadata = self.build_metadata("<hostname>")
path = "<relative path to template (see note below)>"
- bcfg2root = "<path to bcfg2 specification root>"
``path`` should be set to the path to the template file with a leading
slash, relative to the Bcfg2 specification root. See `Inside of
Templates`_ for examples.
-``bcfg2root`` should be set to the absolute path to the Bcfg2
-specification. (This is ``/var/lib/bcfg2`` by default.)
-
Then, run::
- import os
- name = os.path.dirname(path[path.find('/', 1):])
+ import os, Bcfg2.Options
from genshi.template import TemplateLoader, NewTextTemplate
- template = TemplateLoader().load(bcfg2root + path, cls=NewTextTemplate)
+ name = os.path.dirname(path[path.find('/', 1):])
+ setup = Bcfg2.Options.OptionParser({'repo':
+ Bcfg2.Options.SERVER_REPOSITORY})
+ setup.parse('--')
+ template = TemplateLoader().load(set['repo'] + path, cls=NewTextTemplate)
print template.generate(metadata=metadata, path=path, name=name).render()
This gives you more fine-grained control over how your template is
@@ -141,7 +143,6 @@ to the file to be generated, e.g.::
metadata = self.build_metadata("foo.example.com")
path = "/Cfg/etc/sysconfig/network-scripts/ifcfg-template/ifcfg-template.genshi"
- bcfg2root = "/var/lib/bcfg2"
name = "/etc/sysconfig/network-scripts/ifcfg-bond0"
File permissions
diff --git a/man/bcfg2-info.8 b/man/bcfg2-info.8
index 86f2f1b72..a644926b5 100644
--- a/man/bcfg2-info.8
+++ b/man/bcfg2-info.8
@@ -64,7 +64,7 @@ Build configs for all clients in directory.
Build bundle for hostname (not written to disk). If filename is a bundle
template, it is rendered.
.RE
-.B buildfile <filename> <hostname>
+.B buildfile [--altsrc=<altsrc>] <filename> <hostname>
.RS
Build config file for hostname (not written to disk).
.RE
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index e5ae84378..6d4e3e883 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -261,9 +261,20 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
def do_buildfile(self, args):
"""Build a config file for client."""
- if len(args.split()) == 2:
- fname, client = args.split()
+ usage = 'Usage: buildfile [--altsrc=<altsrc>] filename hostname'
+ try:
+ opts, alist = getopt.gnu_getopt(args.split(), '', ['altsrc='])
+ except:
+ print(usage)
+ return
+ for opt in opts:
+ if opt[0] == '--altsrc':
+ altsrc = opt[1]
+ if len(alist) == 2:
+ fname, client = alist
entry = lxml.etree.Element('Path', type='file', name=fname)
+ if altsrc:
+ entry.set("altsrc", altsrc)
try:
metadata = self.build_metadata(client)
self.Bind(entry, metadata)
@@ -272,7 +283,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
except:
print("Failed to build entry %s for host %s" % (fname, client))
else:
- print('Usage: buildfile filename hostname')
+ print(usage)
def do_buildbundle(self, args):
"""Render a bundle for client."""