Skip to content

Commit af00714

Browse files
committed
Add support for insert_defaults in inspect_service
Signed-off-by: Joffrey F <[email protected]>
1 parent ecca6e0 commit af00714

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

docker/api/service.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,14 @@ def create_service(
136136

137137
@utils.minimum_version('1.24')
138138
@utils.check_resource('service')
139-
def inspect_service(self, service):
139+
def inspect_service(self, service, insert_defaults=None):
140140
"""
141141
Return information about a service.
142142
143143
Args:
144-
service (str): Service name or ID
144+
service (str): Service name or ID.
145+
insert_defaults (boolean): If true, default values will be merged
146+
into the service inspect output.
145147
146148
Returns:
147149
``True`` if successful.
@@ -151,7 +153,15 @@ def inspect_service(self, service):
151153
If the server returns an error.
152154
"""
153155
url = self._url('/services/{0}', service)
154-
return self._result(self._get(url), True)
156+
params = {}
157+
if insert_defaults is not None:
158+
if utils.version_lt(self._version, '1.29'):
159+
raise errors.InvalidVersion(
160+
'insert_defaults is not supported in API version < 1.29'
161+
)
162+
params['insertDefaults'] = insert_defaults
163+
164+
return self._result(self._get(url, params=params), True)
155165

156166
@utils.minimum_version('1.24')
157167
@utils.check_resource('task')

docker/models/services.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ def create(self, image, command=None, **kwargs):
177177
service_id = self.client.api.create_service(**create_kwargs)
178178
return self.get(service_id)
179179

180-
def get(self, service_id):
180+
def get(self, service_id, insert_defaults=None):
181181
"""
182182
Get a service.
183183
184184
Args:
185185
service_id (str): The ID of the service.
186+
insert_defaults (boolean): If true, default values will be merged
187+
into the output.
186188
187189
Returns:
188190
(:py:class:`Service`): The service.
@@ -192,8 +194,13 @@ def get(self, service_id):
192194
If the service does not exist.
193195
:py:class:`docker.errors.APIError`
194196
If the server returns an error.
197+
:py:class:`docker.errors.InvalidVersion`
198+
If one of the arguments is not supported with the current
199+
API version.
195200
"""
196-
return self.prepare_model(self.client.api.inspect_service(service_id))
201+
return self.prepare_model(
202+
self.client.api.inspect_service(service_id, insert_defaults)
203+
)
197204

198205
def list(self, **kwargs):
199206
"""

tests/integration/api_service_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ def test_inspect_service_by_name(self):
9999
assert 'ID' in svc_info
100100
assert svc_info['ID'] == svc_id['ID']
101101

102+
@requires_api_version('1.29')
103+
def test_inspect_service_insert_defaults(self):
104+
svc_name, svc_id = self.create_simple_service()
105+
svc_info = self.client.inspect_service(svc_id)
106+
svc_info_defaults = self.client.inspect_service(
107+
svc_id, insert_defaults=True
108+
)
109+
assert svc_info != svc_info_defaults
110+
assert 'RollbackConfig' in svc_info_defaults['Spec']
111+
assert 'RollbackConfig' not in svc_info['Spec']
112+
102113
def test_remove_service_by_id(self):
103114
svc_name, svc_id = self.create_simple_service()
104115
assert self.client.remove_service(svc_id)

0 commit comments

Comments
 (0)