
    b6                         S SK r S SKJrJr  S SKJrJrJrJr  SSK	J
r
Jr   " S S\
5      r " S S	\5      r/ S
Qr/ SQr/ SQr/ SQrS rg)    N)create_unexpected_kwargs_errorInvalidArgument)TaskTemplateContainerSpec	PlacementServiceMode   )Model
Collectionc                   d    \ rS rSrSrSr\S 5       r\S 5       rS r	SS jr
S	 rS
 rS rS rSrg)Service   z
A service.IDc                 &    U R                   S   S   $ )zThe service's name.SpecName)attrsselfs    )lib/third_party/docker/models/services.pynameService.name   s     zz&!&))    c                 V    U R                   R                  S5      R                  S5      $ )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   getr   s    r   versionService.version   s"     zz~~i(,,W55r   c                 `    U R                   R                  R                  U R                  5      $ )zv
Stop and remove the service.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)clientapiremove_serviceidr   s    r   removeService.remove   s!     {{--dgg66r   Nc                 p    Uc  0 nU R                   US'   U R                  R                  R                  US9$ )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.
service)filters)r$   r!   r"   tasks)r   r)   s     r   r*   Service.tasks#   s8      ?G!WW	{{$$W$55r   c                 j   SU;  a  U R                   S   S   S   nUS   US'   UR                  S5      SL a5  U R                   S   S   n[        UR                  SS	5      5      nUS
-   US'   [        SU5      nU R                  R
                  R                  " U R                  U R                  40 UD6$ )z
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   r   r   Imageforce_updateTForceUpdater   r	   update)	r   r   int_get_create_service_kwargsr!   r"   update_servicer$   r   )r   kwargsspectask_templatecurrent_valuecreate_kwargss         r   r1   Service.update8   s     & ::f%n5oFD"7mF7O::n%- JJv.~>M 1 1- CDM%2Q%6F>"28VD{{--GGLL
 
 	
r   c                     U R                   S   S   S   R                  SS5      nU R                  R                  R                  " U R
                  4SU0UD6$ )aV  
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   r   r   TTYFis_tty)r   r   r!   r"   service_logsr$   )r   r5   r=   s      r   logsService.logsU   sU    0 F#N3ODHH5
 {{++DGGMFMfMMr   c                     SU R                   S   S   R                  5       ;   a  [        S5      e[        SU5      nU R                  R
                  R                  U R                  U R                  USS9$ )z
Scale service container.

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

Returns:
    bool: ``True`` if successful.
Globalr   ModezCannot scale a global container
replicatedT)modefetch_current_spec)	r   keysr   r   r!   r"   r4   r$   r   )r   replicasservice_modes      r   scaleService.scaler   so     tzz&)&16688!"CDD"<:{{--dggt||3?AE . G 	Gr   c                 "    U R                  SSS9$ )ze
Force update the service even if no changes require it.

Returns:
    bool: ``True`` if successful.
T)r/   rF   )r1   r   s    r   r/   Service.force_update   s     {{{FFr    N)__name__
__module____qualname____firstlineno____doc__id_attributepropertyr   r   r%   r*   r1   r?   rJ   r/   __static_attributes__rN   r   r   r   r      sQ    L* * 6 676*
:N:G&Gr   r   c                   6    \ rS rSrSr\rSS jrSS jrS r	Sr
g)	ServiceCollection   zServices on the Docker server.Nc                     XS'   X#S'   [        SU5      nU R                  R                  R                  " S0 UD6nU R	                  U5      $ )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.
    sysctls (:py:class:`dict`): A dict of sysctl values to add to the
        container

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

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
r-   commandcreaterN   )r3   r!   r"   create_servicer   )r   r-   r\   r5   r9   
service_ids         r   r]   ServiceCollection.create   sJ    d  w#y28VD[[__33DmD
xx
##r   c                 j    U R                  U R                  R                  R                  X5      5      $ )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_modelr!   r"   inspect_service)r   r_   insert_defaultss      r   r   ServiceCollection.get   s-    * !!KKOO++JH
 	
r   c                     U R                   R                  R                  " S0 UD6 Vs/ s H  nU R                  U5      PM     sn$ s  snf )a  
List services.

Args:
    filters (dict): Filters to process on the nodes list. Valid
        filters: ``id``, ``name`` , ``label`` and ``mode``.
        Default: ``None``.
    status (bool): Include the service task count of running and
        desired tasks. Default: ``None``.

Returns:
    list of :py:class:`Service`: The services.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
rN   )r!   r"   servicesrb   )r   r5   ss      r   listServiceCollection.list  sJ    ( [[__--77
7 q!7
 	
 
s   ArN   rO   )rP   rQ   rR   rS   rT   r   modelr]   r   ri   rW   rN   r   r   rY   rY      s    (EV$p
2
r   rY   )argscap_addcap_dropr\   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sysctls)networks	resourcesrestart_policy)r   rx   rE   update_configrollback_configendpoint_spec)constraintspreferences	platformsmaxreplicasc                 l   0 n[         R                   " U5       H"  nU[        ;   d  M  UR                  U5      X#'   M$     0 n[         R                   " U5       H"  nU[        ;   d  M  UR                  U5      XC'   M$     0 n[         R                   " U5       H"  nU[        ;   d  M  UR                  U5      XS'   M$     SU;   a  UR                  S5      US'   0 n[         R                   " U5       H"  nU[
        ;   d  M  UR                  U5      Xc'   M$     [        S0 UD6nXeS'   SU;   a'  UR                  S5      UR                  S0 5      S.US'   U S:X  a0  SU;   a  UR                  S5      US'   UR                  S	S
5      nXrS	'   U(       a  [        X5      e[        S0 UD6nXS'   [        S0 UD6US'   U$ )Ncontainer_labelsrx   	placement
log_driverlog_driver_options)r   Optionsr1   r/   rF   Tcontainer_specr7   rN   )
copyCREATE_SERVICE_KWARGSpopCONTAINER_SPEC_KWARGSTASK_TEMPLATE_KWARGSPLACEMENT_KWARGSr   r   r   r   )		func_namer5   r9   keycontainer_spec_kwargstask_template_kwargsr   rF   r   s	            r   r3   r3   T  s   Myy ''!'CM ! yy '')/C!& ! yy &&(.

3 % ! V#*0**5G*Hh'Iyy ""#ZZ_IN ! &I&I(1%vJJ|,zz"6;.
\*
 HV#39::n3M 0 $ZZ(<dC.@*+ ,Y??";%:;N-;)*%1%I4H%IM/"r   )r   docker.errorsr   r   docker.typesr   r   r   r   resourcer
   r   r   rY   r   r   r   r   r3   rN   r   r   <module>r      sY     I L L 'FGe FGRJ

 J
\ <   0r   