
    F                         S SK r S SKJr  SSKJrJr  SSKJr  SSKJ	r	  SSKJ
r
  \ R                  " \5      r " S S5      rg)	    N   )DEFAULT_SWARM_ADDR_POOLDEFAULT_SWARM_SUBNET_SIZE)errors)types)utilsc                      \ rS rSrS r\R                  " S5      S 5       r\R                  " S5          SS j5       r\R                  " S5      S 5       r	\R                  " S5      \R                  " S5      S	 5       5       r\R                  " S5        SS
 j5       r\R                  " S5      SS j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 5       r\R                  " S5      SS j5       r\R                  " S5          SS j5       rSrg)SwarmApiMixin   c                     UR                  SS5      nU(       a  U/US'   [        R                  " U R                  /UQ70 UD6$ )a  
Create a :py:class:`docker.types.SwarmSpec` instance that can be used
as the ``swarm_spec`` argument in
:py:meth:`~docker.api.swarm.SwarmApiMixin.init_swarm`.

Args:
    task_history_retention_limit (int): Maximum number of tasks
        history stored.
    snapshot_interval (int): Number of logs entries between snapshot.
    keep_old_snapshots (int): Number of snapshots to keep beyond the
        current snapshot.
    log_entries_for_slow_followers (int): Number of log entries to
        keep around to sync up slow followers after a snapshot is
        created.
    heartbeat_tick (int): Amount of ticks (in seconds) between each
        heartbeat.
    election_tick (int): Amount of ticks (in seconds) needed without a
        leader to trigger a new election.
    dispatcher_heartbeat_period (int):  The delay for an agent to send
        a heartbeat to the dispatcher.
    node_cert_expiry (int): Automatic expiry for nodes certificates.
    external_cas (:py:class:`list`): Configuration for forwarding
        signing requests to an external certificate authority. Use
        a list of :py:class:`docker.types.SwarmExternalCA`.
    name (string): Swarm's name
    labels (dict): User-defined key/value metadata.
    signing_ca_cert (str): The desired signing CA certificate for all
        swarm node TLS leaf certificates, in PEM format.
    signing_ca_key (str): The desired signing CA key for all swarm
        node TLS leaf certificates, in PEM format.
    ca_force_rotate (int): An integer whose purpose is to force swarm
        to generate a new signing CA certificate and key, if none have
        been specified.
    autolock_managers (boolean): If set, generate a key and use it to
        lock data stored on the managers.
    log_driver (DriverConfig): The default log driver to use for tasks
        created in the orchestrator.

Returns:
    :py:class:`docker.types.SwarmSpec`

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.

Example:

    >>> spec = client.api.create_swarm_spec(
      snapshot_interval=5000, log_entries_for_slow_followers=1200
    )
    >>> client.api.init_swarm(
      advertise_addr='eth0', listen_addr='0.0.0.0:5000',
      force_new_cluster=False, swarm_spec=spec
    )
external_caNexternal_cas)popr   	SwarmSpec_version)selfargskwargsext_cas       #lib/third_party/docker/api/swarm.pycreate_swarm_specSwarmApiMixin.create_swarm_spec   sA    p M40&,XF>"t}}>t>v>>    z1.24c                 b    U R                  U R                  U R                  S5      5      S5      $ )zh
Get the unlock key for this Swarm manager.

Returns:
    A ``dict`` containing an ``UnlockKey`` member
