diff --git a/docker/api/container.py b/docker/api/container.py index 2829a109..14af5cc5 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -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": ""}] + + 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`