
    7K                     D    S SK JrJrJr  S SKJr  S rS r " S S5      rg)   )autherrorsutils)ServiceModec                    S nUb  [         R                  " U S5      (       a  SU;   a	  U" SS5        SU;   a	  U" SS5        [         R                  " U S5      (       a  UR                  S5      S	:X  a	  U" S
S5        [         R                  " U S5      (       a  SU;   a	  U" SS5        UbP  [         R                  " U S5      (       a	  U" SS5        [         R                  " U S5      (       a  SU;   a	  U" SS5        UbE  [         R                  " U S5      (       a)  SU;   a#  [        S US    5       5      (       a	  U" SS5        UGb  SU;   a%  [         R                  " U S5      (       a	  U" SS5        UR                  S5      (       a|  [         R                  " U S5      (       a"  US   R                  S5      (       a	  U" SS5        [         R                  " U S5      (       a"  US   R                  S5      (       a	  U" SS5        UR                  S5      (       Ga  UR                  S5      n[         R                  " U S5      (       a  UR                  S5      (       a	  U" SS5        UR                  S 5      b	  U" S!S5        UR                  S"5      b	  U" S#S5        UR                  S$5      b	  U" S%S5        UR                  S&5      b	  U" S'S5        UR                  S(5      b	  U" S)S5        [         R                  " U S5      (       a6  UR                  S*5      b	  U" S'S5        UR                  S+5      b	  U" S,S5        [         R                  " U S5      (       a6  UR                  S-5      b	  U" S.S5        UR                  S/5      b	  U" S0S5        [         R                  " U S15      (       a  UR                  S25      b	  U" S3S15        [         R                  " U S45      (       a  UR                  S55      b	  U" S6S45        UR                  S75      (       aA  [         R                  " U S5      (       a$  US7   R                  S85      (       a
  U" S9S5        g g g g g ):Nc                 L    [         R                  " SR                  X5      5      e)Nz'{} is not supported in API version < {})r   InvalidVersionformat)parammin_versions     %lib/third_party/docker/api/service.pyraise_version_error0_check_api_features.<locals>.raise_version_error   s&    ##5<<
 	
    1.25MaxFailureRatiozUpdateConfig.max_failure_ratioMonitorzUpdateConfig.monitorz1.28FailureActionrollbackz$UpdateConfig.failure_action rollback1.29OrderzUpdateConfig.orderrollback_configzRollbackConfig.orderz1.32Portsc              3   B   #    U  H  oR                  S 5      v   M     g7f)PublishModeN)get).0ps     r   	<genexpr>&_check_api_features.<locals>.<genexpr>*   s     H1GA55''1Gs   zEndpointSpec.Ports[].modeForceUpdateforce_update	Placementz1.30	PlatformszPlacement.platformsz1.27PreferenceszPlacement.preferencesContainerSpecTTYzContainerSpec.ttyHostnamezContainerSpec.hostnameHostszContainerSpec.hostsGroupszContainerSpec.groups	DNSConfigzContainerSpec.dns_configHealthcheckzContainerSpec.healthcheckReadOnly
StopSignalzContainerSpec.stop_signalConfigszContainerSpec.configs
PrivilegeszContainerSpec.privilegesz1.35	IsolationzContainerSpec.isolationz1.38InitzContainerSpec.init	ResourcesGenericResourceszResources.generic_resources)r   
version_ltr   any)versiontask_templateupdate_configendpoint_specr   r   container_specs          r   _check_api_featuresr<      s   
  GV,, M1#$DfMM)#$:FCGV,,  1Z?#:F GV,,-'#$8&A"GV,, 16:GV,,-'#$:FC GV,,M1IHw1GHHH#$?H M)e.>.>/! /!7[))00 -11+>>'(=vF00 -11-@@'(?H_--*..?N00!%%e,,'(;VD!%%j1='(@&I!%%g.:'(=vF!%%h/;'(>G!%%k2>'(BFK!%%m4@'(CVL00!%%j1='(BFK!%%l3?'(CVL00!%%i0<'(?H!%%l3?'(BFK00!%%k2>'(A6J00!%%f-9'(<fE[))00 -112DEE'(EvN F 1 *e !r   c                     U R                  5       nUb]  UR                  5        HI  u  p4US:X  a5  SU;  a  0 US'   US   R                  5        H  u  pVUc  M
  XbS   U'   M     M@  Uc  ME  XBU'   MK     U$ )Nr&   )copyitems)currentoverridemergedts_keyts_valuecs_keycs_values          r   _merge_task_templaterG   e   s    \\^F ( 0F("&0.0F?+(0(A(G(G(I$F+:B/7 )J %!)v !1 Mr   c                      \ rS rSr\R
                  " S5         SS j5       r\R
                  " S5      \R                  " S5      SS j5       5       r\R
                  " S5      \R                  " S5      S 5       5       r	\R
                  " S5      \R                  " S5      S	 5       5       r
\R
                  " S5      SS
 j5       r\R
                  " S5      \R                  " S5         SS j5       5       r\R
                  " S5      SS j5       r\R
                  " S5      \R                  " S5           SS j5       5       rSrg)ServiceApiMixint   z1.24Nc
                    [        U R                  XUU	5        U R                  S5      n
0 nUR                  S0 5      R                  SS5      nUc  [        R
                  " S5      eU(       a   [        U[        5      (       d  [        U5      n[        R                  " U5      u  p[        R                  " X5      nU(       a  XS'   [        R                  " U R                  S5      (       a  U=(       d    UR                  SS5      nUUUU[        R                  " U5      US	.nUb  UUS
'   U	b  U	US'   U R!                  U R#                  U
UUS9S5      $ )aU  
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ModerN   EndpointSpecUpdateConfigRollbackConfig)dataheadersT)r<   _version_urlr   r   DockerException
isinstancedictr   r   resolve_repository_nameget_config_headerr   r5   popconvert_service_networks_result
_post_json)selfr8   namelabelsmoder9   networksendpoint_configr:   r   urlrW   imageregistry	repo_nameauth_headerrV   s                    r   create_serviceServiceApiMixin.create_serviceu   sO   H 	MM=	

 ii*+!!/26::7DI=((>  
4..t$D"::5A,,T<)4%&DMM622F=#4#4Z#FH)66x@)
 $#0D &%4D!"||OOCdGO<d
 	
r   servicec                     U R                  SU5      n0 nUb@  [        R                  " U R                  S5      (       a  [        R
                  " S5      eX$S'   U R                  U R                  X4S9S5      $ )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}r   z6insert_defaults is not supported in API version < 1.29insertDefaultsparamsT)rY   r   r5   rX   r   r	   ra   _get)rc   rp   insert_defaultsri   ru   s        r   inspect_serviceServiceApiMixin.inspect_service   ss    & ii1&v66++L  (7#$||DIIcI94@@r   taskc                 h    U R                  SU5      nU R                  U R                  U5      S5      $ )z
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)rY   ra   rv   )rc   rz   ri   s      r   inspect_taskServiceApiMixin.inspect_task   s-      iid+||DIIcND11r   c                 l    U R                  SU5      nU R                  U5      nU R                  U5        g)z
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.
rr   T)rY   _delete_raise_for_status)rc   rp   ri   resps       r   remove_serviceServiceApiMixin.remove_service   s3    " ii1||C t$r   c                 *   SU(       a  [         R                  " U5      OS0nUb@  [         R                  " U R                  S5      (       a  [        R
                  " S5      eX#S'   U R                  S5      nU R                  U R                  XCS9S5      $ )	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:
    A list of dictionaries containing data about each service.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
filtersNz1.41z-status is not supported in API version < 1.41statusz	/servicesrt   T)	r   convert_filtersr5   rX   r   r	   rY   ra   rv   )rc   r   r   ru   ri   s        r   servicesServiceApiMixin.services  s    ( u,,W5d
 v66++C   &8ii$||DIIcI94@@r   r   c
                     UUUUUUUS.n
U R                  SU5      nU R                  XSS9nU	c*  U R                  U5      S   S   S   R                  SS	5      n	U R	                  SX5      $ )
aV  
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)ru   streamSpecrQ   r&   r'   F)rY   rv   rx   r   _get_result_tty)rc   rp   r   r   r   r   r   r   r   is_ttyru   ri   ress                r   service_logsServiceApiMixin.service_logs'  s    B $
 ii,g6ii4i8>))$&&577:s5%7H  ##D#66r   c                     SU(       a  [         R                  " U5      OS0nU R                  S5      nU R                  U R	                  X2S9S5      $ )ac  
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.
r   Nz/tasksrt   T)r   r   rY   ra   rv   )rc   r   ru   ri   s       r   tasksServiceApiMixin.tasksY  sK    & u,,W5d
 ii!||DIIcI94@@r   c                    [        U R                  X7U
U5        U(       a=  Sn[        R                  " U R                  S5      (       a  SnU R	                  XS9S   nO0 nU R                  SU5      n0 n0 nUc  UR                  S5      OUUS'   Uc  UR                  S5      OUUS'   Ub&  [        U[        5      (       d  [        U5      nUUS	'   OUR                  S	5      US	'   [        UR                  S
0 5      U5      US
'   US
   R                  S0 5      nUR                  SS5      nUb<  [        R                  " U5      u  nn[        R                  " U U5      nU(       a  UUS'   Ub  UUS'   OUR                  S5      US'   Ub  UUS'   OUR                  S5      US'   UbK  [        R                  " U5      n[        R                  " U R                  S5      (       a  UUS'   OUUS
   S'   O[        R                  " U R                  S5      (       a  UR                  S5      US'   OWUS
   R                  S5      cB  UR                  S
0 5      nUR                  S5      nUc  UR                  S5      nUb  UUS
   S'   U
b  U
US'   OUR                  S5      US'   U R                  UUSU0US9nU R!                  USS9$ )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.
Tr   N)rw   r   z/services/{0}/updaterO   rP   rR   rQ   r&   rL   rM   rT   rU   r   rN   rS   r7   )rV   ru   rW   )json)r<   rX   r   r5   rx   rY   r   r[   r\   r   rG   r   r]   r^   r`   rb   ra   )rc   rp   r7   r8   rd   re   rf   r9   rg   rh   r:   fetch_current_specr   inspect_defaultsr@   ri   rV   rW   r;   rj   rk   rl   rm   converted_networkscurrent_task_templatecurrent_networksr   s                              r   update_serviceServiceApiMixin.update_serviceq  s   T 	MM=	

 #v66#' ** + G
 Gii.8.2lw{{6*V28.X.fXdD))"4(DL";;v.DL3KK+] 
^ n-11/2F""7D1"&">">u"EHi00x@K-8)*$#0D #*;;~#>D &%4D!"%,[[1A%BD!"!&!?!?!Iv66#5Z 3E^$Z0dmmV44&{{:6D.!%%j19$+KK$C!488D'#*;;z#: +3C^$Z0$#0D #*;;~#>D dIw#7  
 ||Dt|,,r    )NNNNNNNN)N)NN)FFFF    FallN)
NNNNNNNNFN)__name__
__module____qualname____firstlineno__r   minimum_versionrn   check_resourcerx   r|   r   r   r   r   r   __static_attributes__r   r   r   rI   rI   t   s   
6">B?C04I
 #I
V 6"
)$A % #A8 6"
&!2 " #2" 6"
)$ % #( 6"A #A< 6"
)$HMCH .7 % #.7` 6"A #A. 6"
)$HL=A6:>C'+	u- % #u-r   rI   N)	 r   r   r   typesr   r<   rG   rI   r   r   r   <module>r      s'    " " ]O@t- t-r   