From 9047263354114dd3cd4e6cb7e5cdbd02fc0e61d7 Mon Sep 17 00:00:00 2001 From: Lobsiinvok Date: Mon, 19 Dec 2016 15:07:29 +0800 Subject: Add filters option to NetworkApiMixin.networks Signed-off-by: Boik --- docker/api/network.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docker/api/network.py b/docker/api/network.py index c58ea6e..7ccda55 100644 --- a/docker/api/network.py +++ b/docker/api/network.py @@ -1,19 +1,23 @@ -import json - from ..errors import InvalidVersion from ..utils import check_resource, minimum_version from ..utils import version_lt +from .. import utils class NetworkApiMixin(object): @minimum_version('1.21') - def networks(self, names=None, ids=None): + def networks(self, names=None, ids=None, filters=None): """ List networks. Similar to the ``docker networks ls`` command. Args: names (list): List of names to filter by ids (list): List of ids to filter by + filters (dict): Filters to be processed on the network list. + Available filters: + - ``driver=[]`` Matches a network's driver. + - ``label=[]`` or ``label=[=]``. + - ``type=["custom"|"builtin"] `` Filters networks by type. Returns: (dict): List of network objects. @@ -23,14 +27,13 @@ class NetworkApiMixin(object): If the server returns an error. """ - filters = {} + if filters is None: + filters = {} if names: filters['name'] = names if ids: filters['id'] = ids - - params = {'filters': json.dumps(filters)} - + params = {'filters': utils.convert_filters(filters)} url = self._url("/networks") res = self._get(url, params=params) return self._result(res, json=True) -- cgit v1.2.1