z/swarm/unlockkeyT)_result_get_url)r   s    r   get_unlock_keySwarmApiMixin.get_unlock_keyJ   s(     ||DIIdii0B&CDdKKr   Nc	                    U R                  S5      n	Ub   [        U[        5      (       d  [        S5      eUbE  [        R
                  " U R                  S5      (       a  [        R                  " S5      eUc  [        nUbE  [        R
                  " U R                  S5      (       a  [        R                  " S5      eUc  [        nUUUUUUS.n
Ub@  [        R
                  " U R                  S5      (       a  [        R                  " S5      eXzS	'   Ub@  [        R
                  " U R                  S
5      (       a  [        R                  " S5      eXS'   U R                  XS9nU R                  USS9$ )aE  
Initialize a new Swarm using the current connected engine as the first
node.

Args:
    advertise_addr (string): Externally reachable address advertised
        to other nodes. This can either be an address/port combination
        in the form ``192.168.1.1:4567``, or an interface followed by a
        port number, like ``eth0:4567``. If the port number is omitted,
        the port number from the listen address is used. If
        ``advertise_addr`` is not specified, it will be automatically
        detected when possible. Default: None
    listen_addr (string): Listen address used for inter-manager
        communication, as well as determining the networking interface
        used for the VXLAN Tunnel Endpoint (VTEP). This can either be
        an address/port combination in the form ``192.168.1.1:4567``,
        or an interface followed by a port number, like ``eth0:4567``.
        If the port number is omitted, the default swarm listening port
        is used. Default: '0.0.0.0:2377'
    force_new_cluster (bool): Force creating a new Swarm, even if
        already part of one. Default: False
    swarm_spec (dict): Configuration settings of the new Swarm. Use
        ``APIClient.create_swarm_spec`` to generate a valid
        configuration. Default: None
    default_addr_pool (list of strings): Default Address Pool specifies
        default subnet pools for global scope networks. Each pool
        should be specified as a CIDR block, like '10.0.0.0/8'.
        Default: None
    subnet_size (int): SubnetSize specifies the subnet size of the
        networks created from the default subnet pool. Default: None
    data_path_addr (string): Address or interface to use for data path
        traffic. For example, 192.168.1.1, or an interface, like eth0.
    data_path_port (int): Port number to use for data path traffic.
        Acceptable port range is 1024 to 49151. If set to ``None`` or
        0, the default port 4789 will be used. Default: None

Returns:
    (str): The ID of the created node.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/swarm/initzswarm_spec must be a dictionaryz1.39z6Address pool is only available for API version >= 1.39z5Subnet size is only available for API version >= 1.39)AdvertiseAddr
ListenAddrDefaultAddrPool
SubnetSizeForceNewClusterSpec1.30;Data address path is only available for API version >= 1.30DataPathAddrz1.40z8Data path port is only available for API version >= 1.40DataPathPortdataT)json)r   
isinstancedict	TypeErrorr   
version_ltr   r   InvalidVersionr   r   
_post_jsonr   )r   advertise_addrlisten_addrforce_new_cluster
swarm_specdefault_addr_poolsubnet_sizedata_path_addrdata_path_porturlr,   responses               r   
init_swarmSwarmApiMixin.init_swarmT   sp   b ii&!*Z*F*F=>>(v66++L  "7"v66++K  !($;! ,%0%0
 %v66++*  $2 %v66++*  $2 ??3?2||H4|00r   c                 f    U R                  S5      nU R                  U R                  U5      S5      $ )z
Retrieve low-level information about the current swarm.

Returns:
    A dictionary containing data about the swarm.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/swarmTr   r   r   )r   r<   s     r   inspect_swarmSwarmApiMixin.inspect_swarm   s+     ii!||DIIcND11r   node_idc                 h    U R                  SU5      nU R                  U R                  U5      S5      $ )a  
Retrieve low-level information about a swarm node

Args:
    node_id (string): ID of the node to be inspected.

Returns:
    A dictionary containing data about this node.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.

/nodes/{0}TrA   )r   rD   r<   s      r   inspect_nodeSwarmApiMixin.inspect_node   s-      iig.||DIIcND11r   c                     UUUUS.nUb@  [         R                  " U R                  S5      (       a  [        R                  " S5      eXVS'   U R                  S5      nU R                  XvS9nU R                  U5        g)a  
Make this Engine join a swarm that has already been created.

Args:
    remote_addrs (:py:class:`list`): Addresses of one or more manager
        nodes already participating in the Swarm to join.
    join_token (string): Secret token for joining this Swarm.
    listen_addr (string): Listen address used for inter-manager
        communication if the node gets promoted to manager, as well as
        determining the networking interface used for the VXLAN Tunnel
        Endpoint (VTEP). Default: ``'0.0.0.0:2377``
    advertise_addr (string): Externally reachable address advertised
        to other nodes. This can either be an address/port combination
        in the form ``192.168.1.1:4567``, or an interface followed by a
        port number, like ``eth0:4567``. If the port number is omitted,
        the port number from the listen address is used. If
        AdvertiseAddr is not specified, it will be automatically
        detected when possible. Default: ``None``
    data_path_addr (string): Address or interface to use for data path
        traffic. For example, 192.168.1.1, or an interface, like eth0.

Returns:
    ``True`` if the request went through.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)RemoteAddrsr"   	JoinTokenr!   r'   r(   r)   z/swarm/joinr+   T)r   r1   r   r   r2   r   r3   _raise_for_status)	r   remote_addrs
join_tokenr5   r4   r:   r,   r<   r=   s	            r   
join_swarmSwarmApiMixin.join_swarm   s    @ (%#+	
 %v66++*  $2 ii&??3?2x(r   c                    U R                  S5      nU R                  USU0S9nU(       a  UR                  [        R                  :X  a  gU(       a  UR                  [        R
                  :X  a  gU R                  U5        g)a   
Leave a swarm.

Args:
    force (bool): Leave the swarm even if this node is a manager.
        Default: ``False``

Returns:
    ``True`` if the request went through.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/swarm/leaveforceparamsT)r   _poststatus_codehttp_clientNOT_ACCEPTABLESERVICE_UNAVAILABLErL   )r   rR   r<   r=   s       r   leave_swarmSwarmApiMixin.leave_swarm  sn      ii'::c7E*::;X))[-G-GG X))[-L-LLx(r   c                     U R                  S5      n0 nU(       a  [        R                  " U5      US'   U R                  U R	                  X#S9S5      $ )aX  
List swarm nodes.

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

Returns:
    A list of dictionaries containing data about each swarm node.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/nodesfiltersrS   T)r   r   convert_filtersr   r   )r   r]   r<   rT   s       r   nodesSwarmApiMixin.nodes(  sK    " ii! % 5 5g >F9||DIIcI94@@r   c                 p    U R                  SU5      nSU0nU R                  X4S9nU R                  U5        g)a  
Remove a node from the swarm.

Args:
    node_id (string): ID of the node to be removed.
    force (bool): Force remove an active node. Default: `False`

Raises:
    :py:class:`docker.errors.NotFound`
        If the node referenced doesn't exist in the swarm.

    :py:class:`docker.errors.APIError`
        If the server returns an error.
Returns:
    `True` if the request was successful.
rF   rR   rS   T)r   _deleterL   )r   rD   rR   r<   rT   ress         r   remove_nodeSwarmApiMixin.remove_node@  sC    & iig.U
 ll3l.s#r   c                     [        U[        5      (       a  SU;  a  [        R                  " S5      eOSU0nU R	                  S5      nU R                  X!S9nU R                  U5        g)a  
Unlock a locked swarm.

Args:
    key (string): The unlock key as provided by
        :py:meth:`get_unlock_key`

Raises:
    :py:class:`docker.errors.InvalidArgument`
        If the key argument is in an incompatible format

    :py:class:`docker.errors.APIError`
        If the server returns an error.

Returns:
    `True` if the request was successful.

Example:

    >>> key = client.api.get_unlock_key()
    >>> client.unlock_swarm(key)

	UnlockKeyzInvalid unlock key formatz/swarm/unlockr+   T)r.   r/   r   InvalidArgumentr   r3   rL   )r   keyr<   rc   s       r   unlock_swarmSwarmApiMixin.unlock_swarm[  sk    2 c4  #%,,-HII & $Cii(ooco,s#r   c                 |    U R                  SU[        U5      5      nU R                  XCS9nU R                  U5        g)a  
Update the node's configuration

Args:

    node_id (string): ID of the node to be updated.
    version (int): The version number of the node object being
        updated. This is required to avoid conflicting writes.
    node_spec (dict): Configuration settings to update. Any values
        not provided will be removed. Default: ``None``

Returns:
    `True` if the request went through.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.

Example:

    >>> node_spec = {'Availability': 'active',
                 'Name': 'node-name',
                 'Role': 'manager',
                 'Labels': {'foo': 'bar'}
                }
    >>> client.api.update_node(node_id='24ifsmvkjbyhk', version=8,
        node_spec=node_spec)

z/nodes/{0}/update?version={1}r+   T)r   strr3   rL   )r   rD   version	node_specr<   rc   s         r   update_nodeSwarmApiMixin.update_node  s<    > ii7#g,Oooco2s#r   c                    U R                  S5      nUUUS.nU(       a@  [        R                  " U R                  S5      (       a  [        R
                  " S5      eXWS'   U R                  XbUS9nU R                  U5        g)a  
Update the Swarm's configuration

Args:
    version (int): The version number of the swarm object being
        updated. This is required to avoid conflicting writes.
    swarm_spec (dict): Configuration settings to update. Use
        :py:meth:`~docker.api.swarm.SwarmApiMixin.create_swarm_spec` to
        generate a valid configuration. Default: ``None``.
    rotate_worker_token (bool): Rotate the worker join token. Default:
        ``False``.
    rotate_manager_token (bool): Rotate the manager join token.
        Default: ``False``.
    rotate_manager_unlock_key (bool): Rotate the manager unlock key.
        Default: ``False``.

Returns:
    ``True`` if the request went through.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/swarm/update)rotateWorkerTokenrotateManagerTokenrn   z1.25zCRotate manager unlock key is only available for API version >= 1.25rotateManagerUnlockKey)r,   rT   T)r   r   r1   r   r   r2   r3   rL   )	r   rn   r7   rotate_worker_tokenrotate_manager_tokenrotate_manager_unlock_keyr<   rT   r=   s	            r   update_swarmSwarmApiMixin.update_swarm  s    8 ii(!4"6

 %v66++@  0I+,??3?Gx(r    )N0.0.0.0:2377FNNNNN)r|   NN)F)N)NFFF)__name__
__module____qualname____firstlineno__r   r   minimum_versionr   r>   rB   check_resourcerG   rO   rZ   r_   rd   rj   rp   ry   __static_attributes__r{   r   r   r
   r
      s   ;?z 6"L #L 6":H7;7;7;`1 #`1D 6"2 #2 )$
6"2 # %2" 6"?M7;0 #0d 6" #6 6"A #A. )$
6" # %2 6"! #!F 6"! #!F 6"/3).*//4+ #+r   r
   )logginghttp.clientclientrW   	constantsr   r    r   r   r   	getLoggerr}   logr
   r{   r   r   <module>r      s3     ! J   !D Dr   