HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/docker/api/__pycache__/service.cpython-310.pyc
o

�2.a�I�@sBddlmZmZmZddlmZdd�Zdd�ZGdd�d�Zd	S)
�)�auth�errors�utils)�ServiceModecCsDdd�}|durAt�|d�r d|vr|dd�d|vr |dd�t�|d�r2|�d	�d
kr2|dd�t�|d�rAd
|vrA|dd�|dur_t�|d�rP|dd�t�|d�r_d
|vr_|dd�|dur}t�|d�r}d|vr}tdd�|dD��r}|dd�|du�r�d|vr�t�|d�r�|dd�|�d�r�t�|d�r�|d�d�r�|dd�t�|d�r�|d�d�r�|dd�|�d��r~|�d�}t�|d��r|�d �r�|d!d�|�d"�dur�|d#d�|�d$�dur�|d%d�|�d&�dur�|d'd�|�d(�du�r|d)d�|�d*�du�r|d+d�t�|d��r5|�d,�du�r(|d)d�|�d-�du�r5|d.d�t�|d��rV|�d/�du�rI|d0d�|�d1�du�rV|d2d�t�|d3��rj|�d4�du�rj|d5d3�t�|d6��r~|�d7�du�r~|d8d6�|�d9��r�t�|d��r�|d9�d:��r�|d;d�dSdSdSdSdS)<NcSst�d�||���)Nz'{} is not supported in API version < {})r�InvalidVersion�format)�param�min_version�r
�4/usr/lib/python3/dist-packages/docker/api/service.py�raise_version_errors
��z0_check_api_features.<locals>.raise_version_error�1.25�MaxFailureRatiozUpdateConfig.max_failure_ratio�MonitorzUpdateConfig.monitorz1.28�
FailureAction�rollbackz$UpdateConfig.failure_action rollback�1.29�OrderzUpdateConfig.order�rollback_configzRollbackConfig.orderz1.32�Portscss�|]}|�d�VqdS)�PublishModeN)�get)�.0�pr
r
r�	<genexpr>*s�z&_check_api_features.<locals>.<genexpr>zEndpointSpec.Ports[].mode�ForceUpdate�force_update�	Placementz1.30�	PlatformszPlacement.platformsz1.27�PreferenceszPlacement.preferences�
ContainerSpec�TTYzContainerSpec.tty�HostnamezContainerSpec.hostname�HostszContainerSpec.hosts�GroupszContainerSpec.groups�	DNSConfigzContainerSpec.dns_config�HealthcheckzContainerSpec.healthcheck�ReadOnly�
StopSignalzContainerSpec.stop_signal�ConfigszContainerSpec.configs�
PrivilegeszContainerSpec.privilegesz1.35�	IsolationzContainerSpec.isolationz1.38�InitzContainerSpec.init�	Resources�GenericResourceszResources.generic_resources)r�
version_ltr�any)�version�
task_template�
update_config�
endpoint_specrr�container_specr
r
r�_check_api_featuress�

�




�

















