Sophie

Sophie

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

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>TCheetah &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="TGenshi" href="tgenshi.html" />
    <link rel="prev" title="SSLCA" href="sslca.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="tgenshi.html" title="TGenshi"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="sslca.html" title="SSLCA"
             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="tcheetah">
<span id="server-plugins-generators-tcheetah"></span><h1>TCheetah<a class="headerlink" href="#tcheetah" title="Permalink to this headline">¶</a></h1>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">TCheetah is deprecated.  You should instead use
<a class="reference internal" href="cfg.html#server-plugins-generators-cfg-cheetah"><em>Cheetah Templates</em></a> in the Cfg plugin.</p>
</div>
<p>This document reflects the <tt class="docutils literal"><span class="pre">TCheetah</span></tt> plugin.</p>
<p>The <tt class="docutils literal"><span class="pre">TCheetah</span></tt> plugin allows you to use the <a class="reference external" href="http://www.cheetahtemplate.org/">cheetah templating system</a> to create files, instead of the
various diff-based methods offered by the <tt class="docutils literal"><span class="pre">Cfg</span></tt> plugin. It also allows
you to include the results of probes executed on the client in the
created files.</p>
<p>To begin, you will need to download and install the Cheetah templating
engine from <a class="reference external" href="http://www.cheetahtemplate.org/">http://www.cheetahtemplate.org/</a>.  Once it is installed,
you can enable it by adding <tt class="docutils literal"><span class="pre">TCheetah</span></tt> to the <tt class="docutils literal"><span class="pre">plugins</span></tt> line in
<tt class="docutils literal"><span class="pre">/etc/bcfg2.conf</span></tt> on your Bcfg server.  For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plugins</span> <span class="o">=</span> <span class="n">Base</span><span class="p">,</span><span class="n">Bundler</span><span class="p">,</span><span class="n">Cfg</span><span class="p">,</span><span class="o">...</span><span class="p">,</span><span class="n">TCheetah</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">TCheetah</span></tt> plugin makes use of a <tt class="docutils literal"><span class="pre">Cfg</span></tt>-like directory structure
located in in a <tt class="docutils literal"><span class="pre">TCheetah</span></tt> subdirectory of your repository, usually
<tt class="docutils literal"><span class="pre">/var/lib/bcfg2/TCheetah</span></tt>. Each file has a directory containing two
files, <tt class="docutils literal"><span class="pre">template</span></tt> and <tt class="docutils literal"><span class="pre">info</span></tt>. The template is a standard Cheetah
template with two additions:</p>
<ul class="simple">
<li><cite>self.metadata</cite> is the client&#8217;s <a class="reference internal" href="../grouping/metadata.html#server-plugins-grouping-metadata-clientmetadata"><em>metadata</em></a></li>
<li><cite>self.metadata.Properties.xdata</cite> is an xml document of unstructured data</li>
</ul>
<p>The <tt class="docutils literal"><span class="pre">info</span></tt> file is formatted like <tt class="docutils literal"><span class="pre">:info</span></tt> files from Cfg.</p>
<p>Mostly, people will want to use client metadata.</p>
<div class="section" id="file-permissions">
<h2>File permissions<a class="headerlink" href="#file-permissions" title="Permalink to this headline">¶</a></h2>
<p>File permissions for entries handled by TCheetah are controlled via the
use of <a class="reference internal" href="../../info.html#server-info"><em>info.xml</em></a> files. Note that you <strong>cannot</strong> use both a
Permissions entry and a Path entry to handle the same file.</p>
</div>
<div class="section" id="self-metadata-variables">
<h2>self.metadata variables<a class="headerlink" href="#self-metadata-variables" title="Permalink to this headline">¶</a></h2>
<p>self.metadata is an instance of the class ClientMetadata and documented
<a class="reference internal" href="../grouping/metadata.html#server-plugins-grouping-metadata-clientmetadata"><em>here</em></a>.</p>
</div>
<div class="section" id="self-metadata-properties-xdata">
<h2>self.metadata.Properties.xdata<a class="headerlink" href="#self-metadata-properties-xdata" title="Permalink to this headline">¶</a></h2>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you want to use Properties, you will need to enable the
<a class="reference internal" href="../connectors/properties.html#server-plugins-connectors-properties"><em>Properties</em></a> plugin in
<tt class="docutils literal"><span class="pre">/etc/bcfg2.conf</span></tt>.</p>
</div>
<p>Properties.xdata is a python <a class="reference external" href="http://codespeak.net/lxml/">ElementTree</a>
object, loaded from the data in <tt class="docutils literal"><span class="pre">/var/lib/bcfg2/Properties/&lt;properties</span>
<span class="pre">file&gt;.xml</span></tt>. That file should have a <tt class="docutils literal"><span class="pre">Properties</span></tt> node at its root.</p>
<p>Example <tt class="docutils literal"><span class="pre">Properties/example.xml</span></tt>:</p>
<div class="highlight-xml"><div class="highlight"><pre><span class="nt">&lt;Properties&gt;</span>
 <span class="nt">&lt;host&gt;</span>
   <span class="nt">&lt;www.example.com&gt;</span>
     <span class="nt">&lt;rootdev&gt;</span>/dev/sda<span class="nt">&lt;/rootdev&gt;</span>
   <span class="nt">&lt;/www.example.com&gt;</span>
 <span class="nt">&lt;/host&gt;</span>
