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/models/__pycache__/services.cpython-310.pyc
o

q_aY5�@s�ddlZddlmZmZddlmZmZmZmZddl	m
Z
mZGdd�de
�ZGdd	�d	e�Z
gd
�Zgd�Zgd�Zgd
�Zdd�ZdS)�N)�create_unexpected_kwargs_error�InvalidArgument)�TaskTemplate�
ContainerSpec�	Placement�ServiceMode�)�Model�
Collectionc@s^eZdZdZdZedd��Zedd��Zdd�Zdd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
d	S)�Servicez
A service.�IDcCs|jddS)zThe service's name.�Spec�Name)�attrs��self�r�8/usr/lib/python3/dist-packages/docker/models/services.py�nameszService.namecCs|j�d��d�S)z�
        The version number of the service. If this is not the same as the
        server, the :py:meth:`update` function will not work and you will
        need to call :py:meth:`reload` before calling it again.
        �Version�Index)r�getrrrr�versionszService.versioncCs|jj�|j�S)z�
        Stop and remove the service.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )�client�api�remove_service�idrrrr�removeszService.removeNcCs&|duri}|j|d<|jjj|d�S)a�
        List the tasks in this service.

        Args:
            filters (dict): A map of filters to process on the tasks list.
                Valid filters: ``id``, ``name``, ``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.
        N�service)�filters)rrr�tasks)rrrrrr #s
z
Service.taskscKs�d|vr|jddd}|d|d<|�d�dur/|jdd}t|�dd	��}|d
|d<td|�}|jjj|j|jfi|��S)a)
        Update a service's configuration. Similar to the ``docker service
        update`` command.

        Takes the same parameters as :py:meth:`~ServiceCollection.create`.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �imager
rr�Image�force_updateT�ForceUpdaterr�update)	rr�int�_get_create_service_kwargsrr�update_servicerr)r�kwargs�spec�
task_template�
current_value�
create_kwargsrrrr%8s
��zService.updatecKs6|jddd�dd�}|jjj|jfd|i|��S)a�
        Get log stream for the service.
        Note: This method works only for services with the ``json-file``
        or ``journald`` logging drivers.

        Args:
            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``

        Returns:
            generator: Logs for the service.
        r
rr�TTYF�is_tty)rrrr�service_logsr)rr)r/rrr�logsUs�zService.logscCsBd|jdd��vrtd��td|�}|jjj|j|j|dd�S)z�
        Scale service container.

        Args:
            replicas (int): The number of containers that should be running.

        Returns:
            bool: ``True`` if successful.
        �Globalr
�ModezCannot scale a global container�
replicatedT)�mode�fetch_current_spec)	r�keysrrrrr(rr)r�replicas�service_moderrr�scalers
�z
Service.scalecCs|jddd�S)z�
        Force update the service even if no changes require it.

        Returns:
            bool: ``True`` if successful.
        T)r#r6)r%rrrrr#�szService.force_update�N)�__name__�
__module__�__qualname__�__doc__�id_attribute�propertyrrrr r%r1r:r#rrrrrs