�2r6cCsz|��}|dur;|��D].\}}|dkr2d|vri|d<|d��D]\}}|dur0||d|<q"q|dur:|||<q|S)Nr )�copy�items)�current�override�merged�ts_key�ts_value�cs_key�cs_valuer
r
r�_merge_task_templatees���r@c@s�eZdZe�d�			ddd��Ze�d�e�d�ddd���Ze�d�e�d�d	d
���Ze�d�e�d�dd���Z	e�d�dd
d��Z
e�d�e�d�			ddd���Ze�d�ddd��Ze�d�e�d�					ddd���Z
dS)�ServiceApiMixinz1.24Nc
Cs�t|j||||	�|�d�}
i}|�di��dd�}|dur#t�d��|r.t|t�s.t|�}t	�
|�\}
}t	�||
�}|rA||d<t�
|jd�rP|pO|�dd�}||||t�|�|d	�}|durd||d
<|	durl|	|d<|�|j|
||d�d
�S)a
        Create a service.

        Args:
            task_template (TaskTemplate): Specification of the task to start as
                part of the new service.
            name (string): User-defined name for the service. Optional.
            labels (dict): A map of labels to associate with the service.
                Optional.
            mode (ServiceMode): Scheduling mode for the service (replicated
                or global). Defaults to replicated.
            update_config (UpdateConfig): Specification for the update strategy
                of the service. Default: ``None``
            rollback_config (RollbackConfig): Specification for the rollback
                strategy of the service. Default: ``None``
            networks (:py:class:`list`): List of network names or IDs or
                :py:class:`~docker.types.NetworkAttachmentConfig` to attach the
                service to. Default: ``None``.
            endpoint_spec (EndpointSpec): Properties that can be configured to
                access and load balance a service. Default: ``None``.

        Returns:
            A dictionary containing an ``ID`` key for the newly created
            service.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        z/services/creater �ImageNz,Missing mandatory Image key in ContainerSpec�X-Registry-Authr
�Networks)�Name�Labels�TaskTemplate�ModerD�EndpointSpec�UpdateConfig�RollbackConfig)�data�headersT)r6�_version�_urlrr�DockerException�
isinstance�dictrr�resolve_repository_name�get_config_headerrr/�pop�convert_service_networks�_result�
_post_json)�selfr2�name�labels�moder3�networks�endpoint_configr4r�urlrM�image�registry�	repo_name�auth_headerrLr
r
r�create_serviceusB$
�
��	�zServiceApiMixin.create_service�servicecCsN|�d|�}i}|durt�|jd�rt�d��||d<|�|j||d�d�S)a�
        Return information about a service.

        Args:
            service (str): Service name or ID.
            insert_defaults (boolean): If true, default values will be merged
                into the service inspect output.

        Returns:
            (dict): A dictionary of the server-side representation of the
                service, including all relevant properties.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �
/services/{0}Nrz6insert_defaults is not supported in API version < 1.29�insertDefaults��paramsT)rOrr/rNrrrW�_get)rYre�insert_defaultsr_rir
r
r�inspect_service�s�zServiceApiMixin.inspect_service�taskcCs|�d|�}|�|�|�d�S)a
        Retrieve information about a task.

        Args:
            task (str): Task ID

        Returns:
            (dict): Information about the task.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        z
/tasks/{0}T)rOrWrj)rYrmr_r
r
r�inspect_task�szServiceApiMixin.inspect_taskcCs$|�d|�}|�|�}|�|�dS)a
        Stop and remove a service.

        Args:
            service (str): Service name or ID

        Returns:
            ``True`` if successful.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        rfT)rO�_delete�_raise_for_status)rYrer_�respr
r
r�remove_service�s

zServiceApiMixin.remove_servicecC�6d|rt�|�ndi}|�d�}|�|j||d�d�S)a�
        List services.

        Args:
            filters (dict): Filters to process on the nodes list. Valid
                filters: ``id``, ``name`` , ``label`` and ``mode``.
                Default: ``None``.

        Returns:
            A list of dictionaries containing data about each service.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �filtersNz	/servicesrhT�r�convert_filtersrOrWrj�rYrtrir_r
r
r�servicess�
zServiceApiMixin.servicesr
F��allc

Csd|||||||d�}
|�d|�}|j||
dd�}|	dur+|�|�ddd�d	d
�}	|�d||	�S)ar
            Get log stream for a service.
            Note: This endpoint works only for services with the ``json-file``
            or ``journald`` logging drivers.

            Args:
                service (str): ID or name of the service
                details (bool): Show extra details provided to logs.
                    Default: ``False``
                follow (bool): Keep connection open to read logs as they are
                    sent by the Engine. Default: ``False``
                stdout (bool): Return logs from ``stdout``. Default: ``False``
                stderr (bool): Return logs from ``stderr``. Default: ``False``
                since (int): UNIX timestamp for the logs staring point.
                    Default: 0
                timestamps (bool): Add timestamps to every log line.
                tail (string or int): Number of log lines to be returned,
                    counting from the current end of the logs. Specify an
                    integer or ``'all'`` to output all log lines.
                    Default: ``all``
                is_tty (bool): Whether the service's :py:class:`ContainerSpec`
                    enables the TTY option. If omitted, the method will query
                    the Engine for the information, causing an additional
                    roundtrip.

            Returns (generator): Logs for the service.
        )�details�follow�stdout�stderr�since�
