Skip to content

Commit 48f8b63

Browse files
YASWANTH PUPPALAYASWANTH PUPPALA
YASWANTH PUPPALA
authored and
YASWANTH PUPPALA
committed
Resolved issue docker#3311 (UnixHTTPConnection updating number of connections) and issue docker#3304 (signal argument is now added to container.stop and container.restart)
1 parent db7f8b8 commit 48f8b63

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

docker/api/container.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,26 +1074,27 @@ def resize(self, container, height, width):
10741074
self._raise_for_status(res)
10751075

10761076
@utils.check_resource('container')
1077-
def restart(self, container, timeout=10):
1077+
def restart(self, container, timeout=10, signal=None):
10781078
"""
10791079
Restart a container. Similar to the ``docker restart`` command.
10801080
10811081
Args:
1082-
container (str or dict): The container to restart. If a dict, the
1083-
``Id`` key is used.
1084-
timeout (int): Number of seconds to try to stop for before killing
1085-
the container. Once killed it will then be restarted. Default
1086-
is 10 seconds.
1082+
container (str or dict): The container to restart. If a dict, the ``Id`` key is used.
1083+
timeout (int): Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default is 10 seconds.
1084+
signal (str, optional): The signal to send when stopping the container. Defaults to None, which uses the server's default behavior.
10871085
10881086
Raises:
1089-
:py:class:`docker.errors.APIError`
1090-
If the server returns an error.
1087+
:py:class:`docker.errors.APIError`
1088+
If the server returns an error.
10911089
"""
10921090
params = {'t': timeout}
1091+
if signal is not None:
1092+
params['signal'] = signal
1093+
10931094
url = self._url("/containers/{0}/restart", container)
10941095
conn_timeout = self.timeout
10951096
if conn_timeout is not None:
1096-
conn_timeout += timeout
1097+
conn_timeout += timeout
10971098
res = self._post(url, params=params, timeout=conn_timeout)
10981099
self._raise_for_status(res)
10991100

@@ -1184,30 +1185,33 @@ def stats(self, container, decode=None, stream=True, one_shot=None):
11841185
return self._result(self._get(url, params=params), json=True)
11851186

11861187
@utils.check_resource('container')
1187-
def stop(self, container, timeout=None):
1188+
def stop(self, container, timeout=None, signal=None):
11881189
"""
11891190
Stops a container. Similar to the ``docker stop`` command.
11901191
11911192
Args:
1192-
container (str): The container to stop
1193-
timeout (int): Timeout in seconds to wait for the container to
1194-
stop before sending a ``SIGKILL``. If None, then the
1195-
StopTimeout value of the container will be used.
1196-
Default: None
1193+
container (str): The container to stop.
1194+
timeout (int): Timeout in seconds to wait for the container to stop before sending a ``SIGKILL``. If None, then the StopTimeout value of the container will be used. Default: None.
1195+
signal (str, optional): The signal to send when stopping the container. If not specified, the server's default behavior is used.
11971196
11981197
Raises:
1199-
:py:class:`docker.errors.APIError`
1200-
If the server returns an error.
1198+
:py:class:`docker.errors.APIError`
1199+
If the server returns an error.
12011200
"""
12021201
if timeout is None:
1203-
params = {}
1204-
timeout = 10
1202+
params = {}
1203+
timeout_val = 10
12051204
else:
1206-
params = {'t': timeout}
1205+
params = {'t': timeout}
1206+
timeout_val = timeout
1207+
1208+
if signal is not None:
1209+
params['signal'] = signal
1210+
12071211
url = self._url("/containers/{0}/stop", container)
12081212
conn_timeout = self.timeout
12091213
if conn_timeout is not None:
1210-
conn_timeout += timeout
1214+
conn_timeout += timeout_val
12111215
res = self._post(url, params=params, timeout=conn_timeout)
12121216
self._raise_for_status(res)
12131217

docker/transport/unixconn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
3737
self.timeout = timeout
3838

3939
def _new_conn(self):
40+
self.num_connections += 1
4041
return UnixHTTPConnection(
41-
self.base_url, self.socket_path, self.timeout
42+
self.base_url, self.socket_path, self.timeout
4243
)
4344

4445

0 commit comments

Comments
 (0)