Merge pull request #55 from crosbymichael/nsinit-config

Rename nsinit spec to config and only display raw json
This commit is contained in:
Victor Marmol 2014-06-26 16:37:36 -07:00
commit 14567adea1
4 changed files with 35 additions and 57 deletions

29
nsinit/config.go Normal file
View File

@ -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)
}

View File

@ -30,7 +30,7 @@ func main() {
execCommand,
initCommand,
statsCommand,
specCommand,
configCommand,
nsenterCommand,
}

View File

@ -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
}

View File

@ -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)
}