HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/__pycache__/lxc.cpython-310.pyc
o

�N�ghH�@s
dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
mZe�e�ZddiZd#dd�Zd#dd	�Zd$dd�Zd#d
d�Zd%dd�Zd&dd�Zd'dd�Zd(dd�Zd)dd�Zd$dd�Zd$dd�Zd$dd�Zd$dd �Z d$d!d"�Z!dS)*zC
Control Linux Containers via Salt

:depends: lxc execution module
�N)�OrderedDict�list_�listcCs�t|d|d�}|sdStj�td��.}|j|d|��|gd|idd�}t|�}|�|i��d	d
�}|r8||i}|Wd
�S1sDwYd
S)��
    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
    T��quiet�pathF�	conf_file�lxc.r�<��kwarg�timeout�retN)�
find_guest�salt�client�get_local_client�__opts__�cmd_iter�next�get)�name�funr�hostrZcmd_ret�data�r�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/lxc.py�_dos
�$�rcCs�i}t||d�}|sdStj�td��I}|��D]:\}}g}|D]}	|�|j|d|��|	gd|idd��q!|D]}
t|
�}|�	|i��	dd	�}|rR|�
||i�q9q|Wd	�S1s`wYd	S)
r�rFr	r
rrrrN)�find_guestsrrrr�items�appendrrr�update)�namesrrr�hostsrrZ	sub_names�cmdsr�cmdrrrr�	_do_names4s4
��	��$�r(FcCsn|rt�d�t|d�D](}tt|����\}}dD]}|||vr3|s-t�|dd�d�|SqqdS)z�
    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
    �?'quiet' argument is being deprecated. Please migrate to --quietr)Zrunning�frozen�stoppedZ
lxc_find_host�rZ	outputter�progressN)�log�warning�
_list_iterr�iterr!�
__jid_event__�
fire_event)rrrrr�l�xrrrrXs

���rcCsxi}|�d�}t|d�D]-}tt|����\}}|D]}||D]}||vr7||vr2||�|�q |g||<q qq|S)z�
    Return a dict of hosts and named guests

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

        .. versionadded:: 2015.8.0

    �,r)�splitr0rr1r!r")r$rrrr�stat�staterrrrr us

���r c,
sH|�dd�}|r
t�d�ddd�}|dur d|d<d	|d
<|St|t�r*|�d�}t|t�s9d|d<d	|d
<|Sd	}tj�	t
d
���Չz�j|ddd��|d�rTd}Wntt
fy`Ynw|sxd|�d�|d<d	|d
<|Wd�St�d�td|d|d�}|��D]\}}	|D]}
|
t|	��g�vr�t�d|
|�q�q�||vr�d|�d�|d<d	|d
<|Wd�Stjjjd:i|��}|�dd�}|�dd�}
|o�|
}|�dd�}i}|�dd�}|�re|�setj�t
��k}|���dg�}|D]X}
|}|
|v�r#z�j|
ddd��|
d��rd	}Wntt
f�y"Ynw|||
<tjj�||
t
�}|���r;t�d�q�d|d<d	|d
<|Wd�Wd�SWd�n	1�s`wYt�d ||�g}|D]]}
|
g}tjjjd:i|��}|�r�t�|�}|
|d!<|}�j|d"||gd#d$d%��|i�}|�|�|�d!|
�}
|�|
|�|d<|d�s�|�d&d�|� ||
�j!|d'||d$d(�f��qp|�"d)g�}|�"d*t#��}t$|�D]v\}}|\}}}|�"|g�}	|�"|t#��} | �"|g�}!t%|�}"d}#t|"t&��r1||"v�r1|"|}$|$�d+i�}%|%�r)t|%t&��r)|%�d
d	��s(|%}#nd,�'||%|"�}#n|"}#|#�s8d-}#|#�rFd	|d
<|!� |#��q�|
|%d.<|	� |%�|� |%��q�t(t)|��|d/<|D]�}%|%d.}t*j+�,t
d0d|�}&|�r�d}'t*j+�-|&��r�tjj.�/|&��}(tjj0�1|(�2���3�}'Wd�n	1�s�wYtjj0�1|�}|�3�|'k�r�tjj.�/|&d1��}(|(�4tjj0�5|��|(�6�Wd�n	1�s�wY|$�d2d�})|)�sߐq`�fd3d4�}*tjj7j8|*d5|)d6�}+|+d7k�r�d	|d/<d	|d
<�q`|�sd	|d
<|�st9�:d8|id9�|Wd�S1�swYdS);a*	
    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.
    rNr)�T)�comment�resultzA host must be providedr;Fr<r6z(Container names are not formed as a listr	�	test.ping��rzHost z is not reachablezSearching for LXC Hosts�lxc.listrz?Container '%s' already exists on host '%s', init can be a NO-OPzHost 'z' was not found�pub_key�priv_key�approve_key�seedZminionsz#Container key will be preauthorizedz%Container key preauthorization failedz'Creating container(s) '%s' on host '%s'rzlxc.cloud_init_interfaceriX)Ztgt_typerZseed_cmd�lxc.initr�done�errorsrzInvalid return for {}: {} {}zunknown error (no return)�container_nameZping_statusZpki_dir�w�midcs8|d}�j|ddd�}t�d�|rdStd|����)NrJr=r>r?��OKz
Unresponsive )r'�time�sleep�	Exception)�kwZmid_�ping�rrr�testping�s
zinit.<locals>.testping�)rrJrL�messager-r);rr.r/�
isinstance�strr7rrrrrr'�	TypeError�KeyError�info�__salt__r!�sum�values�utils�argsZclean_kwargs�key�KeyZall_keysZvirtZVirtKeyZ	authorize�copy�deepcopyr#�popr"r�
setdefault�_OrderedDict�	enumerater�dict�format�bool�len�osr�join�exists�filesZfopenZstringutilsZ
to_unicode�read�strip�writeZto_str�flushZcloudZwait_for_funr2r3),r$r�saltcloud_moder�kwargsrr�aliverZ
containersrrPrArBZ
explicit_authrCZseedsZseed_arg�skeyZall_minionsrDZkvr&r_Zsaved_kwargsrFrGZixZacmdZhstrHr'ZherrsZserrsZsub_ret�errorZj_ret�	containerr`ZfcontentZficrJrSrQrrRr�init�sNT