rc@s0eZdZdZeZd	dd�Zd	dd�Zdd�ZdS)
�ServiceCollectionzServices on the Docker server.NcKs8||d<||d<td|�}|jjjdi|��}|�|�S)a1
        Create a service. Similar to the ``docker service create`` command.

        Args:
            image (str): The image name to use for the containers.
            command (list of str or str): Command to run.
            args (list of str): Arguments to the command.
            constraints (list of str): :py:class:`~docker.types.Placement`
                constraints.
            preferences (list of tuple): :py:class:`~docker.types.Placement`
                preferences.
            maxreplicas (int): :py:class:`~docker.types.Placement` maxreplicas
                or (int) representing maximum number of replicas per node.
            platforms (list of tuple): A list of platform constraints
                expressed as ``(arch, os)`` tuples.
            container_labels (dict): Labels to apply to the container.
            endpoint_spec (EndpointSpec): Properties that can be configured to
                access and load balance a service. Default: ``None``.
            env (list of str): Environment variables, in the form
                ``KEY=val``.
            hostname (string): Hostname to set on the container.
            init (boolean): Run an init inside the container that forwards
                signals and reaps processes
            isolation (string): Isolation technology used by the service's
                containers. Only used for Windows containers.
            labels (dict): Labels to apply to the service.
            log_driver (str): Log driver to use for containers.
            log_driver_options (dict): Log driver options.
            mode (ServiceMode): Scheduling mode for the service.
                Default:``None``
            mounts (list of str): Mounts for the containers, in the form
                ``source:target:options``, where options is either
                ``ro`` or ``rw``.
            name (str): Name to give to the service.
            networks (:py:class:`list`): List of network names or IDs or
                :py:class:`~docker.types.NetworkAttachmentConfig` to attach the
                service to. Default: ``None``.
            resources (Resources): Resource limits and reservations.
            restart_policy (RestartPolicy): Restart policy for containers.
            secrets (list of :py:class:`~docker.types.SecretReference`): List
                of secrets accessible to containers for this service.
            stop_grace_period (int): Amount of time to wait for
                containers to terminate before forcefully killing them.
            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``
            user (str): User to run commands as.
            workdir (str): Working directory for commands to run.
            tty (boolean): Whether a pseudo-TTY should be allocated.
            groups (:py:class:`list`): A list of additional groups that the
                container process will run as.
            open_stdin (boolean): Open ``stdin``
            read_only (boolean): Mount the container's root filesystem as read
                only.
            stop_signal (string): Set signal to stop the service's containers
            healthcheck (Healthcheck): Healthcheck
                configuration for this service.
            hosts (:py:class:`dict`): A set of host to IP mappings to add to
                the container's `hosts` file.
            dns_config (DNSConfig): Specification for DNS
                related configurations in resolver configuration file.
            configs (:py:class:`list`): List of
                :py:class:`~docker.types.ConfigReference` that will be exposed
                to the service.
            privileges (Privileges): Security options for the service's
                containers.
            cap_add (:py:class:`list`): A list of kernel capabilities to add to
                the default set for the container.
            cap_drop (:py:class:`list`): A list of kernel capabilities to drop
                from the default set for the container.

        Returns:
            :py:class:`Service`: The created service.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        r!�command�createNr)r'rr�create_servicer)rr!rCr)r-�
service_idrrrrD�s
P

zServiceCollection.createcCs|�|jj�||��S)a}
        Get a service.

        Args:
            service_id (str): The ID of the service.
            insert_defaults (boolean): If true, default values will be merged
                into the output.

        Returns:
            :py:class:`Service`: The service.

        Raises:
            :py:class:`docker.errors.NotFound`
                If the service does not exist.
            :py:class:`docker.errors.APIError`
                If the server returns an error.
            :py:class:`docker.errors.InvalidVersion`
                If one of the arguments is not supported with the current
                API version.
        )�
prepare_modelrr�inspect_service)rrF�insert_defaultsrrrr�s�zServiceCollection.getcs"�fdd��jjjdi|��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:
            list of :py:class:`Service`: The services.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        csg|]}��|��qSr)rG)�.0�srrr�
<listcomp>s��z*ServiceCollection.list.<locals>.<listcomp>Nr)rr�services)rr)rrr�lists
�zServiceCollection.listr;)	r<r=r>r?r�modelrDrrNrrrrrB�s

VrB)�args�cap_add�cap_droprC�configs�
dns_config�env�groups�healthcheck�hostname�hostsr!�init�	isolation�labels�mounts�
open_stdin�
privileges�	read_only�secrets�stop_grace_period�stop_signal�tty�user�workdir)�networks�	resources�restart_policy)rr\r5�
update_config�
endpoint_spec)�constraints�preferences�	platforms�maxreplicasc	Csdi}t�|�D]
}|tvr|�|�||<qi}t�|�D]
}|tvr)|�|�||<qi}t�|�D]
}|tvr>|�|�||<q1d|vrJ|�d�|d<i}t�|�D]
}|tvr^|�|�||<qQtd
i|��}||d<d|vr||�d�|�di�d�|d<|dkr�d|vr�|�d�|d<|�d	d
�}||d	<|r�t||��td
i|��}||d<t	d
i|��|d<|S)N�container_labelsr\�	placement�
log_driver�log_driver_options)r�Optionsr%r#r6T�container_specr+r)
�copy�CREATE_SERVICE_KWARGS�pop�CONTAINER_SPEC_KWARGS�TASK_TEMPLATE_KWARGS�PLACEMENT_KWARGSrrrr)	�	func_namer)r-�key�container_spec_kwargs�task_template_kwargsrqr6rurrrr'NsN����

�
r')rv�
docker.errorsrr�docker.typesrrrr�resourcer	r
rrBryrzrwr{r'rrrr�<module>s