Allow providing a custom storage directory for docker checkpoints

Signed-off-by: boucher <rboucher@gmail.com>
This commit is contained in:
boucher 2016-09-19 12:01:16 -04:00
parent 4c7160ed7b
commit a38761aba4
6 changed files with 34 additions and 10 deletions

View File

@ -1,12 +1,20 @@
package client package client
import ( import (
"net/url"
"github.com/docker/docker/api/types"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// CheckpointDelete deletes the checkpoint with the given name from the given container // CheckpointDelete deletes the checkpoint with the given name from the given container
func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, checkpointID string) error { func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options types.CheckpointDeleteOptions) error {
resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+checkpointID, nil, nil) query := url.Values{}
if options.CheckpointDir != "" {
query.Set("dir", options.CheckpointDir)
}
resp, err := cli.delete(ctx, "/containers/"+containerID+"/checkpoints/"+options.CheckpointID, query, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err
} }

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/api/types"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -16,7 +17,10 @@ func TestCheckpointDeleteError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
} }
err := client.CheckpointDelete(context.Background(), "container_id", "checkpoint_id") err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
CheckpointID: "checkpoint_id",
})
if err == nil || err.Error() != "Error response from daemon: Server error" { if err == nil || err.Error() != "Error response from daemon: Server error" {
t.Fatalf("expected a Server Error, got %v", err) t.Fatalf("expected a Server Error, got %v", err)
} }
@ -40,7 +44,10 @@ func TestCheckpointDelete(t *testing.T) {
}), }),
} }
err := client.CheckpointDelete(context.Background(), "container_id", "checkpoint_id") err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
CheckpointID: "checkpoint_id",
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -2,16 +2,22 @@ package client
import ( import (
"encoding/json" "encoding/json"
"net/url"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// CheckpointList returns the volumes configured in the docker host. // CheckpointList returns the volumes configured in the docker host.
func (cli *Client) CheckpointList(ctx context.Context, container string) ([]types.Checkpoint, error) { func (cli *Client) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
var checkpoints []types.Checkpoint var checkpoints []types.Checkpoint
resp, err := cli.get(ctx, "/containers/"+container+"/checkpoints", nil, nil) query := url.Values{}
if options.CheckpointDir != "" {
query.Set("dir", options.CheckpointDir)
}
resp, err := cli.get(ctx, "/containers/"+container+"/checkpoints", query, nil)
if err != nil { if err != nil {
return checkpoints, err return checkpoints, err
} }

View File

@ -18,7 +18,7 @@ func TestCheckpointListError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
} }
_, err := client.CheckpointList(context.Background(), "container_id") _, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
if err == nil || err.Error() != "Error response from daemon: Server error" { if err == nil || err.Error() != "Error response from daemon: Server error" {
t.Fatalf("expected a Server Error, got %v", err) t.Fatalf("expected a Server Error, got %v", err)
} }
@ -47,7 +47,7 @@ func TestCheckpointList(t *testing.T) {
}), }),
} }
checkpoints, err := client.CheckpointList(context.Background(), "container_id") checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -14,6 +14,9 @@ func (cli *Client) ContainerStart(ctx context.Context, containerID string, optio
if len(options.CheckpointID) != 0 { if len(options.CheckpointID) != 0 {
query.Set("checkpoint", options.CheckpointID) query.Set("checkpoint", options.CheckpointID)
} }
if len(options.CheckpointDir) != 0 {
query.Set("checkpoint-dir", options.CheckpointDir)
}
resp, err := cli.post(ctx, "/containers/"+containerID+"/start", query, nil, nil) resp, err := cli.post(ctx, "/containers/"+containerID+"/start", query, nil, nil)
ensureReaderClosed(resp) ensureReaderClosed(resp)

View File

@ -13,8 +13,8 @@ type apiClientExperimental interface {
// CheckpointAPIClient defines API client methods for the checkpoints // CheckpointAPIClient defines API client methods for the checkpoints
type CheckpointAPIClient interface { type CheckpointAPIClient interface {
CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error
CheckpointDelete(ctx context.Context, container string, checkpointID string) error CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error
CheckpointList(ctx context.Context, container string) ([]types.Checkpoint, error) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)
} }
// PluginAPIClient defines API client methods for the plugins // PluginAPIClient defines API client methods for the plugins