%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/nspawn.pyo

�
���^c@@s2dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlZddlZddlZddlmZmZddlmZddlmZeje�Zidd6Zd	Zd
ZdZ dZ!d
�Z"d�Z#d�Z$de%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+d�Z,d�Z-d�Z.d�Z/de%e%d�Z0e$de%de2e%de%e%dd�	�Z3e$d��Z4e%e2de2de%e%dd�Z5e%e2de2de%e%dd �Z6e%e2de2de%e%dd!�Z7e%e2de2de%e%dd"�Z8e%e2de2de%e%dd#�Z9ddd$�Z:d%�Z;de2e2ddde%e%dddd&�Z<d'�Z=d(�Z>ej?jj@e>d�ZAd)�ZBd*�ZCe$d+��ZDd,�ZEe$d-��ZFe$d.��ZGe$d/��ZHe$e%d0��ZId1�ZJd2�ZKd3�ZLe$e%d4��ZMe$e%d5��ZNej?jj@eNd6�ZOe$e%e%d7��ZPej?jj@ePd8�ZQd9�ZRe%d:�ZSe%d;�ZTd<�ZUej?jj@eUd=�ZVdS(>uu
Manage nspawn containers

.. versionadded:: 2015.8.0

`systemd-nspawn(1)`__ is a tool used to manage lightweight namespace
containers. This execution module provides several functions to help manage
these containers.

.. __: http://www.freedesktop.org/software/systemd/man/systemd-nspawn.html

Minions running systemd >= 219 will place new containers in
``/var/lib/machines``, while those running systemd < 219 will place them in
``/var/lib/container``.

.. note:

    ``nsenter(1)`` is required to run commands within containers. It should
    already be present on any systemd host, as part of the **util-linux**
    package.
