%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/runners/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/runners/lxc.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlZ
ddlZ
ddlmZddlmZeje�Zidd6Zed�Zed	�Zeed
�Zed�Zeeed�Z eed
�Z!eed�Z"eeed�Z#e$eed�Z%eed�Z&eed�Z'eed�Z(eed�Z)eed�Z*dS(uC
Control Linux Containers via Salt

:depends: lxc execution module
i(tabsolute_importtprint_functiontunicode_literalsN(tOrderedDict(tsixulistulist_cC@s�t|dtd|�}|s"tStjjtd�}|j|dj|�|gdi|d6dd�}t	|�}|j
|i�j
d	d
�}|r�i||6}n|S(u�
    Invoke a function in the lxc module with no args

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0
    tquiettpathu	conf_fileulxc.{0}tkwargupathttimeouti<uretN(t
find_guesttTruetFalsetsalttclienttget_local_clientt__opts__tcmd_itertformattnexttgettNone(tnametfunRthostR
tcmd_rettdata((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyt_do$s
	
	cC@si}t|d|�}|s"tStjjtd�}x�tj|�D]�\}}g}xI|D]A}	|j|j	|dj
|�|	gdi|d6dd��qaWxU|D]M}
t|
�}|j|i�jdd	�}|r�|ji||6�q�q�WqHW|S(
u�
    Invoke a function in the lxc module with no args

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0
    Ru	conf_fileulxc.{0}RupathRi<uretN(tfind_guestsRRR
RRRt	iteritemstappendRRRRRtupdate(tnamesRRtretthostsR
Rt	sub_namestcmdsRtcmdR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyt	_do_names@s(

	

cC@s�|rtjd�nx~td|�D]m}ttj|��\}}xId
D]A}|||krN|s�tji|d6dd6d	�n|SqNWq&WdS(u�
    Returns the host for a container.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0


    .. code-block:: bash

        salt-run lxc.find_guest name
    u?'quiet' argument is being deprecated. Please migrate to --quietRurunningufrozenustoppedudatau
lxc_find_hostu	outputteruprogress(urunningufrozenustoppedN(	tlogtwarningt
_list_iterRRRt
__jid_event__t
fire_eventR(RRRRRtltx((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyR	as


cC@s�i}|jd�}x�td|�D]�}ttj|��\}}x_|D]W}xN||D]B}||kr^||kr�||j|�q�|g||<q^q^WqMWq%W|S(u�
    Return a dict of hosts and named guests

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    u,R(tsplitR(RRRR(RRR RRtstattstateR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyR�s
c,@s�|jdd,�}|r(tjd�nidd6td6}|d,kr`d|d<t|d<|St|tj�r�|j	d�}nt|t
�s�d|d<t|d<|Stjj
td	��t}y1�j|d
dd�j|d,�r�t}nWnttfk
rnX|s9d
j|�|d<t|d<|Stjd�td|dtd|�}xbtj|�D]Q\}}	xB|D]:}
|
ttj|	�g�kr�tjd|
|�q�q�WqrW||kr�dj|�|d<t|d<|Stjjj|�}|jdd,�}|jdd,�}
|o6|
}|jdt�}i}|jdt�}|rg|rgtjjt�}|j�jdg�}x�|D]�}
|}|
|kry1�j|
d
dd�j|
d,�r�t}nWqttfk
rqXn|||
<tjjj||
t�}|j �rHtjd�q�d|d<t|d<|Sq�Wntjd||�g}x|D]}
|
g}tjjj|�}|rt!j"|�}|
|d<|}�j|d||gdddd �j|i�}|j#|�n|j$d|
�}
|j|
|�|d<|dsY|j$d!d�n|j%||
�j&|d"|d#|dd �f�q�W|j'd$g�}|j'd%t(��}xOt)|�D]A\}}|\}}}|j'|g�}	|j'|t(��} | j'|g�}!t*|�}"d,}#t|"t+�r�||"kr�|"|}$|$jd&i�}%|%r�t|%t+�r�|%jdt�s�|%}#q�q�d'j||%|"�}#n|"}#|#s�d(}#n|#r�t|d<|!j%|#�q�|
|%d)<|	j%|%�|j%|%�q�Wt,t-|��|d*<xy|D]q}%|%d)}t.j/j0td+d|�}&|r$d}'t.j/j1|&�r�tjj2j3|&��(}(tjj4j5|(j6��j7�}'Wd,QXntjj4j5|�}|j7�|'kr$tjj2j3|&d-��-}(|(j8tjj4j9|��|(j:�Wd,QXq$n|$jd.d,�})|)sBq$n�fd/�}*tjj;j<|*dd0d1|)�}+|+d2kr$t|d*<t|d<q$q$W|s�t|d<n|s�t=j>i|d36d4�n|S(5u*	
    Initialize a new container


    .. code-block:: bash

        salt-run lxc.init name host=minion_id [cpuset=cgroups_cpuset] \
                [cpushare=cgroups_cpushare] [memory=cgroups_memory] \
                [template=lxc_template_name] [clone=original name] \
                [profile=lxc_profile] [network_proflile=network_profile] \
                [nic=network_profile] [nic_opts=nic_opts] \
                [start=(true|false)] [seed=(true|false)] \
                [install=(true|false)] [config=minion_config] \
                [snapshot=(true|false)]

    names
        Name of the containers, supports a single name or a comma delimited
        list of names.

    host
        Minion on which to initialize the container **(required)**

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    saltcloud_mode
        init the container with the saltcloud opts format instead
        See lxc.init_interface module documentation

    cpuset
        cgroups cpuset.

    cpushare
        cgroups cpu shares.

    memory
        cgroups memory limit, in MB

        .. versionchanged:: 2015.5.0
            If no value is passed, no limit is set. In earlier Salt versions,
            not passing this value causes a 1024MB memory limit to be set, and
            it was necessary to pass ``memory=0`` to set no limit.

    template
        Name of LXC template on which to base this container

    clone
        Clone this container from an existing container

    profile
        A LXC profile (defined in config or pillar).

    network_profile
        Network profile to use for the container

        .. versionadded:: 2015.5.2

    nic
        .. deprecated:: 2015.5.0
            Use ``network_profile`` instead

    nic_opts
        Extra options for network interfaces. E.g.:

        ``{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1", "ipv6": "2001:db8::ff00:42:8329"}}``

    start
        Start the newly created container.

    seed
        Seed the container with the minion config and autosign its key.
        Default: true

    install
        If salt-minion is not already installed, install it. Default: true

    config
        Optional config parameters. By default, the id is set to
        the name of the container.
    upathu?'quiet' argument is being deprecated. Please migrate to --quietuucommenturesultuA host must be providedu,u(Container names are not formed as a listu	conf_fileu	test.pingRiuHost {0} is not reachableuSearching for LXC Hostsulxc.listRRu?Container '%s' already exists on host '%s', init can be a NO-OPuHost '{0}' was not foundupub_keyupriv_keyuapprove_keyuseeduminionsu#Container key will be preauthorizedu%Container key preauthorization failedu'Creating container(s) '%s' on host '%s'unameulxc.cloud_init_interfacettgt_typeulistiXuseed_cmdulxc.initRudoneuerrorsuretuInvalid return for {0}: {1} {2}uunknown error (no return)ucontainer_nameuping_statusupki_dirNuwumidc@sR|d}�j|ddd�}tjd�|r9dStdj|���dS(Numidu	test.pingRiiuOKuUnresponsive {0}(R$ttimetsleept	ExceptionR(tkwtmid_tping(R
(s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyttestping�s

itmiduOKumessageuprogress(?RRR&R'R
Rt
isinstanceRtstring_typesR-tlistRR
RRR$t	TypeErrortKeyErrorRtinfot__salt__Rtsumt
itervaluestutilstargstclean_kwargstkeytKeytall_keystvirttVirtKeyt	authorizetcopytdeepcopyRtpopRRt
setdefaultt_OrderedDictt	enumerateRtdicttbooltlentosRtjointexiststfilestfopentstringutilst
to_unicodetreadtstriptwritetto_strtflushtcloudtwait_for_funR)R*(,RRtsaltcloud_modeRtkwargsRR taliveRt
containersRR4tpub_keytpriv_keyt
explicit_authtapprove_keytseedstseed_argtskeytall_minionstseedtkvR#RCtsaved_kwargstdoneterrorstixtacmdthsttcontainer_nameR$therrstserrstsub_retterrortj_rett	containerREtfcontenttficR8R7R6((R
s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytinit�sT



$






$




	

)
	




*!

c
K@s<|rtjd�ntdd|d|dtd||�S(u�
    Wrapper for using lxc.init in saltcloud compatibility mode

    names
        Name of the containers, supports a single name or a comma delimited
        list of names.

    host
        Minion to start the container on. Required.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    saltcloud_mode
        init the container with the saltcloud opts format instead
    u?'quiet' argument is being deprecated. Please migrate to --quietulxc.initRRRbR(R&R'R?R
(RRRRc((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyt
cloud_init�scc@s|p	d}tjjtd�}x�|j|ddi|d6�D]�}|sTqBnt|t�siqBni}ttj	|��}|r�||kr�qBnt||t�s�qBnd||kr�qBnt||dt�s�qBn||d||<|VqBWdS(u�
    Return a generator iterating over hosts

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0
    u*u	conf_fileulxc.listRupathuretN(
RR
RRRR9RQRRtiterkeys(RRttgtR
tcontainer_infotchunktid_((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyR(�s(
	cC@sat|d|�}i}xB|D]:}|j|�|stji|d6dd6d�qqW|S(u,
    List defined containers (running, stopped, and frozen) for the named
    (or all) host(s).

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.list [host=minion_id]
    Rudataulxc_listu	outputteruprogress(R(RR)R*(RRRtitR R�((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytlist_�s

cC@s�t|dd|�}|tkr%|S|rMtjjt�}|j|�n|dkr]dS|s�tj	i|d6dd6d�n|S(uD
    Purge the named container and delete its minion key if present.
    WARNING: Destroys all data associated with the container.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.purge name
    udestroyRNudatau	lxc_purgeu	outputteruprogress(
R%RRRERFRt
delete_keyRR)R*(RR�RRRRl((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytpurge�scC@sGt|dd|�}|rC|rCtji|d6dd6d�n|S(u�
    Start the named container.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.start name
    ustartRudatau	lxc_startu	outputteruprogress(R%R)R*(RRRR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytstarts

cC@sGt|dd|�}|rC|rCtji|d6dd6d�n|S(u�
    Stop the named container.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.stop name
    ustopRudatau
lxc_force_offu	outputteruprogress(R%R)R*(RRRR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytstop!s

cC@sAt|d�}|r=|r=tji|d6dd6d�n|S(u�
    Freeze the named container

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.freeze name
    ufreezeudatau	lxc_pauseu	outputteruprogress(R%R)R*(RRRR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytfreeze6s

cC@sGt|dd|�}|rC|rCtji|d6dd6d�n|S(u�
    Unfreeze the named container

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.unfreeze name
    uunfreezeRudatau
lxc_resumeu	outputteruprogress(R%R)R*(RRRR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pytunfreezeKs

cC@sGt|dd|�}|rC|rCtji|d6dd6d�n|S(u�
    Returns information about a container.

    path
        path to the container parent
        default: /var/lib/lxc (system default)

        .. versionadded:: 2015.8.0

    .. code-block:: bash

        salt-run lxc.info name
    uinfoRudataulxc_infou	outputteruprogress(R%R)R*(RRRR((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyR>`s

(+t__doc__t
__future__RRRR1RTRKtloggingtsalt.clientRtsalt.utils.argstsalt.utils.cloudtsalt.utils.filestsalt.utils.stringutilstsalt.utils.virttsalt.keytsalt.utils.odictRROtsalt.extRt	getLoggert__name__R&t__func_alias__RRR%RR	RRR�R(R�R
R�R�R�R�R�R>(((s4/usr/lib/python2.7/site-packages/salt/runners/lxc.pyt<module>s>
!�! 

Zerion Mini Shell 1.0