1
- import json
2
-
3
1
from ..errors import InvalidVersion
4
2
from ..utils import check_resource , minimum_version
5
3
from ..utils import version_lt
4
+ from .. import utils
6
5
7
6
8
7
class NetworkApiMixin (object ):
9
8
@minimum_version ('1.21' )
10
- def networks (self , names = None , ids = None ):
9
+ def networks (self , names = None , ids = None , filters = None ):
11
10
"""
12
11
List networks. Similar to the ``docker networks ls`` command.
13
12
14
13
Args:
15
14
names (list): List of names to filter by
16
15
ids (list): List of ids to filter by
16
+ filters (dict): Filters to be processed on the network list.
17
+ Available filters:
18
+ - ``driver=[<driver-name>]`` Matches a network's driver.
19
+ - ``label=[<key>]`` or ``label=[<key>=<value>]``.
20
+ - ``type=["custom"|"builtin"] `` Filters networks by type.
17
21
18
22
Returns:
19
23
(dict): List of network objects.
@@ -23,14 +27,13 @@ def networks(self, names=None, ids=None):
23
27
If the server returns an error.
24
28
"""
25
29
26
- filters = {}
30
+ if filters is None :
31
+ filters = {}
27
32
if names :
28
33
filters ['name' ] = names
29
34
if ids :
30
35
filters ['id' ] = ids
31
-
32
- params = {'filters' : json .dumps (filters )}
33
-
36
+ params = {'filters' : utils .convert_filters (filters )}
34
37
url = self ._url ("/networks" )
35
38
res = self ._get (url , params = params )
36
39
return self ._result (res , json = True )
0 commit comments