Skip to content

Commit

Permalink
Merge pull request #1154 from darkowlzz/1082-snapshot-prepare
Browse files Browse the repository at this point in the history
cmd/ctr: add mount subcommand to snapshot
  • Loading branch information
stevvooe committed Jul 19, 2017
2 parents 14e10c8 + 4dc02c0 commit 72c59ae
Showing 1 changed file with 61 additions and 4 deletions.
65 changes: 61 additions & 4 deletions cmd/ctr/snapshot.go
Expand Up @@ -27,6 +27,7 @@ var snapshotCommand = cli.Command{
removeSnapshotCommand,
prepareSnapshotCommand,
treeSnapshotCommand,
mountSnapshotCommand,
},
}

Expand Down Expand Up @@ -196,9 +197,14 @@ var removeSnapshotCommand = cli.Command{

var prepareSnapshotCommand = cli.Command{
Name: "prepare",
Usage: "prepare gets mount commands for digest",
ArgsUsage: "[flags] <digest> <target>",
Flags: []cli.Flag{},
Usage: "prepare a snapshot from a committed snapshot",
ArgsUsage: "[flags] digest target",
Flags: []cli.Flag{
cli.StringFlag{
Name: "snapshot-name",
Usage: "name of the target snapshot",
},
},
Action: func(clicontext *cli.Context) error {
ctx, cancel := appContext(clicontext)
defer cancel()
Expand All @@ -211,16 +217,67 @@ var prepareSnapshotCommand = cli.Command{
if err != nil {
return err
}

target := clicontext.Args().Get(1)

snapshotName := clicontext.String("snapshot-name")
// Use the target as the snapshotName if no snapshot-name is provided
if snapshotName == "" {
snapshotName = target
}

logrus.Infof("preparing mounts %s", dgst.String())

snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}

mounts, err := snapshotter.Prepare(ctx, target, dgst.String())
mounts, err := snapshotter.Prepare(ctx, snapshotName, dgst.String())
if err != nil {
return err
}

for _, m := range mounts {
fmt.Fprintf(os.Stdout, "mount -t %s %s %s -o %s\n", m.Type, m.Source, target, strings.Join(m.Options, ","))
}

return nil
},
}

var mountSnapshotCommand = cli.Command{
Name: "mount",
Usage: "mount gets mount commands for the active snapshots",
ArgsUsage: "[flags] target",
Flags: []cli.Flag{
cli.StringFlag{
Name: "snapshot-name",
Usage: "name of the snapshot",
},
},
Action: func(clicontext *cli.Context) error {
ctx, cancel := appContext(clicontext)
defer cancel()

if clicontext.NArg() != 1 {
return cli.ShowSubcommandHelp(clicontext)
}

target := clicontext.Args().Get(0)

snapshotName := clicontext.String("snapshot-name")
// Use the target as the snapshotName if no snapshot-name is provided
if snapshotName == "" {
snapshotName = target
}

snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}

mounts, err := snapshotter.Mounts(ctx, snapshotName)
if err != nil {
return err
}
Expand Down

0 comments on commit 72c59ae

Please sign in to comment.