mirror of https://github.com/docker/docker-py.git
Add support for scope filter in inspect_network
Fix missing scope implementation in create_network Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
6e1f9333d3
commit
a0f6758c76
|
@ -61,6 +61,8 @@ class NetworkApiMixin(object):
|
||||||
attachable (bool): If enabled, and the network is in the global
|
attachable (bool): If enabled, and the network is in the global
|
||||||
scope, non-service containers on worker nodes will be able to
|
scope, non-service containers on worker nodes will be able to
|
||||||
connect to the network.
|
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
|
ingress (bool): If set, create an ingress network which provides
|
||||||
the routing-mesh in swarm mode.
|
the routing-mesh in swarm mode.
|
||||||
|
|
||||||
|
@ -140,6 +142,13 @@ class NetworkApiMixin(object):
|
||||||
|
|
||||||
data['Ingress'] = ingress
|
data['Ingress'] = ingress
|
||||||
|
|
||||||
|
if scope is not None:
|
||||||
|
if version_lt(self._version, '1.30'):
|
||||||
|
raise InvalidVersion(
|
||||||
|
'scope is not supported in API version < 1.30'
|
||||||
|
)
|
||||||
|
data['Scope'] = scope
|
||||||
|
|
||||||
url = self._url("/networks/create")
|
url = self._url("/networks/create")
|
||||||
res = self._post_json(url, data=data)
|
res = self._post_json(url, data=data)
|
||||||
return self._result(res, json=True)
|
return self._result(res, json=True)
|
||||||
|
@ -181,7 +190,7 @@ class NetworkApiMixin(object):
|
||||||
|
|
||||||
@minimum_version('1.21')
|
@minimum_version('1.21')
|
||||||
@check_resource('net_id')
|
@check_resource('net_id')
|
||||||
def inspect_network(self, net_id, verbose=None):
|
def inspect_network(self, net_id, verbose=None, scope=None):
|
||||||
"""
|
"""
|
||||||
Get detailed information about a network.
|
Get detailed information about a network.
|
||||||
|
|
||||||
|
@ -189,12 +198,18 @@ class NetworkApiMixin(object):
|
||||||
net_id (str): ID of network
|
net_id (str): ID of network
|
||||||
verbose (bool): Show the service details across the cluster in
|
verbose (bool): Show the service details across the cluster in
|
||||||
swarm mode.
|
swarm mode.
|
||||||
|
scope (str): Filter the network by scope (``swarm``, ``global``
|
||||||
|
or ``local``).
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
if verbose is not None:
|
if verbose is not None:
|
||||||
if version_lt(self._version, '1.28'):
|
if version_lt(self._version, '1.28'):
|
||||||
raise InvalidVersion('verbose was introduced in API 1.28')
|
raise InvalidVersion('verbose was introduced in API 1.28')
|
||||||
params['verbose'] = verbose
|
params['verbose'] = verbose
|
||||||
|
if scope is not None:
|
||||||
|
if version_lt(self._version, '1.31'):
|
||||||
|
raise InvalidVersion('scope was introduced in API 1.31')
|
||||||
|
params['scope'] = scope
|
||||||
|
|
||||||
url = self._url("/networks/{0}", net_id)
|
url = self._url("/networks/{0}", net_id)
|
||||||
res = self._get(url, params=params)
|
res = self._get(url, params=params)
|
||||||
|
|
|
@ -102,15 +102,19 @@ class NetworkCollection(Collection):
|
||||||
name (str): Name of the network
|
name (str): Name of the network
|
||||||
driver (str): Name of the driver used to create the network
|
driver (str): Name of the driver used to create the network
|
||||||
options (dict): Driver options as a key-value dictionary
|
options (dict): Driver options as a key-value dictionary
|
||||||
ipam (dict): Optional custom IP scheme for the network.
|
ipam (IPAMConfig): Optional custom IP scheme for the network.
|
||||||
Created with :py:class:`~docker.types.IPAMConfig`.
|
|
||||||
check_duplicate (bool): Request daemon to check for networks with
|
check_duplicate (bool): Request daemon to check for networks with
|
||||||
same name. Default: ``True``.
|
same name. Default: ``None``.
|
||||||
internal (bool): Restrict external access to the network. Default
|
internal (bool): Restrict external access to the network. Default
|
||||||
``False``.
|
``False``.
|
||||||
labels (dict): Map of labels to set on the network. Default
|
labels (dict): Map of labels to set on the network. Default
|
||||||
``None``.
|
``None``.
|
||||||
enable_ipv6 (bool): Enable IPv6 on the network. Default ``False``.
|
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
|
ingress (bool): If set, create an ingress network which provides
|
||||||
the routing-mesh in swarm mode.
|
the routing-mesh in swarm mode.
|
||||||
|
|
||||||
|
@ -155,6 +159,10 @@ class NetworkCollection(Collection):
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
network_id (str): The ID of the network.
|
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:
|
Returns:
|
||||||
(:py:class:`Network`) The network.
|
(:py:class:`Network`) The network.
|
||||||
|
|
|
@ -465,3 +465,22 @@ class TestNetworks(BaseAPIIntegrationTest):
|
||||||
net_name, _ = self.create_network()
|
net_name, _ = self.create_network()
|
||||||
result = self.client.prune_networks()
|
result = self.client.prune_networks()
|
||||||
assert net_name in result['NetworksDeleted']
|
assert net_name in result['NetworksDeleted']
|
||||||
|
|
||||||
|
@requires_api_version('1.31')
|
||||||
|
def test_create_inspect_network_with_scope(self):
|
||||||
|
assert self.init_swarm()
|
||||||
|
net_name_loc, net_id_loc = self.create_network(scope='local')
|
||||||
|
|
||||||
|
assert self.client.inspect_network(net_name_loc)
|
||||||
|
assert self.client.inspect_network(net_name_loc, scope='local')
|
||||||
|
with pytest.raises(docker.errors.NotFound):
|
||||||
|
self.client.inspect_network(net_name_loc, scope='global')
|
||||||
|
|
||||||
|
net_name_swarm, net_id_swarm = self.create_network(
|
||||||
|
driver='overlay', scope='swarm'
|
||||||
|
)
|
||||||
|
|
||||||
|
assert self.client.inspect_network(net_name_swarm)
|
||||||
|
assert self.client.inspect_network(net_name_swarm, scope='swarm')
|
||||||
|
with pytest.raises(docker.errors.NotFound):
|
||||||
|
self.client.inspect_network(net_name_swarm, scope='local')
|
||||||
|
|
Loading…
Reference in New Issue