<liclass="toctree-l2"><aclass="reference internal"href="#implementing-a-new-preos-sub-command">21.3. Implementing a new PreOS sub-command</a><ul>
<liclass="toctree-l3"><aclass="reference internal"href="#example-of-writing-new-dummy-preos-sub-command">21.3.1. Example of writing new dummy preos sub-command</a><ul>
<p>For more info about the available options see the cdist manual page.</p>
<p>This will bootstrap (<codeclass="docutils literal notranslate"><spanclass="pre">-B</span></code>) ubuntu PreOS in the <codeclass="docutils literal notranslate"><spanclass="pre">/preos/preos-ubuntu</span></code>
directory, it will be configured (<codeclass="docutils literal notranslate"><spanclass="pre">-C</span></code>) using default the built-in initial
manifest and with specified ssh authorized key (<codeclass="docutils literal notranslate"><spanclass="pre">-k</span></code>).
After bootstrapping and configuration, the PXE boot directory will be
created (<codeclass="docutils literal notranslate"><spanclass="pre">-p</span></code>) in <codeclass="docutils literal notranslate"><spanclass="pre">/preos/pxe-ubuntu</span></code>.</p>
<p>After PreOS is created, new machines can be booted using the created PXE
(after proper dhcp and tftp settings).</p>
<p>Since PreOS is configured with ssh authorized key it can be accessed through
ssh, i.e. it can be further installed and configured with cdist.</p>
<h2><spanclass="section-number">21.3. </span>Implementing a new PreOS sub-command<aclass="headerlink"href="#implementing-a-new-preos-sub-command"title="Permalink to this headline">¶</a></h2>
<p>preos command is implemented as a plugin system. This plugin system scans for
preos subcommands in the <codeclass="docutils literal notranslate"><spanclass="pre">cdist/preos/</span></code> distribution directory and also in
<codeclass="docutils literal notranslate"><spanclass="pre">~/.cdist/preos/</span></code> directory if it exists.</p>
<p>preos subcommand is a module or a class that satisfies the following:</p>
<ulclass="simple">
<li><p>it has the attribute <codeclass="docutils literal notranslate"><spanclass="pre">_cdist_preos</span></code> set to <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code></p></li>
<li><p>it defines a function/method <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code>.</p></li>
</ul>
<p>For a module-based preos subcommand, the <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code> function accepts a
module object as its first argument and the list of command line
<p>For a class-based preos subcommand <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code> method should be
static-method and must accept a class as its first argument and the
list of command line arguments (<codeclass="docutils literal notranslate"><spanclass="pre">sys.argv[2:]</span></code>).</p>
<p>If preos scanning finds a module/class that has <codeclass="docutils literal notranslate"><spanclass="pre">_cdist_preos</span></code> set
to <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code> and a function/method <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code> then this module/class is
registered to preos subcommands. The name of the command is set to <codeclass="docutils literal notranslate"><spanclass="pre">_preos_name</span></code>
attribute if defined in the module/class, defaulting to the module/class name in lowercase.
When a registered preos subcommand is specified, <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code>
will be called with the first argument set to module/class and the second
argument set to <codeclass="docutils literal notranslate"><spanclass="pre">sys.argv[2:]</span></code>.</p>
<h3><spanclass="section-number">21.3.1. </span>Example of writing new dummy preos sub-command<aclass="headerlink"href="#example-of-writing-new-dummy-preos-sub-command"title="Permalink to this headline">¶</a></h3>
<sectionid="module-based-preos">
<h4><spanclass="section-number">21.3.1.1. </span>Module-based preos:<aclass="headerlink"href="#module-based-preos"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li><p>Create directory <codeclass="docutils literal notranslate"><spanclass="pre">~/.cdist/preos/</span></code> if it does not exist</p></li>
<li><p>Create <codeclass="docutils literal notranslate"><spanclass="pre">~/.cdist/preos/netbsd.py</span></code> with the following contents:</p></li>
<h4><spanclass="section-number">21.3.1.2. </span>Class based preos:<aclass="headerlink"href="#class-based-preos"title="Permalink to this headline">¶</a></h4>
<olclass="arabic simple">
<li><p>Create directory <codeclass="docutils literal notranslate"><spanclass="pre">~/.cdist/preos/</span></code> if it does not exist</p></li>
<li><p>Create <codeclass="docutils literal notranslate"><spanclass="pre">~/.cdist/preos/freebsd.py</span></code> with the following contents:</p></li>
<p>In the <codeclass="docutils literal notranslate"><spanclass="pre">commandline</span></code> function/method you have all the freedom to actually create
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.