summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Baldo <git@baldoalessandro.net>2017-11-01 01:44:21 +0100
committerJoffrey F <f.joffrey@gmail.com>2017-11-01 15:18:05 -0700
commit76b138a0a1c4258517cf8f6876028bbc810166d7 (patch)
treeed162130b3df518b6bc2f6c2227838cac594588c
parentbb148380e1ea92e26c8e4dc783dd18b8a39506c0 (diff)
downloaddocker-py-76b138a0a1c4258517cf8f6876028bbc810166d7.tar.gz
Improve docs for service list filters
- add "label" and "mode" to the list of available filter keys in the high-level service API - add "label" and "mode" to the list of available filter keys in the low-level service API - add integration tests Signed-off-by: Alessandro Baldo <git@baldoalessandro.net>
-rw-r--r--docker/api/service.py3
-rw-r--r--docker/models/services.py3
-rw-r--r--tests/integration/api_service_test.py15
3 files changed, 17 insertions, 4 deletions
diff --git a/docker/api/service.py b/docker/api/service.py
index 9ce830c..e6b4876 100644
--- a/docker/api/service.py
+++ b/docker/api/service.py
@@ -201,7 +201,8 @@ class ServiceApiMixin(object):
Args:
filters (dict): Filters to process on the nodes list. Valid
- filters: ``id`` and ``name``. Default: ``None``.
+ filters: ``id``, ``name`` , ``label`` and ``mode``.
+ Default: ``None``.
Returns:
A list of dictionaries containing data about each service.
diff --git a/docker/models/services.py b/docker/models/services.py
index d45621b..f2a5d35 100644
--- a/docker/models/services.py
+++ b/docker/models/services.py
@@ -201,7 +201,8 @@ class ServiceCollection(Collection):
Args:
filters (dict): Filters to process on the nodes list. Valid
- filters: ``id`` and ``name``. Default: ``None``.
+ filters: ``id``, ``name`` , ``label`` and ``mode``.
+ Default: ``None``.
Returns:
(list of :py:class:`Service`): The services.
diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py
index baa6afa..8c6d4af 100644
--- a/tests/integration/api_service_test.py
+++ b/tests/integration/api_service_test.py
@@ -52,7 +52,7 @@ class ServiceTest(BaseAPIIntegrationTest):
return None
time.sleep(interval)
- def create_simple_service(self, name=None):
+ def create_simple_service(self, name=None, labels=None):
if name:
name = 'dockerpytest_{0}'.format(name)
else:
@@ -62,7 +62,9 @@ class ServiceTest(BaseAPIIntegrationTest):
BUSYBOX, ['echo', 'hello']
)
task_tmpl = docker.types.TaskTemplate(container_spec)
- return name, self.client.create_service(task_tmpl, name=name)
+ return name, self.client.create_service(
+ task_tmpl, name=name, labels=labels
+ )
@requires_api_version('1.24')
def test_list_services(self):
@@ -76,6 +78,15 @@ class ServiceTest(BaseAPIIntegrationTest):
assert len(test_services) == 1
assert 'dockerpytest_' in test_services[0]['Spec']['Name']
+ @requires_api_version('1.24')
+ def test_list_services_filter_by_label(self):
+ test_services = self.client.services(filters={'label': 'test_label'})
+ assert len(test_services) == 0
+ self.create_simple_service(labels={'test_label': 'testing'})
+ test_services = self.client.services(filters={'label': 'test_label'})
+ assert len(test_services) == 1
+ assert test_services[0]['Spec']['Labels']['test_label'] == 'testing'
+
def test_inspect_service_by_id(self):
svc_name, svc_id = self.create_simple_service()
svc_info = self.client.inspect_service(svc_id)