Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > b50d8ee6d7871fcc13c0677a9364ed59 > files > 443

bcfg2-doc-1.3.0-1.fc17.noarch.rpm



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>TemplateHelper &mdash; Bcfg2 1.3.0 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/sidebar.js"></script>
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
    <link rel="top" title="Bcfg2 1.3.0 documentation" href="../../../index.html" />
    <link rel="up" title="Plugins" href="../index.html" />
    <link rel="next" title="Reporting" href="../statistics/reporting.html" />
    <link rel="prev" title="PuppetENC" href="puppetenc.html" />
 
<link rel="stylesheet" href="../../../_static/bcfg2.css" type=""/>

  </head>
  <body>

<div style="text-align: left; padding: 10px 10px 15px 15px">
<a href="../../../index.html"><img src="../../../_static/bcfg2_logo.png" border="0" alt="sampledoc"/></a>
</div>

    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../statistics/reporting.html" title="Reporting"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="puppetenc.html" title="PuppetENC"
             accesskey="P">previous</a> |</li>
	<li><a href="../../../index.html">home</a> |&nbsp;</li>
	<!--<li><a href="../../../search.html">search</a> |&nbsp;</li>-->
	<li><a href="../../../help/index.html">help</a> |&nbsp;</li>
	<li><a href="../../../contents.html">documentation </a> &raquo;</li>

          <li><a href="../../../contents.html" >Bcfg2 documentation 1.3.0</a> &raquo;</li>
          <li><a href="../../index.html" >The Bcfg2 Server</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Plugins</a> &raquo;</li> 
      </ul>
    </div>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="templatehelper">
<span id="server-plugins-connectors-templatehelper"></span><h1>TemplateHelper<a class="headerlink" href="#templatehelper" title="Permalink to this headline">¶</a></h1>
<p>The TemplateHelper plugin is a connector plugin that adds Python
classes and methods to client metadata instances for use in
templates.  This allows you to easily reuse code that is common
amongst multiple templates and add convenience methods.</p>
<div class="section" id="using-templatehelper">
<h2>Using TemplateHelper<a class="headerlink" href="#using-templatehelper" title="Permalink to this headline">¶</a></h2>
<p>First, <tt class="docutils literal"><span class="pre">mkdir</span> <span class="pre">/var/lib/bcfg2/TemplateHelper</span></tt> and add
<strong>TemplateHelper</strong> to your <tt class="docutils literal"><span class="pre">plugins</span></tt> line in <tt class="docutils literal"><span class="pre">/etc/bcfg2.conf</span></tt>.
Restart <tt class="docutils literal"><span class="pre">bcfg2-server</span></tt>.</p>
<p>Now, any <tt class="docutils literal"><span class="pre">.py</span></tt> file placed in <tt class="docutils literal"><span class="pre">/var/lib/bcfg2/TemplateHelper/</span></tt>
will be read and added to matching client metadata objects.  See
<a class="reference internal" href="#writing-templatehelpers"><em>Writing Helpers</em></a> below for more information on how to
write TemplateHelper scripts.</p>
<p>TemplateHelper does not support group- or host-specific helpers.  All
helpers will be available to all clients.</p>
</div>
<div class="section" id="writing-helpers">
<span id="writing-templatehelpers"></span><h2>Writing Helpers<a class="headerlink" href="#writing-helpers" title="Permalink to this headline">¶</a></h2>
<p>A helper module is just a Python module with three special conditions:</p>
<ul class="simple">
<li>The filename must end with <tt class="docutils literal"><span class="pre">.py</span></tt></li>
<li>The module must have an attribute, <tt class="docutils literal"><span class="pre">__export__</span></tt>, that lists all of
the classes, functions, variables, or other symbols you wish to
export from the module.</li>
<li><tt class="docutils literal"><span class="pre">data</span></tt>, <tt class="docutils literal"><span class="pre">name</span></tt>, <tt class="docutils literal"><span class="pre">fam</span></tt>, <tt class="docutils literal"><span class="pre">Index</span></tt>, and <tt class="docutils literal"><span class="pre">HandleEvent</span></tt> are
reserved names.  You should not include symbols with a reserved name
in <tt class="docutils literal"><span class="pre">__export__</span></tt>.  Additionally, including symbols that start with
an underscore or double underscore is bad form, and may also produce
errors.</li>
</ul>
<p>See <tt class="docutils literal"><span class="pre">examples/TemplateHelper</span></tt> for examples of helper modules.</p>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>Specific helpers can be referred to in
templates as <tt class="docutils literal"><span class="pre">metadata.TemplateHelper[&lt;modulename&gt;]</span></tt>. That accesses
a HelperModule object will has, as attributes, all symbols listed in
<tt class="docutils literal"><span class="pre">__export__</span></tt>.  For example, consider this helper module:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">__export__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;hello&quot;</span><span class="p">]</span>

<span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">metadata</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&quot;Hello, </span><span class="si">%s</span><span class="s">!&quot;</span> <span class="o">%</span> <span class="n">metadata</span><span class="o">.</span><span class="n">hostname</span>
</pre></div>
</div>
<p>To use this in a Genshi template, we could do:</p>
<div class="highlight-python"><pre>${metadata.TemplateHelper['hello'].hello(metadata)}</pre>
</div>
<p>The template would produce:</p>
<div class="highlight-python"><pre>Hello, foo.example.com!</pre>
</div>
<p>Note that the client metadata object is not passed to a helper module
in any magical way; if you want to access the client metadata object
in a helper function or class, you must pass the object to the
function manually.</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">TemplateHelper</a><ul>
<li><a class="reference internal" href="#using-templatehelper">Using TemplateHelper</a></li>
<li><a class="reference internal" href="#writing-helpers">Writing Helpers</a></li>
<li><a class="reference internal" href="#usage">Usage</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="puppetenc.html"
                        title="previous chapter">PuppetENC</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../statistics/reporting.html"
                        title="next chapter">Reporting</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/server/plugins/connectors/templatehelper.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../statistics/reporting.html" title="Reporting"
             >next</a> |</li>
        <li class="right" >
          <a href="puppetenc.html" title="PuppetENC"
             >previous</a> |</li>
	<li><a href="../../../index.html">home</a> |&nbsp;</li>
	<!--<li><a href="../../../search.html">search</a> |&nbsp;</li>-->
	<li><a href="../../../help/index.html">help</a> |&nbsp;</li>
	<li><a href="../../../contents.html">documentation </a> &raquo;</li>

          <li><a href="../../../contents.html" >Bcfg2 documentation 1.3.0</a> &raquo;</li>
          <li><a href="../../index.html" >The Bcfg2 Server</a> &raquo;</li>
          <li><a href="../index.html" >Plugins</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2009-2013, Narayan Desai.
      Last updated on Mar 20, 2013.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>