Skip to content

Commit 7cd7458

Browse files
authored
api: add status parameter to services list (#3093)
Signed-off-by: Lorin Bucher <[email protected]>
1 parent e9d4ddf commit 7cd7458

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

docker/api/service.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,16 @@ def remove_service(self, service):
262262
return True
263263

264264
@utils.minimum_version('1.24')
265-
def services(self, filters=None):
265+
def services(self, filters=None, status=None):
266266
"""
267267
List services.
268268
269269
Args:
270270
filters (dict): Filters to process on the nodes list. Valid
271271
filters: ``id``, ``name`` , ``label`` and ``mode``.
272272
Default: ``None``.
273+
status (bool): Include the service task count of running and
274+
desired tasks. Default: ``None``.
273275
274276
Returns:
275277
A list of dictionaries containing data about each service.
@@ -281,6 +283,12 @@ def services(self, filters=None):
281283
params = {
282284
'filters': utils.convert_filters(filters) if filters else None
283285
}
286+
if status is not None:
287+
if utils.version_lt(self._version, '1.41'):
288+
raise errors.InvalidVersion(
289+
'status is not supported in API version < 1.41'
290+
)
291+
params['status'] = status
284292
url = self._url('/services')
285293
return self._result(self._get(url, params=params), True)
286294

docker/models/services.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def list(self, **kwargs):
266266
filters (dict): Filters to process on the nodes list. Valid
267267
filters: ``id``, ``name`` , ``label`` and ``mode``.
268268
Default: ``None``.
269+
status (bool): Include the service task count of running and
270+
desired tasks. Default: ``None``.
269271
270272
Returns:
271273
list of :py:class:`Service`: The services.

tests/integration/api_service_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ def test_list_services_filter_by_label(self):
8585
assert len(test_services) == 1
8686
assert test_services[0]['Spec']['Labels']['test_label'] == 'testing'
8787

88+
@requires_api_version('1.41')
89+
def test_list_services_with_status(self):
90+
test_services = self.client.services()
91+
assert len(test_services) == 0
92+
self.create_simple_service()
93+
test_services = self.client.services(
94+
filters={'name': 'dockerpytest_'}, status=False
95+
)
96+
assert 'ServiceStatus' not in test_services[0]
97+
test_services = self.client.services(
98+
filters={'name': 'dockerpytest_'}, status=True
99+
)
100+
assert 'ServiceStatus' in test_services[0]
101+
88102
def test_inspect_service_by_id(self):
89103
svc_name, svc_id = self.create_simple_service()
90104
svc_info = self.client.inspect_service(svc_id)

0 commit comments

Comments
 (0)