<span class="nt">&lt;/Properties&gt;</span>
</pre></div>
</div>
<p>You may use any of the ElementTree methods to access data in your
template.  Several examples follow, each producing an identical result
on the host &#8216;www.example.com&#8217;:</p>
<div class="highlight-python"><pre>$self.metadata.Properties['example.xml'].xdata.find('host').find('www.example.com').find('rootdev').text
$self.metadata.Properties['example.xml'].xdata.find('host').find($self.metadata.hostname).find('rootdev').text
${self.metadata.Properties['example.xml'].xdata.xpath('host/www.example.com/rootdev')[0].text}
${self.metadata.Properties['example.xml'].xdata.xpath('host/' + self.metadata.hostname + '/rootdev')[0].text}
#set $path = 'host/' + $self.metadata.hostname + '/rootdev'
${self.metadata.Properties['example.xml'].xdata.xpath($path)[0].text}
${self.metadata.Properties['example.xml'].xdata.xpath(path)[0].text}</pre>
</div>
</div>
<div class="section" id="other-variables">
<h2>Other Variables<a class="headerlink" href="#other-variables" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><strong>Template.searchList(self)[1][&#8216;path&#8217;]</strong> is the Path name specified in a Bundle</li>
<li><strong>Template.searchList(self)[1][&#8216;source_path&#8217;]</strong> is the path to the TCheetah template on the Bcfg2 server</li>
</ul>
</div>
<div class="section" id="simple-example">
<h2>Simple Example<a class="headerlink" href="#simple-example" title="Permalink to this headline">¶</a></h2>
<p>TCheetah works similar to Cfg in that you define all literal information
about a particular file in a directory rooted at TGenshi/path_to_file.
The actual file contents are placed in a file named <cite>template</cite> in that
directory. Below is a simple example a file <tt class="docutils literal"><span class="pre">/foo</span></tt>.</p>
<p><tt class="docutils literal"><span class="pre">/var/lib/bcfg2/TCheetah/foo/template</span></tt></p>
<div class="highlight-none"><div class="highlight"><pre>&gt; buildfile /foo &lt;clientname&gt;
Hostname is $self.metadata.hostname
Filename is $Template.searchList(self)[1][&#39;path&#39;]
Template is $Template.searchList(self)[1][&#39;source_path&#39;]
Groups:
#for $group in $self.metadata.groups:
 * $group
#end for
Categories:
#for $category in $self.metadata.categories:
 * $category -- $self.metadata.categories[$category]
#end for

Probes:
#for $probe in $self.metadata.Probes:
 * $probe -- $self.metadata.Probes[$probe]
#end for
</pre></div>
</div>
<p><tt class="docutils literal"><span class="pre">/var/lib/bcfg2/TCheetah/foo/info</span></tt></p>
<div class="highlight-none"><div class="highlight"><pre>mode: 624
</pre></div>
</div>
<div class="section" id="output">
<h3>Output<a class="headerlink" href="#output" title="Permalink to this headline">¶</a></h3>
<p>The following output can be generated with bcfg2-info. Note that probe
information is not persistent, hence, it only works when clients directly
query the server. For this reason, bcfg2-info output doesn&#8217;t reflect
current client probe state.</p>
<div class="highlight-xml"><div class="highlight"><pre><span class="nt">&lt;Path</span> <span class="na">type=</span><span class="s">&quot;file&quot;</span> <span class="na">name=</span><span class="s">&quot;/foo&quot;</span> <span class="na">owner=</span><span class="s">&quot;root&quot;</span> <span class="na">mode=</span><span class="s">&quot;0624&quot;</span> <span class="na">group=</span><span class="s">&quot;root&quot;</span><span class="nt">&gt;</span>
Hostname is topaz.mcs.anl.gov
Filename is /foo
Template is /var/lib/bcfg2/TCheetah/foo/template
Groups:
 * desktop
 * mcs-base
 * ypbound
 * workstation
 * xserver
 * debian-sarge
 * debian
 * a
Categories:
 * test -- a

Probes:
<span class="nt">&lt;/Path&gt;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="example-replace-the-crontab-plugin">
<h2>Example: Replace the crontab plugin<a class="headerlink" href="#example-replace-the-crontab-plugin" title="Permalink to this headline">¶</a></h2>
<p>In many cases you can use the TCheetah plugin to avoid writing custom
plugins in Python. This example randomizes the time of cron.daily
execution with a stable result. Cron.daily is run at a consistent,
randomized time between midnight and 7am.:</p>
<div class="highlight-python"><pre>#import random
#silent random.seed($self.metadata.hostname)

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab`
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin://bin

# m h dom mon dow user  command
17 *    * * *   root    run-parts --report /etc/cron.hourly
$random.randrange(0,59) $random.randrange(0,6)    * * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6    * * 7   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6    1 * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly.</pre>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Comments and Cheetah
As Cheetah processes your templates it will consider hash &#8220;#&#8221; style
comments to be actual comments in the template and will strip them
from the final config file.  If you would like to preserve the comment
in the final config file you need to escape the hash character &#8216;#&#8217;
which will tell Cheetah (and Python) that you do in fact want the
comment to appear in the final config file.:</p>
<div class="last highlight-python"><pre># This is a comment in my template which will be stripped when it's processed through Cheetah
\# This comment will appear in the generated config file.</pre>
</div>
</div>
</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="#">TCheetah</a><ul>
<li><a class="reference internal" href="#file-permissions">File permissions</a></li>
<li><a class="reference internal" href="#self-metadata-variables">self.metadata variables</a></li>
<li><a class="reference internal" href="#self-metadata-properties-xdata">self.metadata.Properties.xdata</a></li>
<li><a class="reference internal" href="#other-variables">Other Variables</a></li>
<li><a class="reference internal" href="#simple-example">Simple Example</a><ul>
<li><a class="reference internal" href="#output">Output</a></li>
</ul>
</li>
<li><a class="reference internal" href="#example-replace-the-crontab-plugin">Example: Replace the crontab plugin</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="sslca.html"
                        title="previous chapter">SSLCA</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tgenshi.html"
                        title="next chapter">TGenshi</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/server/plugins/generators/tcheetah.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="tgenshi.html" title="TGenshi"
             >next</a> |</li>
        <li class="right" >
          <a href="sslca.html" title="SSLCA"
             >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>