
                         d    S SK Jr  S SKJr  SSKJr  SSKJrJr   " S S\5      r	 " S S	\5      r
g
)   )	APIClient)version_gte   )	Container)Model
Collectionc                   J    \ rS rSrSr\S 5       r\S 5       rS rS r	S r
Srg	)
Network   z
A Docker network.
c                 8    U R                   R                  S5      $ )z
The name of the network.
Name)attrsgetselfs    )lib/third_party/docker/models/networks.pynameNetwork.name   s    
 zz~~f%%    c                     U R                   R                  S5      =(       d    0 R                  5        Vs/ s H'  oR                  R                  R                  U5      PM)     sn$ s  snf )zy
The containers that are connected to the network, as a list of
:py:class:`~docker.models.containers.Container` objects.

Containers)r   r   keysclient
containers)r   cids     r   r   Network.containers   sW     ZZ^^L)/R557
7 14KK""&&s+7
 	
 
s   .A&c                     [        U[        5      (       a  UR                  nU R                  R                  R
                  " XR                  /UQ70 UD6$ )aJ  
Connect a container to this network.

Args:
    container (str): Container to connect to this network, as either
        an ID, name, or :py:class:`~docker.models.containers.Container`
        object.
    aliases (:py:class:`list`): A list of aliases for this endpoint.
        Names in that list can be used within the network to reach the
        container. Defaults to ``None``.
    links (:py:class:`list`): A list of links for this endpoint.
        Containers declared in this list will be linkedto this
        container. Defaults to ``None``.
    ipv4_address (str): The IP address of this container on the
        network, using the IPv4 protocol. Defaults to ``None``.
    ipv6_address (str): The IP address of this container on the
        network, using the IPv6 protocol. Defaults to ``None``.
    link_local_ips (:py:class:`list`): A list of link-local (IPv4/IPv6)
        addresses.
    driver_opt (dict): A dictionary of options to provide to the
        network driver. Defaults to ``None``.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)
isinstancer   idr   apiconnect_container_to_networkr   	containerargskwargss       r   connectNetwork.connect   sL    6 i++!I{{;;ww
!%
)/
 	
r   c                     [        U[        5      (       a  UR                  nU R                  R                  R
                  " XR                  /UQ70 UD6$ )a  
Disconnect a container from this network.

Args:
    container (str): Container to disconnect from this network, as
        either an ID, name, or
        :py:class:`~docker.models.containers.Container` object.
    force (bool): Force the container to disconnect from a network.
        Default: ``False``

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)r   r   r   r   r    !disconnect_container_from_networkr"   s       r   
disconnectNetwork.disconnect>   sL     i++!I{{@@ww
!%
)/
 	
r   c                 `    U R                   R                  R                  U R                  5      $ )zn
Remove this network.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)r   r    remove_networkr   r   s    r   removeNetwork.removeS   s!     {{--dgg66r    N)__name__
__module____qualname____firstlineno____doc__propertyr   r   r&   r*   r.   __static_attributes__r0   r   r   r
   r
      s?     & & 
 

B
*7r   r
   c                   n    \ rS rSrSr\rS rS rS r	S	S jr
\R                  R                  \
l        Srg)
NetworkCollection^   z 
Networks on the Docker server.
c                 ~    U R                   R                  R                  " U/UQ70 UD6nU R                  US   5      $ )aC  
Create a network. Similar to the ``docker network create``.

Args:
    name (str): Name of the network
    driver (str): Name of the driver used to create the network
    options (dict): Driver options as a key-value dictionary
    ipam (IPAMConfig): Optional custom IP scheme for the network.
    check_duplicate (bool): Request daemon to check for networks with
        same name. Default: ``None``.
    internal (bool): Restrict external access to the network. Default
        ``False``.
    labels (dict): Map of labels to set on the network. Default
        ``None``.
    enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
    attachable (bool): If enabled, and the network is in the global
        scope,  non-service containers on worker nodes will be able to
        connect to the network.
    scope (str): Specify the network's scope (``local``, ``global`` or
        ``swarm``)
    ingress (bool): If set, create an ingress network which provides
        the routing-mesh in swarm mode.

Returns:
    (:py:class:`Network`): The network that was created.

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

Example:
    A network using the bridge driver:

        >>> client.networks.create("network1", driver="bridge")

    You can also create more advanced networks with custom IPAM
    configurations. For example, setting the subnet to
    ``192.168.52.0/24`` and gateway address to ``192.168.52.254``.

    .. code-block:: python

        >>> ipam_pool = docker.types.IPAMPool(
            subnet='192.168.52.0/24',
            gateway='192.168.52.254'
        )
        >>> ipam_config = docker.types.IPAMConfig(
            pool_configs=[ipam_pool]
        )
        >>> client.networks.create(
            "network1",
            driver="bridge",
            ipam=ipam_config
        )

Id)r   r    create_networkr   )r   r   r$   r%   resps        r   createNetworkCollection.created   s:    p {{--dDTDVDxxT
##r   c                 t    U R                  U R                  R                  R                  " U/UQ70 UD65      $ )a  
Get a network by its ID.

Args:
    network_id (str): The ID of the network.
    verbose (bool): Retrieve the service details across the cluster in
        swarm mode.
    scope (str): Filter the network by scope (``swarm``, ``global``
        or ``local``).

Returns:
    (:py:class:`Network`) The network.

Raises:
    :py:class:`docker.errors.NotFound`
        If the network does not exist.

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

)prepare_modelr   r    inspect_network)r   
network_idr$   r%   s       r   r   NetworkCollection.get   s7    , !!KKOO++JHHH
 	
r   c                 ^   UR                  SS5      nU R                  R                  R                  " U0 UD6nU Vs/ s H  oPR	                  U5      PM     nnU(       aH  [        U R                  R                  R                  S5      (       a  U H  nUR                  5         M     U$ s  snf )a#  
List networks. Similar to the ``docker network ls`` command.

Args:
    names (:py:class:`list`): List of names to filter by.
    ids (:py:class:`list`): List of ids to filter by.
    filters (dict): Filters to be processed on the network list.
        Available filters:
        - ``driver=[<driver-name>]`` Matches a network's driver.
        - `label` (str|list): format either ``"key"``, ``"key=value"``
            or a list of such.
        - ``type=["custom"|"builtin"]`` Filters networks by type.
    greedy (bool): Fetch more details for each network individually.
        You might want this to get the containers attached to them.

Returns:
    (list of :py:class:`Network`) The networks on the server.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
greedyFz1.28)popr   r    networksrB   r   _versionreload)r   r$   r%   rG   r>   itemrI   nets           r   listNetworkCollection.list   s    . He,{{''889=>&&t,>k$++//":":FCC

  	 ?s   B*Nc                 H    U R                   R                  R                  US9$ )N)filters)r   r    prune_networks)r   rQ   s     r   pruneNetworkCollection.prune   s    {{--g->>r   r0   )N)r1   r2   r3   r4   r5   r
   modelr?   r   rN   rS   r   rR   r7   r0   r   r   r9   r9   ^   s6     E9$v
4>?,,44EMr   r9   N)r    r   utilsr   r   r   resourcer   r   r
   r9   r0   r   r   <module>rX      s.      ! 'T7e T7n|5
 |5r   