File tree 3 files changed +25
-1
lines changed 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -262,14 +262,16 @@ def remove_service(self, service):
262
262
return True
263
263
264
264
@utils .minimum_version ('1.24' )
265
- def services (self , filters = None ):
265
+ def services (self , filters = None , status = None ):
266
266
"""
267
267
List services.
268
268
269
269
Args:
270
270
filters (dict): Filters to process on the nodes list. Valid
271
271
filters: ``id``, ``name`` , ``label`` and ``mode``.
272
272
Default: ``None``.
273
+ status (bool): Include the service task count of running and
274
+ desired tasks. Default: ``None``.
273
275
274
276
Returns:
275
277
A list of dictionaries containing data about each service.
@@ -281,6 +283,12 @@ def services(self, filters=None):
281
283
params = {
282
284
'filters' : utils .convert_filters (filters ) if filters else None
283
285
}
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
284
292
url = self ._url ('/services' )
285
293
return self ._result (self ._get (url , params = params ), True )
286
294
Original file line number Diff line number Diff line change @@ -266,6 +266,8 @@ def list(self, **kwargs):
266
266
filters (dict): Filters to process on the nodes list. Valid
267
267
filters: ``id``, ``name`` , ``label`` and ``mode``.
268
268
Default: ``None``.
269
+ status (bool): Include the service task count of running and
270
+ desired tasks. Default: ``None``.
269
271
270
272
Returns:
271
273
list of :py:class:`Service`: The services.
Original file line number Diff line number Diff line change @@ -85,6 +85,20 @@ def test_list_services_filter_by_label(self):
85
85
assert len (test_services ) == 1
86
86
assert test_services [0 ]['Spec' ]['Labels' ]['test_label' ] == 'testing'
87
87
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
+
88
102
def test_inspect_service_by_id (self ):
89
103
svc_name , svc_id = self .create_simple_service ()
90
104
svc_info = self .client .inspect_service (svc_id )
You can’t perform that action at this time.
0 commit comments