timestamps�tailz/services/{0}/logsT)ri�streamN�SpecrGr r!F)rOrjrlr�_get_result_tty)
rYrer{r|r}r~rr�r��is_ttyrir_�resr
r
r�service_logss.!�
�����zServiceApiMixin.service_logscCrs)a�
        Retrieve a list of tasks.

        Args:
            filters (dict): A map of filters to process on the tasks list.
                Valid filters: ``id``, ``name``, ``service``, ``node``,
                ``label`` and ``desired-state``.

        Returns:
            (:py:class:`list`): List of task dictionaries.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        rtNz/tasksrhTrurwr
r
r�tasksQs�
zServiceApiMixin.tasksc
CsLt|j|||
|�|r d}
t�|jd�rd}
|j||
d�d}ni}|�d|�}i}i}|dur5|�d�n||d<|durB|�d�n||d<|durXt|t�sSt	|�}||d	<n|�d	�|d	<t
|�d
i�|�|d
<|d
�di�}|�dd�}|dur�t�|�\}}t�
||�}|r�||d
<|dur�||d<n|�d�|d<|dur�||d<n|�d�|d<|dur�t�|�}t�|jd�r�||d<n?||d
d<n8t�|jd�r�|�d�|d<n)|d
�d�du�r|�d
i�}|�d�}|dur�|�d�}|du�r||d
d<|
du�r
|
|d<n|�d�|d<|j||d|i|d�}|j|dd�S)a�
        Update a service.

        Args:
            service (string): A service identifier (either its name or service
                ID).
            version (int): The version number of the service object being
                updated. This is required to avoid conflicting writes.
            task_template (TaskTemplate): Specification of the updated task to
                start as part of the service.
            name (string): New name for the service. Optional.
            labels (dict): A map of labels to associate with the service.
                Optional.
            mode (ServiceMode): Scheduling mode for the service (replicated
                or global). Defaults to replicated.
            update_config (UpdateConfig): Specification for the update strategy
                of the service. Default: ``None``.
            rollback_config (RollbackConfig): Specification for the rollback
                strategy of the service. Default: ``None``
            networks (:py:class:`list`): List of network names or IDs or
                :py:class:`~docker.types.NetworkAttachmentConfig` to attach the
                service to. Default: ``None``.
            endpoint_spec (EndpointSpec): Properties that can be configured to
                access and load balance a service. Default: ``None``.
            fetch_current_spec (boolean): Use the undefined settings from the
                current specification of the service. Default: ``False``

        Returns:
            A dictionary containing a ``Warnings`` key.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        TrN)rkr�z/services/{0}/updaterErFrHrGr rBrCrJrKr
rDrIr1)rLrirM)�json)r6rNrr/rlrOrrQrRrr@rrSrTrVrXrW)rYrer1r2rZr[r\r3r]r^r4�fetch_current_specr�inspect_defaultsr9r_rLrMr5r`rarbrc�converted_networks�current_task_template�current_networksrqr
r
r�update_serviceisz*
���

�








�zServiceApiMixin.update_service)NNNNNNNN)N)FFFFryFrzN)
NNNNNNNNFN)�__name__�
__module__�__qualname__r�minimum_versionrd�check_resourcerlrnrrrxr�r�r�r
r
r
rrAtsB�K�0�rAN)	�rrr�typesrr6r@rAr
r
r
r�<module>s
`