/
interface.go
36 lines (27 loc) · 1.14 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package migrator
import (
"context"
"github.com/pouchcontainer/d2p-migrator/ctrd"
"github.com/pouchcontainer/d2p-migrator/docker"
)
var migratorFactory map[string]func(Config) (Migrator, error)
// Migrator is an interface to migrate docker containers to other containers
type Migrator interface {
// PreMigrate do something before migration
PreMigrate(ctx context.Context, cli *docker.Dockerd, ctrdCli *ctrd.Client) error
// Migrate does migrate action
Migrate(ctx context.Context, cli *docker.Dockerd, ctrdCli *ctrd.Client) error
// PostMigrate do something after migration
PostMigrate(ctx context.Context, cli *docker.Dockerd, ctrdCli *ctrd.Client, dockerRpmName, pouchRpmPath string) error
// RevertMigration reverts migration
RevertMigration(ctx context.Context, cli *docker.Dockerd, ctrdCli *ctrd.Client) error
// Cleanup does some clean works when migrator exited
Cleanup() error
}
// Register registers a migrator to be a d2p-migrator.
func Register(name string, create func(Config) (Migrator, error)) {
if migratorFactory == nil {
migratorFactory = make(map[string]func(Config) (Migrator, error))
}
migratorFactory[name] = create
}