Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support checkpoint restore #3094

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added api support for creating container checkpoints
astro-stan committed Feb 3, 2023
commit 1b6890603fdc0821eab3dd2dd6c8be3348c1e137
92 changes: 90 additions & 2 deletions docker/api/container.py
Original file line number Diff line number Diff line change
@@ -669,6 +669,93 @@ def create_endpoint_config(self, *args, **kwargs):
"""
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 @@ def start(self, container, checkpoint=None, checkpoint_dir=None,
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`