i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortSaltInvocationError(tsix(trangeulistulist_unspawnu/nspawn.initial_seeduF/etc/systemd/system/multi-user.target.wants/systemd-nspawn@{0}.serviceunsentercC@s^tddkrTtjjjt�rTtjjj�dkrMtj	d�qTt
SntdfS(uA
    Only work on systems that have been booted with systemd
    ukerneluLinuxu+nspawn: Unable to determine systemd versionudThe nspawn execution module failed to load: only work on systems that have been booted with systemd.N(t
__grains__tsalttutilstsystemdtbootedt__context__tversiontNonetlogterrort__virtualname__tFalse(((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt__virtual__8scC@stjjjt�S(u�
    Returns __context__.get('systemd.version', 0), avoiding duplication of the
    call to dict.get and making it easier to change how we handle this context
    var in the future
    (RR	R
R
R(((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_sd_versionFsc@s"tj���fd��}|S(u>
    Decorator to ensure that the named container exists.
    c@sCt|�s$tdj|���n�||tjjj|��S(NuContainer '{0}' does not exist(texistsRtformatRR	targstclean_kwargs(tnameRtkwargs(twrapped(s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytcheck_existsSs(t	functoolstwraps(RR((Rs7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_ensure_existsOsucC@s{t�dkrQ|r;gdD]}tjj||�^qStjjd|�Sn&tjjd|�}|rs|gS|SdS(us
    Return the container root directory. Starting with systemd 219, new
    images go into /var/lib/machines.
    i�u/var/lib/machinesu/var/lib/containerN(u/var/lib/machinesu/var/lib/container(Rtostpathtjoin(Rt	all_rootstxtret((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_root]s#cC@s�t|�}tjj|�rItjjjtd<t	dj
|���nCytj|�|SWn+tk
r�}t	dj
||���nXdS(u+
    Make the container root directory
    uretcodeuContainer {0} already existsu0Unable to make container root directory {0}: {1}N(
R&R R!RRtdefaultst	exitcodestSALT_BUILD_FAILRRRtmakedirstOSError(RR!texc((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_make_container_rootps
cC@s}y$tjjjtd<tj|�Wn=tk
rc}|jtj	krdt
dj|���qdnXt
dj|���dS(Nuretcodeu(Unable to cleanup container root dir {0}uContainer {0} failed to build(RR'R(R)RtshutiltrmtreeR+terrnotENOENTRR(tdstRR,((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt
_build_failed�scK@sytjjjd�s$td��nt|�}dj|�}td|dt�}|ddkrut	||�n|S(u+
    Bootstrap an Arch Linux container
    upacstrapuBpacstrap not found, is the arch-install-scripts package installed?upacstrap -c -d {0} baseucmd.run_alltpython_shelluretcodei(
RR	R!twhichRR-Rt__salt__RR3(RRR2tcmdR%((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_bootstrap_arch�sc	K@s�|jdt�}|sDtdj�dkr;td}qDd}ndddd	d
ddd
dg	}||kr�tdj|���nt|�}dj||�}td|dt�}|ddkr�t||�n|S(u,
    Bootstrap a Debian Linux container
    uversionuosudebianu	osreleaseustableuhammuslinkupotatouwoodyusargeuetchulennyusqueezeuwheezyuSUnsupported Debian version "{0}". Only "stable" or "jessie" and newer are supportedu debootstrap --arch=amd64 {0} {1}ucmd.run_allR4uretcodei(	tgetRRtlowerRRR-R6R3(RRR
trelease_blacklistR2R7R%((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_bootstrap_debian�s 
	!cK@s�t|�}|jdt�sJtdj�dkrAtd}qPd}nd}dj||�}td|dt�}|d	d
kr�t||�n|S(u&
    Bootstrap a Fedora container
    uversionuosufedorau	osreleaseu21u�yum -y --releasever={0} --nogpg --installroot={1} --disablerepo="*" --enablerepo=fedora install systemd passwd yum fedora-release vim-minimalucmd.run_allR4uretcodei(R-R9RRR:RR6R3(RRR2R
R7R%((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_bootstrap_fedora�s
	cK@s�|jdt�}|sDtdj�dkr;td}qDd}nt|�}dj||�}td|dt�}|d	d
kr�t||�n|S(u,
    Bootstrap a Ubuntu Linux container
    uversionuosuubuntuu
oscodenameuxenialu debootstrap --arch=amd64 {0} {1}ucmd.run_allR4uretcodei(R9RRR:R-RR6R3(RRR
R2R7R%((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_bootstrap_ubuntu�s
	cC@sWxPgtD]}|jd�r
|^q
D]&}tjd|�tj|d�q)WdS(u4
    Clear any lxc variables set in __context__
    unspawn.uClearing __context__['%s']N(Rt
startswithRttracetpopR(R$tvar((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_clear_context�s/cC@s$t|�dkrtSt|�SdS(u<
    Raise an exception if the container does not exist
    urunningN(tstatetTruetstart(R((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_ensure_running�scC@s�yt|�}Wn&tk
r8tdj|���nXyt�}tjd|�Wn#ttfk
r{td��nX||kr�tdj||���ndS(u`
    Raises an exception if the systemd version is not greater than the
    passed version.
    uInvalid version '{0}'unspawn: detected systemd %su%nspawn: Unable to get systemd versionu>This function requires systemd >= {0} (Detected version: {1}).N(tintt
ValueErrorRRRRtdebugt
IndexError(R
t	installed((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_ensure_systemd�s
	udebugcC@s2d}tddj||�d|d|d|�S(u+
    Helper function to run machinectl
    u!machinectl --no-legend --no-pagerucmd.run_allu{0} {1}toutput_logleveltignore_retcodetuse_vt(R6R(R7RNRORPtprefix((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_machinectls
cC@s�t|�}d}znyStd||dtdtd|d|d|d|d|d	|d
|	d|
�
}
Wntk
r~�nXWd|r�|d
kr�t|�d
kr�t|�nX|dkr�|
S|
|SdS(u/
    Common logic for nspawn.run functions
    ucontainer_resource.runtcontainer_typetexec_drivertoutputtno_starttstdinR4RNRORPtkeep_envNustoppeduall(Nuall(RDRR6RtEXEC_DRIVERt	Exceptiontstop(RR7RURVRWR4tpreserve_stateRNRORPRXt
orig_stateR,R%((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_runs4

cC@sUytt|�jd��SWn1ttfk
rP}tdj||���nXdS(u�
    Returns the PID of a container

    name
        Container name

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.pid arch1
    uPIDu*Unable to get PID for container '{0}': {1}N(RHtinfoR9t	TypeErrorRIRR(RR,((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytpidLs
c

C@sCt||dd
d|d|d|d|d|d|d|d	|	�	S(uL
    Run :mod:`cmd.run <salt.modules.cmdmod.run>` within a container

    name
        Name of the container in which to run the command

    cmd
        Command to run

    no_start : False
        If the container is not running, don't start it

    preserve_state : True
        After running the command, return the container to its previous state

    stdin : None
        Standard input to be used for the command

    output_loglevel : debug
        Level at which to log the output from the command. Set to ``quiet`` to
        suppress logging.

    use_vt : False
        Use SaltStack's utils.vt to stream output to console.

    keep_env : None
        If not passed, only a sane default PATH environment variable will be
        set. If ``True``, all environment variables from the container's host
        will be kept. Otherwise, a comma-separated list (or Python list) of
        environment variable names can be passed, and those environment
        variables will be kept.

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.run mycontainer 'ifconfig -a'
    RURVR\RWR4RNRPRORXN(R^R(
RR7RVR\RWR4RNRPRORX((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytrunbs0c

C@sCt||ddd|d|d|d|d|d|d	|d
|	�	S(u�
    Run :mod:`cmd.run_stdout <salt.modules.cmdmod.run_stdout>` within a container

    name
        Name of the container in which to run the command

    cmd
        Command to run

    no_start : False
        If the container is not running, don't start it

    preserve_state : True
        After running the command, return the container to its previous state

    stdin : None
        Standard input to be used for the command

    output_loglevel : debug
        Level at which to log the output from the command. Set to ``quiet`` to
        suppress logging.

    use_vt : False
        Use SaltStack's utils.vt to stream output to console. Assumes
        ``output=all``.

    keep_env : None
        If not passed, only a sane default PATH environment variable will be
        set. If ``True``, all environment variables from the container's host
        will be kept. Otherwise, a comma-separated list (or Python list) of
        environment variable names can be passed, and those environment
        variables will be kept.


    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.run_stdout mycontainer 'ifconfig -a'
    RUustdoutRVR\RWR4RNRPRORX(R^(
RR7RVR\RWR4RNRPRORX((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt
run_stdout�s2c

C@sCt||ddd|d|d|d|d|d|d	|d
|	�	S(u�
    Run :mod:`cmd.run_stderr <salt.modules.cmdmod.run_stderr>` within a container

    name
        Name of the container in which to run the command

    cmd
        Command to run

    no_start : False
        If the container is not running, don't start it

    preserve_state : True
        After running the command, return the container to its previous state

    stdin : None
        Standard input to be used for the command

    output_loglevel : debug
        Level at which to log the output from the command. Set to ``quiet`` to
        suppress logging.

    use_vt : False
        Use SaltStack's utils.vt to stream output to console. Assumes
        ``output=all``.

    keep_env : None
        If not passed, only a sane default PATH environment variable will be
        set. If ``True``, all environment variables from the container's host
        will be kept. Otherwise, a comma-separated list (or Python list) of
        environment variable names can be passed, and those environment
        variables will be kept.


    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.run_stderr mycontainer 'ip addr show'
    RUustderrRVR\RWR4RNRPRORX(R^(
RR7RVR\RWR4RNRPRORX((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt
run_stderr�s2c

C@sCt||ddd|d|d|d|d|d|d	|d
|	�	S(uz
    Run :mod:`cmd.retcode <salt.modules.cmdmod.retcode>` within a container

    name
        Name of the container in which to run the command

    cmd
        Command to run

    no_start : False
        If the container is not running, don't start it

    preserve_state : True
        After running the command, return the container to its previous state

    stdin : None
        Standard input to be used for the command

    output_loglevel : debug
        Level at which to log the output from the command. Set to ``quiet`` to
        suppress logging.

    use_vt : False
        Use SaltStack's utils.vt to stream output to console. Assumes
        ``output=all``.

    keep_env : None
        If not passed, only a sane default PATH environment variable will be
        set. If ``True``, all environment variables from the container's host
        will be kept. Otherwise, a comma-separated list (or Python list) of
        environment variable names can be passed, and those environment
        variables will be kept.


    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.retcode mycontainer 'ip addr show'
    RUuretcodeRVR\RWR4RNRPRORX(R^(
RR7RVR\RWR4RNRPRORX((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytretcodes2c

C@sCt||ddd|d|d|d|d|d|d	|d
|	�	S(u@
    Run :mod:`cmd.run_all <salt.modules.cmdmod.run_all>` within a container

    .. note::

        While the command is run within the container, it is initiated from the
        host. Therefore, the PID in the return dict is from the host, not from
        the container.

    name
        Name of the container in which to run the command

    cmd
        Command to run

    no_start : False
        If the container is not running, don't start it

    preserve_state : True
        After running the command, return the container to its previous state

    stdin : None
        Standard input to be used for the command

    output_loglevel : debug
        Level at which to log the output from the command. Set to ``quiet`` to
        suppress logging.

    use_vt : False
        Use SaltStack's utils.vt to stream output to console. Assumes
        ``output=all``.

    keep_env : None
        If not passed, only a sane default PATH environment variable will be
        set. If ``True``, all environment variables from the container's host
        will be kept. Otherwise, a comma-separated list (or Python list) of
        environment variable names can be passed, and those environment
        variables will be kept.


    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.run_all mycontainer 'ip addr show'
    RUuallRVR\RWR4RNRPRORX(R^(
RR7RVR\RWR4RNRPRORX((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytrun_all\s8cC@sz|s)tdj�}tjd|�ny$t�dj|�|d|�SWn&tk
rutdj|���nXdS(u3
    Bootstrap a container from package servers, if dist is None the os the
    minion is running as will be created, otherwise the needed bootstrapping
    tools will need to be available on the host.

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.bootstrap_container <name>
    uosu6nspawn.bootstrap: no dist provided, defaulting to '%s'u_bootstrap_{0}R
uUnsupported distribution "{0}"N(RR:RRJtglobalsRtKeyErrorR(RtdistR
((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytbootstrap_container�s$
cC@sYd}t|d�}|rOt|d�}d|kr?d}qUt|d�nd}|S(Niucommand -v salt-minionups auxusalt-minioniu*salt-call --local service.stop salt-minion(ReRc(RR%t
has_miniont	processes((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_needs_install�s	c
C@s�|	d,k	rAytj|	�WqAtk
r=tjd�qAXnt|�}|sWd,S|
ryd|
kr|
d7}
qnd}
|s�d}nt|�}
|
s�|
S|s�t|�}nt}t|dj	t
��dk}tj�}|r�|r�t}n�t
}td|d	|d
|d|d|d
|�}|sE|sE|r�|r�td�}dj	|�}t|dj	|�dt
�tdd|�}tjjd|�}xLdj	|�dj	|�gD],}t||�r�tjd||�t
Sq�Wt||dj	|�dt�t||dtjj|d��t||dtjj|d��t||dtjj|d��|
j	|�}
d j	||
jd!d"�|�}tjd#||�t||d$d%d&t�dk}q�t
}n�tjj|d�}|d'}t||dd(�t||dtjj|d��t||dtjj|d��t|d)dt
�t}tj|�|
d*kr�t|�n|r�t|d+j	t
�dt
�n|S(-u
    Bootstrap a container from package servers, if dist is None the os the
    minion is running as will be created, otherwise the needed bootstrapping
    tools will need to be available on the host.

    CLI Example::

        salt '*' nspawn.bootstrap_salt arch1
    iu{0}u -c {0}u-c {0}ushu
test -e '{0}'iu
seed.mkconfigttmptid_tapprove_keytpub_keytpriv_keyutest.random_hashu/tmp/.c_{0}uinstall -m 0700 -d {0}R4uconfig.gather_bootstrap_scriptt	bootstrapu/tmpumkdir -p {0}u
chmod 700 {0}utmpdir %s creation failed (%s)u{0}/bootstrap.shR*uconfiguminionuprivkeyu
minion.pemupubkeyu
minion.pubu{0} {2}/bootstrap.sh {1}u'u''u Running %s in LXC container '%s'RNuinfoRPupki_diru/etc/salt/minionu,salt-call --local service.enable salt-minionustoppedutouch '{0}'N(RttimetsleepR`R_RGRmREReRtSEED_MARKERttempfiletmkdtempRR6RbR R!R"RcRRtcopy_totreplaceRtconfigt
minion_configR.R/R[(RR{RptinstallRqRrt
bootstrap_urlt
force_installtunconditional_installtbootstrap_delaytbootstrap_argstbootstrap_shelltc_infoR]t
needs_installtseededRnR%t	cfg_filestrstrt	configdirtbs_tdest_dirR7R|tpki_dir((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytbootstrap_salt�s�
	
	

	


		
##


cC@s�g}t�dkrkx�td�dj�D]8}y|j|j�d�Wq,tk
rcq,q,Xq,Wnlt�}yOxHtj|�D]7}tj	j
tj	j||��r�|j|�q�q�WWntk
r�nX|S(ux
    Lists all nspawn containers

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.list_all
    i�ulist-imagesustdouti(
RRRt
splitlinestappendtsplitRKR&R tlistdirR!tisdirR"R+(R%tlinetrootdirtdirname((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytlist_allBs

	!
cC@s`g}xMtd�dj�D]5}y|j|j�d�Wqtk
rQqXqWt|�S(u�
    Lists running nspawn containers

    .. note::

        ``nspawn.list`` also works to list running containers

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.list_running
        salt myminion nspawn.list
    ulistustdouti(RRR�R�R�RKtsorted(R%R�((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytlist_running^s
cC@s ttt��tt���S(u�
    Lists stopped nspawn containers

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.list_stopped
    (R�tsetR�R�(((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytlist_stopped{s
cC@s>dj|�}|tkr#t|S|t�kt|<t|S(u�
    Returns true if the named container exists

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.exists <name>
    unspawn.exists.{0}(RRR�(Rt
contextkey((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyR�s

cC@sMy4dj|�}t|dt�djd�dSWntk
rHdSXdS(u�
    Return state of container (running or stopped)

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.state <name>
    ushow {0} --property=StateROustdoutu=i����ustoppedN(RRRRER�RK(RR7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyRD�s
%
cK@sKtjjj|�}|jdt�}|rCtjjj|�n|sVt|�n|t�krrt	|�nt
dj|��}|ddkr�tdj|���nidd6dd	6td
6dd6}i}t
jd
�}t
jd�}|dj�}t}	d}
x3tt|��D]}|j||�}|r�|j�\}
}|j|
|
�}
|
tkryq$n7|
dkr�y|j�d}Wq�tk
r�q�Xn|
}
|	r�t}	n|||
<q$|
dkr�q$n|j||�r�Pn|	r||
j||j��q$||
||j�g||
<t}	q$W|S(u*
    Return info about a container

    .. note::

        The container must be running for ``machinectl`` to gather information
        about it. If the container is stopped, then this function will start
        it.

    start : False
        If ``True``, then the container will be started to retrieve the info. A
        ``Started`` key will be in the return data if the container was
        started.

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.info arch1
        salt myminion nspawn.info arch1 force_start=False
    ustartu
status {0}uretcodeiu&Unable to get info for container '{0}'uNetwork InterfaceuIfaceuPIDuLeaderuServiceu
Running SinceuSinceu^\s+([A-Za-z]+): (.+)$u[|`]ustdoutN(RR	RRRARtinvalid_kwargsRGR�RFRRRRtretcompileR�RRtlentmatchtgroupsR9R�RKtsearchR�tstripRE(RRtstart_R�tkey_name_mapR%tkv_pairttreetlinest	multilinetcur_keytidxR�tkeytval((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyR_�s`



	

cC@sFdj|�}td|dt�dkrBtjjjtd<tStS(u�
    Set the named container to be launched at boot

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.enable <name>
    u#systemctl enable systemd-nspawn@{0}ucmd.retcodeR4iuretcode(	RR6RRR'R(tEX_UNAVAILABLERRE(RR7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytenable�s
cC@sFdj|�}td|dt�dkrBtjjjtd<tStS(u�
    Set the named container to *not* be launched at boot

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.enable <name>
    u$systemctl disable systemd-nspawn@{0}ucmd.retcodeR4iuretcode(	RR6RRR'R(R�RRE(RR7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytdisables
cC@swt�dkr'tdj|��}n%dj|�}td|dt�}|ddkrstjjjt	d<tSt
S(uz
    Start the named container

    CLI Example:

    .. code-block:: bash

        salt myminion nspawn.start <name>
    i�u	start {0}u"systemctl start systemd-nspawn@{0}ucmd.run_allR4uretcodei(RRRRR6RRR'R(R�RRE(RR%R7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyRF"scC@s�t�dkr?|rd}nd}tdj||��}n%dj|�}td|dt�}|dd	kr�tjjjt	d<tSt
S(
uq
    This is a compatibility function which provides the logic for
    nspawn.poweroff and nspawn.terminate.
    i�u	terminateupoweroffu{0} {1}u!systemctl stop systemd-nspawn@{0}ucmd.run_allR4uretcodei(RRRRR6RRR'R(R�RRE(RtkilltactionR%R7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyR[:s	cC@st|dt�S(uQ
    Issue a clean shutdown to the container.  Equivalent to running
    ``machinectl poweroff`` on the named container.

    For convenience, running ``nspawn.stop``(as shown in the CLI examples
    below) is equivalent to running ``nspawn.poweroff``.

    .. note::

        ``machinectl poweroff`` is only supported in systemd >= 219. On earlier
        systemd versions, running this function will simply issue a clean
        shutdown via ``systemctl``.

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.poweroff arch1
        salt myminion nspawn.stop arch1
    R�(R[R(R((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytpoweroffPscC@st|dt�S(u�
    Kill all processes in the container without issuing a clean shutdown.
    Equivalent to running ``machinectl terminate`` on the named container.

    For convenience, running ``nspawn.stop`` and passing ``kill=True`` (as
    shown in the CLI examples below) is equivalent to running
    ``nspawn.terminate``.

    .. note::

        ``machinectl terminate`` is only supported in systemd >= 219. On
        earlier systemd versions, running this function will simply issue a
        clean shutdown via ``systemctl``.

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.terminate arch1
        salt myminion nspawn.stop arch1 kill=True
    R�(R[RE(R((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt	terminatehscC@s
t|�S(uL
    This is a compatibility function which simply calls nspawn.reboot.
    (treboot(R((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytrestart�scC@s�t�dkrFt|�dkr9tdj|��}q�t|�Snqdj|�}td|dt�}|ddkr�tjj	j
td<tSd	j|�}td|dt�}|ddkr�tjj	j
td<tStS(
ud
    Reboot the container by sending a SIGINT to its init process. Equivalent
    to running ``machinectl reboot`` on the named container.

    For convenience, running ``nspawn.restart`` (as shown in the CLI examples
    below) is equivalent to running ``nspawn.reboot``.

    .. note::

        ``machinectl reboot`` is only supported in systemd >= 219. On earlier
        systemd versions, running this function will instead restart the
        container via ``systemctl``.

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.reboot arch1
        salt myminion nspawn.restart arch1
    i�urunningu
reboot {0}u!systemctl stop systemd-nspawn@{0}ucmd.run_allR4uretcodeiu"systemctl start systemd-nspawn@{0}(
RRDRRRRFR6RRR'R(R�RRE(RR�R%R7((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyR��s
cC@s�|r1t|�dkr1tdj|���nd�}t�dkr�tdj|��}|ddkr�tjjjt	d<|||d�q�nFy#t
jtj
jt�|��Wn tk
r�}|||�nXtS(	u�
    Remove the named container

    .. warning::

        This function will remove all data associated with the container. It
        will not, however, remove the btrfs subvolumes created by pulling
        container images (:mod:`nspawn.pull_raw
        <salt.modules.nspawn.pull_raw>`, :mod:`nspawn.pull_tar
        <salt.modules.nspawn.pull_tar>`, :mod:`nspawn.pull_dkr
        <salt.modules.nspawn.pull_dkr>`).

    stop : False
        If ``True``, the container will be destroyed even if it is
        running/frozen.

    CLI Examples:

    .. code-block:: bash

        salt '*' nspawn.remove foo
        salt '*' nspawn.remove foo stop=True
    ustoppeduContainer '{0}' is not stoppedcS@stdj||���dS(Nu%Unable to remove container '{0}': {1}(RR(RR,((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_failed_remove�si�u
remove {0}uretcodeiustderr(RDRRRRRRR'R(R�RR.R/R R!R"R&R+RE(RR[R�R%R,((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytremove�s	#udestroycC@s�|}yJ|jd�rOtd|�}|sFtdj|���n|}nWn&tk
rxtdj|���nXt�dkr�ntd|||dtdtd	|d
|�S(u^
    Copy a file from the host into a container

    name
        Container name

    source
        File to be copied to the container

    dest
        Destination on the container. Must be an absolute path.

    overwrite : False
        Unless this option is set to ``True``, then if a file exists at the
        location specified by the ``dest`` argument, an error will be raised.

    makedirs : False

        Create the parent directory on the container if it does not already
        exist.

    CLI Example:

    .. code-block:: bash

        salt 'minion' nspawn.copy_to /tmp/foo /root/foo
    usalt://u
cp.cache_fileuUnable to cache {0}uInvalid source file {0}i�ucontainer_resource.copy_toRSRTt	overwriteR*(	R?R6RRtAttributeErrorRRRRY(RtsourcetdestR�R*R!t
cached_source((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyRy�s(

ucpcK@sBtd�t|�r.tdj|���n|dkrCd}n*|dkrXd}ntdj|���tjjj|�}tgt	j
tjjj|��D]$\}}||kr�||f^q��}|r�tjjj|�ng}|dkr�|jdt
�}	|	s'|jd	�q�d
�}
y|	j�}	Wntk
rZ|
�q�X|	dkrq|
�n|jd
j|	��n8|dkr�d|kr�|jdj|d��q�ndj|dj|�||�}t|dt�}|ddkr>d}
|dr/|
dj|d�7}
nt|
��ntS(u5
    Common logic for machinectl pull-* commands
    i�uContainer '{0}' already existsurawutaruverifyudkruindexuUnsupported image type '{0}'u--verify=nocS@std��dS(Nu:'verify' must be one of the following: signature, checksum(R(((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_bad_verifyNsu	signatureuchecksumu--verify={0}u--dkr-index-url={0}upull-{0} {1} {2} {3}u RPuretcodeiuMError occurred pulling image. Stderr from the pull command (if any) follows: ustderru

{0}(urawutar(uverify(uindex(urawutar(u	signatureuchecksum(RMRRRRR	RRtdictRt	iteritemsR�R9RR�R:R�R"RRRER(t	pull_typetimageRRtvalid_kwargsR$tyt
bad_kwargst	pull_optstverifyR�R7tresulttmsg((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt_pull_image,sR
		+!	

 
cC@std||d|�S(u�
    Execute a ``machinectl pull-raw`` to download a .qcow2 or raw disk image,
    and add it to /var/lib/machines as a new container.

    .. note::

        **Requires systemd >= 219**

    url
        URL from which to download the container

    name
        Name for the new container

    verify : False
        Perform signature or checksum verification on the container. See the
        ``machinectl(1)`` man page (section titled "Image Transfer Commands")
        for more information on requirements for image verification. To perform
        signature verification, use ``verify=signature``. For checksum
        verification, use ``verify=checksum``. By default, no verification will
        be performed.

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.pull_raw http://ftp.halifax.rwth-aachen.de/fedora/linux/releases/21/Cloud/Images/x86_64/Fedora-Cloud-Base-20141203-21.x86_64.raw.xz fedora21
    urawR�(R�(turlRR�((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytpull_rawoscC@std||d|�S(ue
    Execute a ``machinectl pull-raw`` to download a .tar container image,
    and add it to /var/lib/machines as a new container.

    .. note::

        **Requires systemd >= 219**

    url
        URL from which to download the container

    name
        Name for the new container

    verify : False
        Perform signature or checksum verification on the container. See the
        ``machinectl(1)`` man page (section titled "Image Transfer Commands")
        for more information on requirements for image verification. To perform
        signature verification, use ``verify=signature``. For checksum
        verification, use ``verify=checksum``. By default, no verification will
        be performed.

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.pull_tar http://foo.domain.tld/containers/archlinux-2015.02.01.tar.gz arch2
    utarR�(R�(R�RR�((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytpull_tar�scC@std||d|�S(uu
    Execute a ``machinectl pull-dkr`` to download a docker image and add it to
    /var/lib/machines as a new container.

    .. note::

        **Requires systemd >= 219**

    url
        URL from which to download the container

    name
        Name for the new container

    index
        URL of the Docker index server from which to pull (must be an
        ``http://`` or ``https://`` URL).

    CLI Examples:

    .. code-block:: bash

        salt myminion nspawn.pull_dkr centos/centos6 cent6 index=https://get.docker.com
        salt myminion nspawn.pull_docker centos/centos6 cent6 index=https://get.docker.com
    udkrtindex(R�(R�RR�((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pytpull_dkr�supull_docker(Wt__doc__t
__future__RRRR0RtloggingR R�R.RtRwtsalt.defaults.exitcodesRtsalt.utils.argstsalt.utils.functoolstsalt.utils.pathtsalt.utils.systemdtsalt.exceptionsRRtsalt.extRtsalt.ext.six.movesRt	getLoggert__name__Rt__func_alias__RRvtWANTRYRRRRR&R-R3R8R<R=R>RCRGRMRRRRER^RaRbRcRdReRfRjRmR�R�R�R	talias_functiontlist_R�RRDR_R�R�RFR[R�R�R�R�R�tdestroyRytcpR�R�R�R�tpull_docker(((s7/usr/lib/python2.7/site-packages/salt/modules/nspawn.pyt<module>s
													
	$6888<	o			
		S			205	C  	

Zerion Mini Shell 1.0