api/types: move checkpoint-types to api/types/checkpoint
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3e5b2a6ef6
commit
b688af2226
16 changed files with 93 additions and 66 deletions
|
@ -1,10 +1,10 @@
|
|||
package checkpoint // import "github.com/docker/docker/api/server/router/checkpoint"
|
||||
|
||||
import "github.com/docker/docker/api/types"
|
||||
import "github.com/docker/docker/api/types/checkpoint"
|
||||
|
||||
// Backend for Checkpoint
|
||||
type Backend interface {
|
||||
CheckpointCreate(container string, config types.CheckpointCreateOptions) error
|
||||
CheckpointDelete(container string, config types.CheckpointDeleteOptions) error
|
||||
CheckpointList(container string, config types.CheckpointListOptions) ([]types.Checkpoint, error)
|
||||
CheckpointCreate(container string, config checkpoint.CreateOptions) error
|
||||
CheckpointDelete(container string, config checkpoint.DeleteOptions) error
|
||||
CheckpointList(container string, config checkpoint.ListOptions) ([]checkpoint.Summary, error)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
|
@ -13,7 +13,7 @@ func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.R
|
|||
return err
|
||||
}
|
||||
|
||||
var options types.CheckpointCreateOptions
|
||||
var options checkpoint.CreateOptions
|
||||
if err := httputils.ReadJSON(r, &options); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
|
|||
return err
|
||||
}
|
||||
|
||||
checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
|
||||
checkpoints, err := s.backend.CheckpointList(vars["name"], checkpoint.ListOptions{
|
||||
CheckpointDir: r.Form.Get("dir"),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -47,7 +47,7 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http
|
|||
return err
|
||||
}
|
||||
|
||||
err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{
|
||||
err := s.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{
|
||||
CheckpointDir: r.Form.Get("dir"),
|
||||
CheckpointID: vars["checkpoint"],
|
||||
})
|
||||
|
|
7
api/types/checkpoint/list.go
Normal file
7
api/types/checkpoint/list.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package checkpoint
|
||||
|
||||
// Summary represents the details of a checkpoint when listing endpoints.
|
||||
type Summary struct {
|
||||
// Name is the name of the checkpoint.
|
||||
Name string
|
||||
}
|
19
api/types/checkpoint/options.go
Normal file
19
api/types/checkpoint/options.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package checkpoint
|
||||
|
||||
// CreateOptions holds parameters to create a checkpoint from a container.
|
||||
type CreateOptions struct {
|
||||
CheckpointID string
|
||||
CheckpointDir string
|
||||
Exit bool
|
||||
}
|
||||
|
||||
// ListOptions holds parameters to list checkpoints for a container.
|
||||
type ListOptions struct {
|
||||
CheckpointDir string
|
||||
}
|
||||
|
||||
// DeleteOptions holds parameters to delete a checkpoint from a container.
|
||||
type DeleteOptions struct {
|
||||
CheckpointID string
|
||||
CheckpointDir string
|
||||
}
|
|
@ -11,24 +11,6 @@ import (
|
|||
units "github.com/docker/go-units"
|
||||
)
|
||||
|
||||
// CheckpointCreateOptions holds parameters to create a checkpoint from a container
|
||||
type CheckpointCreateOptions struct {
|
||||
CheckpointID string
|
||||
CheckpointDir string
|
||||
Exit bool
|
||||
}
|
||||
|
||||
// CheckpointListOptions holds parameters to list checkpoints for a container
|
||||
type CheckpointListOptions struct {
|
||||
CheckpointDir string
|
||||
}
|
||||
|
||||
// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
|
||||
type CheckpointDeleteOptions struct {
|
||||
CheckpointID string
|
||||
CheckpointDir string
|
||||
}
|
||||
|
||||
// ContainerAttachOptions holds parameters to attach to a container.
|
||||
type ContainerAttachOptions struct {
|
||||
Stream bool
|
||||
|
|
|
@ -494,11 +494,6 @@ type NetworkInspectOptions struct {
|
|||
Verbose bool
|
||||
}
|
||||
|
||||
// Checkpoint represents the details of a checkpoint
|
||||
type Checkpoint struct {
|
||||
Name string // Name is the name of the checkpoint
|
||||
}
|
||||
|
||||
// DiskUsageObject represents an object type used for disk usage query filtering.
|
||||
type DiskUsageObject string
|
||||
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
package types
|
||||
|
||||
import "github.com/docker/docker/api/types/system"
|
||||
import (
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
"github.com/docker/docker/api/types/system"
|
||||
)
|
||||
|
||||
// CheckpointCreateOptions holds parameters to create a checkpoint from a container.
|
||||
//
|
||||
// Deprecated: use [checkpoint.CreateOptions].
|
||||
type CheckpointCreateOptions = checkpoint.CreateOptions
|
||||
|
||||
// CheckpointListOptions holds parameters to list checkpoints for a container
|
||||
//
|
||||
// Deprecated: use [checkpoint.ListOptions].
|
||||
type CheckpointListOptions = checkpoint.ListOptions
|
||||
|
||||
// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
|
||||
//
|
||||
// Deprecated: use [checkpoint.DeleteOptions].
|
||||
type CheckpointDeleteOptions = checkpoint.DeleteOptions
|
||||
|
||||
// Checkpoint represents the details of a checkpoint when listing endpoints.
|
||||
//
|
||||
// Deprecated: use [checkpoint.Summary].
|
||||
type Checkpoint = checkpoint.Summary
|
||||
|
||||
// Info contains response of Engine API:
|
||||
// GET "/info"
|
||||
|
|
|
@ -3,11 +3,11 @@ package client // import "github.com/docker/docker/client"
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
// CheckpointCreate creates a checkpoint from the given container with the given name
|
||||
func (cli *Client) CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error {
|
||||
func (cli *Client) CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error {
|
||||
resp, err := cli.post(ctx, "/containers/"+container+"/checkpoints", nil, options, nil)
|
||||
ensureReaderClosed(resp)
|
||||
return err
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
|
@ -20,7 +20,7 @@ func TestCheckpointCreateError(t *testing.T) {
|
|||
client := &Client{
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{
|
||||
err := client.CheckpointCreate(context.Background(), "nothing", checkpoint.CreateOptions{
|
||||
CheckpointID: "noting",
|
||||
Exit: true,
|
||||
})
|
||||
|
@ -43,7 +43,7 @@ func TestCheckpointCreate(t *testing.T) {
|
|||
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
|
||||
}
|
||||
|
||||
createOptions := &types.CheckpointCreateOptions{}
|
||||
createOptions := &checkpoint.CreateOptions{}
|
||||
if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func TestCheckpointCreate(t *testing.T) {
|
|||
}),
|
||||
}
|
||||
|
||||
err := client.CheckpointCreate(context.Background(), expectedContainerID, types.CheckpointCreateOptions{
|
||||
err := client.CheckpointCreate(context.Background(), expectedContainerID, checkpoint.CreateOptions{
|
||||
CheckpointID: expectedCheckpointID,
|
||||
Exit: true,
|
||||
})
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
// CheckpointDelete deletes the checkpoint with the given name from the given container
|
||||
func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options types.CheckpointDeleteOptions) error {
|
||||
func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error {
|
||||
query := url.Values{}
|
||||
if options.CheckpointDir != "" {
|
||||
query.Set("dir", options.CheckpointDir)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
|
@ -20,7 +20,7 @@ func TestCheckpointDeleteError(t *testing.T) {
|
|||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
|
||||
err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
|
||||
err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
|
||||
CheckpointID: "checkpoint_id",
|
||||
})
|
||||
|
||||
|
@ -45,7 +45,7 @@ func TestCheckpointDelete(t *testing.T) {
|
|||
}),
|
||||
}
|
||||
|
||||
err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
|
||||
err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
|
||||
CheckpointID: "checkpoint_id",
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
"encoding/json"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
// CheckpointList returns the checkpoints of the given container in the docker host
|
||||
func (cli *Client) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
|
||||
var checkpoints []types.Checkpoint
|
||||
func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) {
|
||||
var checkpoints []checkpoint.Summary
|
||||
|
||||
query := url.Values{}
|
||||
if options.CheckpointDir != "" {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
|
@ -21,7 +21,7 @@ func TestCheckpointListError(t *testing.T) {
|
|||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
|
||||
_, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
|
||||
_, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ func TestCheckpointList(t *testing.T) {
|
|||
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
||||
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
||||
}
|
||||
content, err := json.Marshal([]types.Checkpoint{
|
||||
content, err := json.Marshal([]checkpoint.Summary{
|
||||
{
|
||||
Name: "checkpoint",
|
||||
},
|
||||
|
@ -48,7 +48,7 @@ func TestCheckpointList(t *testing.T) {
|
|||
}),
|
||||
}
|
||||
|
||||
checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
|
||||
checkpoints, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -62,6 +62,6 @@ func TestCheckpointListContainerNotFound(t *testing.T) {
|
|||
client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
|
||||
}
|
||||
|
||||
_, err := client.CheckpointList(context.Background(), "unknown", types.CheckpointListOptions{})
|
||||
_, err := client.CheckpointList(context.Background(), "unknown", checkpoint.ListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package client // import "github.com/docker/docker/client"
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
)
|
||||
|
||||
type apiClientExperimental interface {
|
||||
|
@ -12,7 +12,7 @@ type apiClientExperimental interface {
|
|||
|
||||
// CheckpointAPIClient defines API client methods for the checkpoints
|
||||
type CheckpointAPIClient interface {
|
||||
CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error
|
||||
CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error
|
||||
CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)
|
||||
CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error
|
||||
CheckpointDelete(ctx context.Context, container string, options checkpoint.DeleteOptions) error
|
||||
CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
"github.com/docker/docker/daemon/names"
|
||||
)
|
||||
|
||||
|
@ -51,7 +51,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s
|
|||
}
|
||||
|
||||
// CheckpointCreate checkpoints the process running in a container with CRIU
|
||||
func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreateOptions) error {
|
||||
func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateOptions) error {
|
||||
container, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -85,7 +85,7 @@ func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreat
|
|||
}
|
||||
|
||||
// CheckpointDelete deletes the specified checkpoint
|
||||
func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDeleteOptions) error {
|
||||
func (daemon *Daemon) CheckpointDelete(name string, config checkpoint.DeleteOptions) error {
|
||||
container, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -98,8 +98,8 @@ func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDelet
|
|||
}
|
||||
|
||||
// CheckpointList lists all checkpoints of the specified container
|
||||
func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOptions) ([]types.Checkpoint, error) {
|
||||
var out []types.Checkpoint
|
||||
func (daemon *Daemon) CheckpointList(name string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) {
|
||||
var out []checkpoint.Summary
|
||||
|
||||
container, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
|
@ -124,7 +124,7 @@ func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOpt
|
|||
if !d.IsDir() {
|
||||
continue
|
||||
}
|
||||
cpt := types.Checkpoint{Name: d.Name()}
|
||||
cpt := checkpoint.Summary{Name: d.Name()}
|
||||
out = append(out, cpt)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/checkpoint"
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
|
@ -56,7 +57,7 @@ func TestCheckpoint(t *testing.T) {
|
|||
poll.WithDelay(100*time.Millisecond),
|
||||
)
|
||||
|
||||
cptOpt := types.CheckpointCreateOptions{
|
||||
cptOpt := checkpoint.CreateOptions{
|
||||
Exit: false,
|
||||
CheckpointID: "test",
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ func TestCheckpoint(t *testing.T) {
|
|||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(true, inspect.State.Running))
|
||||
|
||||
checkpoints, err := apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{})
|
||||
checkpoints, err := apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(checkpoints), 1)
|
||||
assert.Equal(t, checkpoints[0].Name, "test")
|
||||
|
@ -109,7 +110,7 @@ func TestCheckpoint(t *testing.T) {
|
|||
containerExec(t, apiClient, cID, []string{"touch", "/tmp/test-file"})
|
||||
|
||||
// Do a second checkpoint
|
||||
cptOpt = types.CheckpointCreateOptions{
|
||||
cptOpt = checkpoint.CreateOptions{
|
||||
Exit: true,
|
||||
CheckpointID: "test2",
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ func TestCheckpoint(t *testing.T) {
|
|||
assert.Check(t, is.Equal(false, inspect.State.Running))
|
||||
|
||||
// Check that both checkpoints are listed.
|
||||
checkpoints, err = apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{})
|
||||
checkpoints, err = apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, len(checkpoints), 2)
|
||||
cptNames := make([]string, 2)
|
||||
|
@ -154,7 +155,7 @@ func TestCheckpoint(t *testing.T) {
|
|||
containerExec(t, apiClient, cID, []string{"test", "-f", "/tmp/test-file"})
|
||||
|
||||
for _, id := range []string{"test", "test2"} {
|
||||
cptDelOpt := types.CheckpointDeleteOptions{
|
||||
cptDelOpt := checkpoint.DeleteOptions{
|
||||
CheckpointID: id,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue