ctr: add ctr snapshot info <key>
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
parent
22df20b35f
commit
fef7f3addc
@ -1,10 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -31,11 +27,9 @@ var containerInfoCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cjson, err := json.MarshalIndent(container.Info(), "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(cjson))
|
||||
|
||||
printAsJSON(container.Info())
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -3,12 +3,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
gocontext "context"
|
||||
@ -185,15 +182,7 @@ var shimStateCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if err := json.Indent(buf, data, " ", " "); err != nil {
|
||||
return err
|
||||
}
|
||||
buf.WriteTo(os.Stdout)
|
||||
printAsJSON(r)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ var snapshotCommand = cli.Command{
|
||||
treeSnapshotCommand,
|
||||
mountSnapshotCommand,
|
||||
commitSnapshotCommand,
|
||||
infoSnapshotCommand,
|
||||
},
|
||||
}
|
||||
|
||||
@ -312,6 +313,36 @@ var treeSnapshotCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var infoSnapshotCommand = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get info about a snapshot",
|
||||
ArgsUsage: "<key>",
|
||||
Action: func(clicontext *cli.Context) error {
|
||||
ctx, cancel := appContext(clicontext)
|
||||
defer cancel()
|
||||
|
||||
if clicontext.NArg() != 1 {
|
||||
return cli.ShowSubcommandHelp(clicontext)
|
||||
}
|
||||
|
||||
key := clicontext.Args().Get(0)
|
||||
|
||||
snapshotter, err := getSnapshotter(clicontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := snapshotter.Stat(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printAsJSON(info)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
type snapshotTreeNode struct {
|
||||
Name string
|
||||
Parent string
|
||||
|
@ -417,3 +417,11 @@ func labelArgs(labelStrings []string) map[string]string {
|
||||
|
||||
return labels
|
||||
}
|
||||
|
||||
func printAsJSON(x interface{}) {
|
||||
b, err := json.MarshalIndent(x, "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "can't marshal %+v as a JSON string: %v\n", x, err)
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user