HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib64/python3.10/site-packages/docker/context/__pycache__/api.cpython-310.pyc
o

�h��@sRddlZddlZddlmZddlmZmZmZmZddl	m
Z
Gdd�d�ZdS)�N)�errors�)�METAFILE�get_current_context_name�get_meta_dir�#write_context_name_to_docker_config)�Contextc@szeZdZdZedd�Ze		ddd��Zeddd	��Zed
d��Z	edd
��Z
eddd��Zedd��Zeddd��Z
dS)�
ContextAPIzfContext API.
    Contains methods for context management:
    create, list, remove, get, inspect.
    �default�swarmNFc	Csv|st�d��|dkrt�d��t�|�}|rt�|��d}|r&|dkr&|}t||�}|j|||||d�|��|S)aRCreates a new context.
        Returns:
            (Context): a Context object.
        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextAlreadyExists`
                If a context with the name already exists.
            :py:class:`docker.errors.ContextException`
                If name is default.

        Example:

        >>> from docker.context import ContextAPI
        >>> ctx = ContextAPI.create_context(name='test')
        >>> print(ctx.Metadata)
        {
            "Name": "test",
            "Metadata": {},
            "Endpoints": {
                "docker": {
                    "Host": "unix:///var/run/docker.sock",
                    "SkipTLSVerify": false
                }
            }
        }
        �namer
z$"default" is a reserved context name�dockerr)�skip_tls_verify�
def_namespace)r�MissingContextParameter�ContextExceptionr�load_context�ContextAlreadyExists�set_endpoint�save)	�clsr�orchestrator�host�tls_cfg�default_namespacer�ctx�endpoint�r�E/usr/local/CyberCP/lib/python3.10/site-packages/docker/context/api.py�create_contexts(
�


�zContextAPI.create_contextcCs"|st�}|dkr|jSt�|�S)a�Retrieves a context object.
        Args:
            name (str): The name of the context

        Example:

        >>> from docker.context import ContextAPI
        >>> ctx = ContextAPI.get_context(name='test')
        >>> print(ctx.Metadata)
        {
            "Name": "test",
            "Metadata": {},
            "Endpoints": {
                "docker": {
                "Host": "unix:///var/run/docker.sock",
                "SkipTLSVerify": false
                }
            }
        }
        r
)r�DEFAULT_CONTEXTrr)rrrrr�get_contextHs

zContextAPI.get_contextc
Cs�g}t�t��D]>\}}}||D]4}|tkrEzt�ttj�||���}|�	|d�Wqt
yD}zt�d|�d|���|�d}~wwqq|j
g}|D]
}	|�	t�|	��qM|S)z�Context list.
        Returns:
            (Context): List of context objects.
        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �NamezFailed to load metafile z: N)�os�walkrr�json�load�open�path�join�append�	Exceptionrrr rr)
r�names�dirname�dirnames�fnames�filename�data�e�contextsrrrrr3ds.	�������zContextAPI.contextscCs|��S)z]Get current context.
        Returns:
            (Context): current context object.
        )r!)rrrr�get_current_contextszContextAPI.get_current_contextcCs8|�|�}|st�|��t|�}|rt�d|����dS)NzFailed to set current context: )r!r�ContextNotFoundrr)rrr�errrrr�set_current_context�s

��zContextAPI.set_current_contextcCsV|st�d��|dkrt�d��t�|�}|st�|��|t�kr%td�|��dS)aYRemove a context. Similar to the ``docker context rm`` command.

        Args:
            name (str): The name of the context

        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextNotFound`
                If a context with the name does not exist.
            :py:class:`docker.errors.ContextException`
                If name is default.

        Example:

        >>> from docker.context import ContextAPI
        >>> ContextAPI.remove_context(name='test')
        >>>
        rr
z#context "default" cannot be removedN)	rrrrrr5rr�remove�rrrrrr�remove_context�s
�


zContextAPI.remove_contextcCs<|st�d��|dkr|��St�|�}|st�|��|�S)aRemove a context. Similar to the ``docker context inspect`` command.

        Args:
            name (str): The name of the context

        Raises:
            :py:class:`docker.errors.MissingContextParameter`
                If a context name is not provided.
            :py:class:`docker.errors.ContextNotFound`
                If a context with the name does not exist.

        Example:

        >>> from docker.context import ContextAPI
        >>> ContextAPI.remove_context(name='test')
        >>>
        rr
)rrr rrr5r9rrr�inspect_context�s


zContextAPI.inspect_context)NNNNF)N)r
)�__name__�
__module__�__qualname__�__doc__rr �classmethodrr!r3r4r7r:r;rrrrr	s&
�1



 r	)r%r#r
r�configrrrr�contextrr	rrrr�<module>s