lorax/docs/html/_modules/lifted/upload.html
2019-11-05 14:36:46 -08:00

411 lines
30 KiB
HTML

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lifted.upload &mdash; Lorax 32.2 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></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/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
32.2
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>lifted.upload</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for lifted.upload</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">multiprocessing</span> <span class="k">import</span> <span class="n">current_process</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">from</span> <span class="nn">uuid</span> <span class="k">import</span> <span class="n">uuid4</span>
<span class="kn">from</span> <span class="nn">ansible_runner.interface</span> <span class="k">import</span> <span class="n">run</span> <span class="k">as</span> <span class="n">ansible_run</span>
<span class="kn">from</span> <span class="nn">ansible_runner.exceptions</span> <span class="k">import</span> <span class="n">AnsibleRunnerException</span>
<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s2">&quot;lifted&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="Upload"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload">[docs]</a><span class="k">class</span> <span class="nc">Upload</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;Represents an upload of an image to a cloud provider. Instances of this</span>
<span class="sd"> class are serialized as TOML and stored in the upload queue directory,</span>
<span class="sd"> which is /var/lib/lorax/upload/queue/ by default&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">uuid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">provider_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">playbook_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">image_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">settings</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">creation_time</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">upload_log</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">upload_pid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">image_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">status</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uuid</span> <span class="o">=</span> <span class="n">uuid</span> <span class="ow">or</span> <span class="nb">str</span><span class="p">(</span><span class="n">uuid4</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">provider_name</span> <span class="o">=</span> <span class="n">provider_name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">playbook_path</span> <span class="o">=</span> <span class="n">playbook_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_name</span> <span class="o">=</span> <span class="n">image_name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">settings</span> <span class="o">=</span> <span class="n">settings</span>
<span class="bp">self</span><span class="o">.</span><span class="n">creation_time</span> <span class="o">=</span> <span class="n">creation_time</span> <span class="ow">or</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">timestamp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_log</span> <span class="o">=</span> <span class="n">upload_log</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span> <span class="o">=</span> <span class="n">upload_pid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_path</span> <span class="o">=</span> <span class="n">image_path</span>
<span class="k">if</span> <span class="n">status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;WAITING&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_log</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Logs something to the upload log with an optional callback</span>
<span class="sd"> :param message: the object to log</span>
<span class="sd"> :type message: object</span>
<span class="sd"> :param callback: a function of the form callback(self)</span>
<span class="sd"> :type callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">message</span><span class="p">:</span>
<span class="n">messages</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
<span class="c1"># Log multi-line messages as individual log lines</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">messages</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_log</span> <span class="o">+=</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{message}</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">if</span> <span class="n">callback</span><span class="p">:</span>
<span class="n">callback</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<div class="viewcode-block" id="Upload.serializable"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.serializable">[docs]</a> <span class="k">def</span> <span class="nf">serializable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Returns a representation of the object as a dict for serialization</span>
<span class="sd"> :returns: the object&#39;s __dict__</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span></div>
<div class="viewcode-block" id="Upload.summary"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.summary">[docs]</a> <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a dict with useful information about the upload</span>
<span class="sd"> :returns: upload information</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span>
<span class="s2">&quot;uuid&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">uuid</span><span class="p">,</span>
<span class="s2">&quot;status&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">,</span>
<span class="s2">&quot;provider_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">provider_name</span><span class="p">,</span>
<span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_name</span><span class="p">,</span>
<span class="s2">&quot;image_path&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">,</span>
<span class="s2">&quot;creation_time&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">creation_time</span><span class="p">,</span>
<span class="s2">&quot;settings&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">,</span>
<span class="p">}</span></div>
<div class="viewcode-block" id="Upload.set_status"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.set_status">[docs]</a> <span class="k">def</span> <span class="nf">set_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Sets the status of the upload with an optional callback</span>
<span class="sd"> :param status: the new status</span>
<span class="sd"> :type status: str</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Setting status to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">status</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span>
<span class="k">if</span> <span class="n">status_callback</span><span class="p">:</span>
<span class="n">status_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.ready"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.ready">[docs]</a> <span class="k">def</span> <span class="nf">ready</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image_path</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Provide an image_path and mark the upload as ready to execute</span>
<span class="sd"> :param image_path: path of the image to upload</span>
<span class="sd"> :type image_path: str</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Setting image_path to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">image_path</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_path</span> <span class="o">=</span> <span class="n">image_path</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;WAITING&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.reset"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.reset">[docs]</a> <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Reset the upload so it can be attempted again</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_cancellable</span><span class="p">():</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Can&#39;t reset, status is </span><span class="si">{self.status}</span><span class="s2">!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Can&#39;t reset, no image supplied yet!&quot;</span><span class="p">)</span>
<span class="c1"># self.error = None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Resetting state&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.is_cancellable"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.is_cancellable">[docs]</a> <span class="k">def</span> <span class="nf">is_cancellable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Is the upload in a cancellable state?</span>
<span class="sd"> :returns: whether the upload is cancellable</span>
<span class="sd"> :rtype: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;WAITING&quot;</span><span class="p">,</span> <span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="s2">&quot;RUNNING&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.cancel"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.cancel">[docs]</a> <span class="k">def</span> <span class="nf">cancel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Cancel the upload. Sends a SIGINT to self.upload_pid.</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_cancellable</span><span class="p">():</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">f</span><span class="s2">&quot;Can&#39;t cancel, status is already </span><span class="si">{self.status}</span><span class="s2">!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">kill</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;CANCELLED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.execute"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.execute">[docs]</a> <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Execute the upload. Meant to be called from a dedicated process so</span>
<span class="sd"> that the upload can be cancelled by sending a SIGINT to</span>
<span class="sd"> self.upload_pid.</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">!=</span> <span class="s2">&quot;READY&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;This upload is not ready!&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span> <span class="o">=</span> <span class="n">current_process</span><span class="p">()</span><span class="o">.</span><span class="n">pid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;RUNNING&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Executing playbook.yml&quot;</span><span class="p">)</span>
<span class="c1"># NOTE: event_handler doesn&#39;t seem to be called for playbook errors</span>
<span class="n">logger</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="s2">&quot;stdout&quot;</span><span class="p">],</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="n">runner</span> <span class="o">=</span> <span class="n">ansible_run</span><span class="p">(</span>
<span class="n">playbook</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">playbook_path</span><span class="p">,</span>
<span class="n">extravars</span><span class="o">=</span><span class="p">{</span>
<span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">,</span>
<span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_name</span><span class="p">,</span>
<span class="s2">&quot;image_path&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">,</span>
<span class="p">},</span>
<span class="n">event_handler</span><span class="o">=</span><span class="n">logger</span><span class="p">,</span>
<span class="n">verbosity</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Try logging events and stats -- but they may not exist, so catch the error</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">runner</span><span class="o">.</span><span class="n">events</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">dir</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">runner</span><span class="o">.</span><span class="n">stats</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">except</span> <span class="n">AnsibleRunnerException</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">runner</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">if</span> <span class="n">runner</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;successful&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;FINISHED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;FAILED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">traceback</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>