Added api support for creating container checkpoints

This commit is contained in:
Stanislav Dimov 2023-02-03 17:22:32 +00:00
parent d285e6103d
commit 1b6890603f
No known key found for this signature in database
GPG Key ID: 52C3CE2B376F25D2
1 changed files with 90 additions and 2 deletions

View File

@ -669,6 +669,93 @@ class ContainerApiMixin:
"""
return EndpointConfig(self._version, *args, **kwargs)
@utils.check_resource('container')
def container_checkpoints(self, container, checkpoint_dir=None):
"""
(Experimental) List all container checkpoints.
Args:
container (str): The container to find checkpoints for
checkpoint_dir (str): Custom directory in which to search for
checkpoints. Default: None (use default checkpoint dir)
Returns:
List of dicts, one for each checkpoint. In the form of:
[{"Name": "<checkpoint_name>"}]
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
params = {}
if checkpoint_dir:
params["dir"] = checkpoint_dir
return self._result(
self._get(self._url("/containers/{0}/checkpoints", container),
params=params),
True
)
@utils.check_resource('container')
def container_remove_checkpoint(self, container, checkpoint,
checkpoint_dir=None):
"""
(Experimental) Remove container checkpoint.
Args:
container (str): The container the checkpoint belongs to
checkpoint (str): The checkpoint ID to remove
checkpoint_dir (str): Custom directory in which to search for
checkpoints. Default: None (use default checkpoint dir)
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
params = {}
if checkpoint_dir:
params["dir"] = checkpoint_dir
res = self._delete(
self._url("/containers/{0}/checkpoints/{1}",
container,
checkpoint),
params=params
)
self._raise_for_status(res)
@utils.check_resource('container')
def container_create_checkpoint(self, container, checkpoint,
checkpoint_dir=None,
leave_running=False):
"""
(Experimental) Create new container checkpoint.
Args:
container (str): The container to checkpoint
checkpoint (str): The checkpoint ID
checkpoint_dir (str): Custom directory in which to place the
checkpoint. Default: None (use default checkpoint dir)
leave_running (bool): Determines if the container should be left
running after the checkpoint is created
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
data = {
"CheckpointID": checkpoint,
"Exit": not leave_running,
}
if checkpoint_dir:
data["CheckpointDir"] = checkpoint_dir
res = self._post_json(
self._url("/containers/{0}/checkpoints", container),
data=data
)
self._raise_for_status(res)
@utils.check_resource('container')
def diff(self, container):
"""
@ -1103,9 +1190,10 @@ class ContainerApiMixin:
Args:
container (str): The container to start
checkpoint (str): (Experimental) The checkpoint ID from which
to start
to start. Default: None (do not start from a checkpoint)
checkpoint_dir (str): (Experimental) Custom directory in which to
search for checkpoints
search for checkpoints. Default: None (use default
checkpoint dir)
Raises:
:py:class:`docker.errors.APIError`