From 21b71ef33dfe7896c2158af0594c5fc738e9c138 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 26 Jun 2014 16:24:16 -0700 Subject: [PATCH 1/2] Rename spec to config Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- nsinit/config.go | 29 +++++++++++++++++++++++++++++ nsinit/main.go | 2 +- nsinit/spec.go | 40 ---------------------------------------- 3 files changed, 30 insertions(+), 41 deletions(-) create mode 100644 nsinit/config.go delete mode 100644 nsinit/spec.go diff --git a/nsinit/config.go b/nsinit/config.go new file mode 100644 index 00000000..e1f28fcc --- /dev/null +++ b/nsinit/config.go @@ -0,0 +1,29 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + + "github.com/codegangsta/cli" +) + +var configCommand = cli.Command{ + Name: "config", + Usage: "display the container configuration", + Action: configAction, +} + +func configAction(context *cli.Context) { + container, err := loadContainer() + if err != nil { + log.Fatal(err) + } + + data, err := json.MarshalIndent(container, "", "\t") + if err != nil { + log.Fatal(err) + } + + fmt.Printf("%s", data) +} diff --git a/nsinit/main.go b/nsinit/main.go index 20132de0..a3d7bd10 100644 --- a/nsinit/main.go +++ b/nsinit/main.go @@ -30,7 +30,7 @@ func main() { execCommand, initCommand, statsCommand, - specCommand, + configCommand, nsenterCommand, } diff --git a/nsinit/spec.go b/nsinit/spec.go deleted file mode 100644 index beadc9d8..00000000 --- a/nsinit/spec.go +++ /dev/null @@ -1,40 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "log" - - "github.com/codegangsta/cli" - "github.com/docker/libcontainer" -) - -var specCommand = cli.Command{ - Name: "spec", - Usage: "display the container specification", - Action: specAction, -} - -func specAction(context *cli.Context) { - container, err := loadContainer() - if err != nil { - log.Fatal(err) - } - - spec, err := getContainerSpec(container) - if err != nil { - log.Fatalf("Failed to get spec - %v\n", err) - } - - fmt.Printf("Spec:\n%v\n", spec) -} - -// returns the container spec in json format. -func getContainerSpec(container *libcontainer.Config) (string, error) { - spec, err := json.MarshalIndent(container, "", "\t") - if err != nil { - return "", err - } - - return string(spec), nil -} From 361ac10612c3240c7dc6a107f3218a293fceddfd Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 26 Jun 2014 16:25:55 -0700 Subject: [PATCH 2/2] Just output raw stats json Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- nsinit/stats.go | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/nsinit/stats.go b/nsinit/stats.go index eae98338..331d27f2 100644 --- a/nsinit/stats.go +++ b/nsinit/stats.go @@ -21,30 +21,19 @@ func statsAction(context *cli.Context) { log.Fatal(err) } - runtimeCkpt, err := libcontainer.GetState(dataPath) + state, err := libcontainer.GetState(dataPath) if err != nil { log.Fatal(err) } - stats, err := getStats(container, runtimeCkpt) - if err != nil { - log.Fatalf("Failed to get stats - %v\n", err) - } - - fmt.Printf("Stats:\n%v\n", stats) -} - -// returns the container stats in json format. -func getStats(container *libcontainer.Config, state *libcontainer.State) (string, error) { stats, err := libcontainer.GetStats(container, state) if err != nil { - return "", err + log.Fatal(err) } - - out, err := json.MarshalIndent(stats, "", "\t") + data, err := json.MarshalIndent(stats, "", "\t") if err != nil { - return "", err + log.Fatal(err) } - return string(out), nil + fmt.Printf("%s", data) }