2019-10-16 21:01:30 +00:00
<!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" >
2019-12-19 21:44:12 +00:00
< title > lifted.upload — Lorax 32.4 documentation< / title >
2019-10-16 21:01:30 +00:00
< 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" >
2019-12-19 21:44:12 +00:00
32.4
2019-10-16 21:01:30 +00:00
< / 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 >
2019-11-05 22:36:46 +00:00
< li class = "toctree-l1" > < a class = "reference internal" href = "../../mkksiso.html" > mkksiso< / a > < / li >
2019-10-16 21:01:30 +00:00
< 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 > » < / li >
< li > < a href = "../index.html" > Module code< / a > » < / 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 < http://www.gnu.org/licenses/> .< / 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" > " lifted" < / 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" > " " " 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" " " < / 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" > " " < / 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" > " WAITING" < / 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" > " " " 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" > " " " < / 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" > " < / span > < span class = "si" > {message}< / span > < span class = "se" > \n< / span > < span class = "s2" > " < / 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" > " " " Returns a representation of the object as a dict for serialization< / span >
< span class = "sd" > :returns: the object' s __dict__< / span >
< span class = "sd" > :rtype: dict< / span >
< span class = "sd" > " " " < / 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" > " " " 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" > " " " < / span >
< span class = "k" > return< / span > < span class = "p" > {< / span >
< span class = "s2" > " uuid" < / 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" > " status" < / 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" > " provider_name" < / 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" > " image_name" < / 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" > " image_path" < / 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" > " creation_time" < / 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" > " settings" < / 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" > " " " 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" > " " " < / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > _log< / span > < span class = "p" > (< / span > < span class = "s2" > " Setting status to < / span > < span class = "si" > %s< / span > < span class = "s2" > " < / 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" > " " " 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" > " " " < / span >
< span class = "bp" > self< / span > < span class = "o" > .< / span > < span class = "n" > _log< / span > < span class = "p" > (< / span > < span class = "s2" > " Setting image_path to < / span > < span class = "si" > %s< / span > < span class = "s2" > " < / 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" > " WAITING" < / 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" > " READY" < / 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" > " " " 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" > " " " < / 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" > " Can' t reset, status is < / span > < span class = "si" > {self.status}< / span > < span class = "s2" > !" < / 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" > " Can' t reset, no image supplied yet!" < / 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" > " Resetting state" < / 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" > " READY" < / 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" > " " " 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" > " " " < / 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" > " WAITING" < / span > < span class = "p" > ,< / span > < span class = "s2" > " READY" < / span > < span class = "p" > ,< / span > < span class = "s2" > " RUNNING" < / 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" > " " " 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" > " " " < / 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" > " Can' t cancel, status is already < / span > < span class = "si" > {self.status}< / span > < span class = "s2" > !" < / 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" > " CANCELLED" < / 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" > " " " 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" > " " " < / 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" > " READY" < / span > < span class = "p" > :< / span >
< span class = "k" > raise< / span > < span class = "ne" > RuntimeError< / span > < span class = "p" > (< / span > < span class = "s2" > " This upload is not ready!" < / 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" > " RUNNING" < / 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" > " Executing playbook.yml" < / span > < span class = "p" > )< / span >
< span class = "c1" > # NOTE: event_handler doesn' 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" > " stdout" < / 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" > " image_name" < / 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" > " image_path" < / 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" > " < / span > < span class = "si" > %s< / span > < span class = "s2" > " < / 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" > " < / span > < span class = "si" > %s< / span > < span class = "s2" > " < / 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" > " < / span > < span class = "si" > %s< / span > < span class = "s2" > " < / 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" > " successful" < / 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" > " FINISHED" < / 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" > " FAILED" < / 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 >
© 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 >