<liclass="toctree-l2"><aclass="reference internal"href="#implementing-new-preos-sub-command">19.3. Implementing new PreOS sub-command</a><ul>
<liclass="toctree-l3"><aclass="reference internal"href="#example-writing-new-dummy-preos-sub-command">19.3.1. Example writing new dummy preos sub-command</a><ul>
<liclass="toctree-l4"><aclass="reference internal"href="#module-based-preos">19.3.1.1. Module based preos:</a></li>
<liclass="toctree-l4"><aclass="reference internal"href="#class-based-preos">19.3.1.2. Class based preos:</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="#simple-tipical-use-case-for-using-preos-and-trigger">19.4. Simple tipical use case for using PreOS and trigger</a></li>
<p>For more info about available options see cdist manual page.</p>
<p>This will bootstrap (<codeclass="docutils literal"><spanclass="pre">-b</span></code>) ubuntu PreOS in <codeclass="docutils literal"><spanclass="pre">/preos/preos-ubuntu</span></code> directory, it
will be configured (<codeclass="docutils literal"><spanclass="pre">-C</span></code>) using default built-in initial manifest and with
specified ssh authorized key (<codeclass="docutils literal"><spanclass="pre">-k</span></code>) and with specified trigger command (<codeclass="docutils literal"><spanclass="pre">-t</span></code>).
After bootstrapping and configuration PXE
boot directory will be created (<codeclass="docutils literal"><spanclass="pre">-p</span></code>) in <codeclass="docutils literal"><spanclass="pre">/preos/pxe-ubuntu</span></code>.</p>
<p>After PreOS is created new machines can be booted using created PXE (after
proper dhcp, tftp setting).</p>
<p>Since PreOS is configured with ssh authorized key it can be accessed throguh
ssh, i.e. it can be further installed and configured with cdist.</p>
<p>When installing and configuring new machines using cdist's PreOS concept
<h2>19.3. Implementing new PreOS sub-command<aclass="headerlink"href="#implementing-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 <codeclass="docutils literal"><spanclass="pre">cdist/preos/</span></code> distribution directory and also in
<codeclass="docutils literal"><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>it has attribute <codeclass="docutils literal"><spanclass="pre">_cdist_preos</span></code> set to <codeclass="docutils literal"><spanclass="pre">True</span></code></li>
<li>it has function/method <codeclass="docutils literal"><spanclass="pre">commandline</span></code>.</li>
</ul>
<p>For a module based preos subcommand <codeclass="docutils literal"><spanclass="pre">commandline</span></code> function accepts a module
object as its first argument and the list of command line
<p>If preos scanning finds a module/class that has <codeclass="docutils literal"><spanclass="pre">_cdist_preos</span></code> set
to <codeclass="docutils literal"><spanclass="pre">True</span></code> and it has function/method <codeclass="docutils literal"><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"><spanclass="pre">_preos_name</span></code>
attribute if it exists, otherwise it is set to the module/class name, lowercase.
When registered preos subcommand is specified as preos command then <codeclass="docutils literal"><spanclass="pre">commandline</span></code>
will be called with first argument set to module/class object and second argument
set to <codeclass="docutils literal"><spanclass="pre">sys.argv[2:]</span></code>.</p>
<h3>19.3.1. Example writing new dummy preos sub-command<aclass="headerlink"href="#example-writing-new-dummy-preos-sub-command"title="Permalink to this headline">¶</a></h3>
preos PreOS to create, one of: <spanclass="o">{</span><spanclass="s1">'netbsd'</span>, <spanclass="s1">'debian'</span>, <spanclass="s1">'ubuntu'</span><spanclass="o">}</span>
optional arguments:
-h, --help show this <spanclass="nb">help</span> message and <spanclass="nb">exit</span>
preos PreOS to create, one of: <spanclass="o">{</span><spanclass="s1">'freebsd'</span>, <spanclass="s1">'debian'</span>, <spanclass="s1">'ubuntu'</span><spanclass="o">}</span>
optional arguments:
-h, --help show this <spanclass="nb">help</span> message and <spanclass="nb">exit</span>
$ cdist preos freebsd
FreeBSD dummy preos: <spanclass="o">[]</span>
</pre></div>
</div>
<p>In the <codeclass="docutils literal"><spanclass="pre">commandline</span></code> function/method you have all the freedom to actually create
<h2>19.4. Simple tipical use case for using PreOS and trigger<aclass="headerlink"href="#simple-tipical-use-case-for-using-preos-and-trigger"title="Permalink to this headline">¶</a></h2>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.