���
����
���
��%�
��

��
��
�
�
��&�rzcKs*|rt�d�tdd||d|d�|��S)a�
    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
    r)rET)r$rrtrNr)r.r/r[)r$rrrurrr�
cloud_init�s
��r{ccs��|pd}tj�td��T}|j|dd|id�D]@}|sqt|t�s#qi}tt|�	���}|r4||kr4qt||t�s<qd||vrCqt||dt�sMq||d||<|VqWd�dS1sdwYdS)z�
    Return a generator iterating over hosts

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

        .. versionadded:: 2015.8.0
    �*r	r@r)r
rN)
rrrrrrVrhrr1�keys)rrZtgtrZcontainer_info�chunkZid_rrrr0�s,�

�"�r0cCs>t||d�}i}|D]}|�|�|st�|dd�d�q
|S)a,
    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]
    rZlxc_listr,r-)r0r#r2r3)rrr�itrr~rrrr�s

��TcCszt|d|d�}|dur
|S|r*tj�t��
}|�|�Wd�n1s%wY|dur0dS|s;t�|dd�d�|S)aD
    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
    ZdestroyrFNZ	lxc_purger,r-)r(rr`rar�
delete_keyr2r3)rr�rrrrwrrr�purge�s�r�cC�,t|d|d�}|r|st�|dd�d�|S)z�
    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
    �startrZ	lxc_startr,r-�r(r2r3�rrrrrrrr��r�cCr�)z�
    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
    �stoprZ
lxc_force_offr,r-r�r�rrrr� s
�r�cCs(t|d�}|r|st�|dd�d�|S)z�
    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
    �freezeZ	lxc_pauser,r-r�r�rrrr�6s
r�cCr�)z�
    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
    �unfreezerZ
lxc_resumer,r-r�r�rrrr�Jr�r�cCr�)z�
    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
    rZrZlxc_infor,r-r�r�rrrrZ^r�rZ)N)FN)NFF)NF)NN)NFN)TFN)"�__doc__rb�loggingrlrMZsalt.clientrZsalt.keyZsalt.utils.argsZsalt.utils.cloudZsalt.utils.filesZsalt.utils.stringutilsZsalt.utils.virtZsalt.utils.odictrrf�	getLogger�__name__r.Z__func_alias__rr(rr rzr{r0rr�r�r�r�r�rZrrrr�<module>s>



$