File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/dockermod.cpython-310.pyc
Back
o ;jɅ � @ sZ d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlZddlZddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZ ddlmZ ddlmZ dZ zddl!Z!dZ"W n e#y� dZ"Y nw zddl$Z$dZ%W n e#y� dZ%Y nw zddl&Z&dZ'W n e#y� dZ'Y nw e(ej)j*�+d ��Z,e�-e.�Z/d ddd dddd�Z0dZ1dZ2dZ3e4� Z5dZ6dZ7dgZ8dddd�Z9dd� Z:dd� Z;G dd� dej<�Z=dd � Z>e5fd!d"�Z?d#d$� Z@d%d&� ZAd'd(� ZBd)d*� ZCd+d,� ZDd-d.� ZEd/d0� ZFd1d2� ZGd�d3d4�ZHd5d6� ZId7d8� ZJd9d:� ZKd;d<� ZLeAd=d>� �ZMd?d@� ZNdAdB� ZOdCdD� ZPdEdF� ZQdGdH� ZRd�dIdJ�ZS d�dKdL�ZTd�dMdN�ZUej)j�VeUdO�ZWdPdQ� ZXd�dSdT�ZY�d dUdV�ZZdWdX� Z[dYdZ� Z\d[d\� Z]d]d^� Z^d_d`� Z_�d dadb�Z`�d dcdd�Zadedf� Zbdgdh� Zcdidj� Zddkdl� Zedmdn� Zfdodp� Zgdqdr� Zhdsdt� Zidudv� Zjdwdx� Zkd�dydz�Zld�d{d|�Zmd}d~� Zn�ddd��Zod�d�� Zpd�d�� Zqd�d�� ZreBdddddej)jsjtfd�d���ZueBddddej)jsjtddddf d�d���Zv�dd�d��Zwej)j�Vewd��Zx�dd�d��Zy�dd�d��ZzeB�dd�d���Z{d�d�� Z| �dd�d��Z}�dd�d��Z~�dd�d��Z�dd�d��Z��dd�d��Z�d�d�� Z�ddej)jsjtfd�d��Z�ddej)jsjtfd�d��Z�d�d�� Z��dd�d��Z��dd�d��Z��dd�d��Z�dddej)jsjtfd�d��Z�d�d�� Z�d�d�� Z�d�d�� Z�d�d�� Z�d�d�� Z�d�d�d��Z��dd�d��Z�d�d�� Z�d�d Z�eBd�dĄ �Z�eBd�dƄ �Z�ej)j�Ve�dǡZ��dd�dʄZ�eBd�d̄ �Z�eBd�d΄ �Z�eBd�d�dЄ�Z�eBd�d҄ �Z�ej)j�Ve�dӡZ��dd�dՄZ� �d d�dׄZ�eB � �d d�dڄ�Z�eB � � �dd�d݄�Z� � �dd�d߄Z� � �dd�d�Z� � �dd�d�Z� � �dd�d�Z� � �dd�d�Z� � � �dd�d�Z� � � �dd�d�Z�d�d� Z��d d�d�Z�d�d�d�Z�d�d� Z�d�d�d��Z�d�d�d��Z��dd�d�Z� �dd�d��Z�dS ( a~ Management of Docker Containers .. versionadded:: 2015.8.0 .. versionchanged:: 2017.7.0 This module has replaced the legacy docker execution module. :depends: docker_ Python module .. _`create_container()`: http://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.create_container .. _`create_host_config()`: http://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.create_host_config .. _`connect_container_to_network()`: http://docker-py.readthedocs.io/en/stable/api.html#docker.api.network.NetworkApiMixin.connect_container_to_network .. _`create_network()`: http://docker-py.readthedocs.io/en/stable/api.html#docker.api.network.NetworkApiMixin.create_network .. _`logs()`: http://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.logs .. _`IPAM pool`: http://docker-py.readthedocs.io/en/stable/api.html#docker.types.IPAMPool .. _docker: https://pypi.python.org/pypi/docker .. _docker-py: https://pypi.python.org/pypi/docker-py .. _lxc-attach: https://linuxcontainers.org/lxc/manpages/man1/lxc-attach.1.html .. _nsenter: http://man7.org/linux/man-pages/man1/nsenter.1.html .. _docker-exec: http://docs.docker.com/reference/commandline/cli/#exec .. _`docker-py Low-level API`: http://docker-py.readthedocs.io/en/stable/api.html .. _timelib: https://pypi.python.org/pypi/timelib .. _`trusted builds`: https://blog.docker.com/2013/11/introducing-trusted-builds/ .. _`Docker Engine API`: https://docs.docker.com/engine/api/v1.33/#operation/ContainerCreate .. note:: Older releases of the Python bindings for Docker were called docker-py_ in PyPI. All releases of docker_, and releases of docker-py_ >= 1.6.0 are supported. These python bindings can easily be installed using :py:func:`pip.install <salt.modules.pip.install>`: .. code-block:: bash salt myminion pip.install docker To upgrade from docker-py_ to docker_, you must first uninstall docker-py_, and then install docker_: .. code-block:: bash salt myminion pip.uninstall docker-py salt myminion pip.install docker .. _docker-authentication: Authentication -------------- If you have previously performed a ``docker login`` from the minion, then the credentials saved in ``~/.docker/config.json`` will be used for any actions which require authentication. If not, then credentials can be configured in any of the following locations: - Minion config file - Grains - Pillar data - Master config file (requires :conf_minion:`pillar_opts` to be set to ``True`` in Minion config file in order to work) .. important:: Versions prior to 3000 require that Docker credentials are configured in Pillar data. Be advised that Pillar data is still recommended though, because this keeps the configuration from being stored on the Minion. Also, keep in mind that if one gets your ``~/.docker/config.json``, the password can be decoded from its contents. The configuration schema is as follows: .. code-block:: yaml docker-registries: <registry_url>: username: <username> password: <password> For example: .. code-block:: yaml docker-registries: hub: username: foo password: s3cr3t .. note:: As of the 2016.3.7, 2016.11.4, and 2017.7.0 releases of Salt, credentials for the Docker Hub can be configured simply by specifying ``hub`` in place of the registry URL. In earlier releases, it is necessary to specify the actual registry URL for the Docker Hub (i.e. ``https://index.docker.io/v1/``). More than one registry can be configured. Salt will look for Docker credentials in the ``docker-registries`` Pillar key, as well as any key ending in ``-docker-registries``. For example: .. code-block:: yaml docker-registries: 'https://mydomain.tld/registry:5000': username: foo password: s3cr3t foo-docker-registries: https://index.foo.io/v1/: username: foo password: s3cr3t bar-docker-registries: https://index.bar.io/v1/: username: foo password: s3cr3t To login to the configured registries, use the :py:func:`docker.login <salt.modules.dockermod.login>` function. This only needs to be done once for a given registry, and it will store/update the credentials in ``~/.docker/config.json``. .. note:: For Salt releases before 2016.3.7 and 2016.11.4, :py:func:`docker.login <salt.modules.dockermod.login>` is not available. Instead, Salt will try to authenticate using each of your configured registries for each push/pull, behavior which is not correct and has been resolved in newer releases. Configuration Options --------------------- The following configuration options can be set to fine-tune how Salt uses Docker: - ``docker.url``: URL to the docker service (default: local socket). - ``docker.version``: API version to use (should not need to be set manually in the vast majority of cases) - ``docker.exec_driver``: Execution driver to use, one of ``nsenter``, ``lxc-attach``, or ``docker-exec``. See the :ref:`Executing Commands Within a Running Container <docker-execution-driver>` section for more details on how this config parameter is used. These configuration options are retrieved using :py:mod:`config.get <salt.modules.config.get>` (click the link for further information). .. _docker-execution-driver: Executing Commands Within a Running Container --------------------------------------------- .. note:: With the release of Docker 1.13.1, the Execution Driver has been removed. Starting in versions 2016.3.6, 2016.11.4, and 2017.7.0, Salt defaults to using ``docker exec`` to run commands in containers, however for older Salt releases it will be necessary to set the ``docker.exec_driver`` config option to either ``docker-exec`` or ``nsenter`` for Docker versions 1.13.1 and newer. Multiple methods exist for executing commands within Docker containers: - lxc-attach_: Default for older versions of docker - nsenter_: Enters container namespace to run command - docker-exec_: Native support for executing commands in Docker containers (added in Docker 1.3) Adding a configuration option (see :py:func:`config.get <salt.modules.config.get>`) called ``docker.exec_driver`` will tell Salt which execution driver to use: .. code-block:: yaml docker.exec_driver: docker-exec If this configuration option is not found, Salt will use the appropriate interface (either nsenter_ or lxc-attach_) based on the ``Execution Driver`` value returned from ``docker info``. docker-exec_ will not be used by default, as it is presently (as of version 1.6.2) only able to execute commands as the effective user of the container. Thus, if a ``USER`` directive was used to run as a non-privileged user, docker-exec_ would be unable to perform the action as root. Salt can still use docker-exec_ as an execution driver, but must be explicitly configured (as in the example above) to do so at this time. If possible, try to manually specify the execution driver, as it will save Salt a little work. This execution module provides functions that shadow those from the :mod:`cmd <salt.modules.cmdmod>` module. They are as follows: - :py:func:`docker.retcode <salt.modules.dockermod.retcode>` - :py:func:`docker.run <salt.modules.dockermod.run>` - :py:func:`docker.run_all <salt.modules.dockermod.run_all>` - :py:func:`docker.run_stderr <salt.modules.dockermod.run_stderr>` - :py:func:`docker.run_stdout <salt.modules.dockermod.run_stdout>` - :py:func:`docker.script <salt.modules.dockermod.script>` - :py:func:`docker.script_retcode <salt.modules.dockermod.script_retcode>` Detailed Function Documentation ------------------------------- � N)�CommandExecutionError�SaltInvocationError)�__file_client__)� HighStatezrestructuredtext enTF�nsenter�importZps�rm�signal�start�tagZapply)�import_�ps_�rm_�signal_�start_�tag_�apply_)� � r )r � r z([\d.]+)�docker)ZdockerngZmoby� highstate)�slsr r c C s� t rbzt� } W n ty Y dS w | du rdS | tkrNzt� �d�}W n ty/ d}Y nw |du s8|tkr:tS dd�d� t tt��d� t t|���fS dd�d� t tt��d� t t| ���fS dS ) z. Only load if docker libs are present )Fz6Docker module found, but no version could be extractedN�VersionInfoFz9Insufficient Docker version (required: {}, installed: {})�.z<Insufficient docker-py version (required: {}, installed: {}))Fz7Could not import docker module, is docker-py installed?)� HAS_DOCKER_PY�_get_docker_py_versioninfo� Exception� MIN_DOCKER_PY�version�get� MIN_DOCKER�__virtualname__�format�join�map�str)Zdocker_py_versioninfoZdocker_versioninfo� r'