1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add GetenvInt64 ans SetenvInt64

This commit is contained in:
Victor Vieux 2013-12-12 13:35:50 -08:00
parent 51e2c1794b
commit 85b9338205
5 changed files with 34 additions and 23 deletions

View file

@ -448,17 +448,12 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver"))
//FIXME:Cleanup this mess
DriverStatus := remoteInfo.GetJson("DriverStatus")
if DriverStatus != nil {
if tab, ok := DriverStatus.([]interface{}); ok {
for _, line := range tab {
if pair, ok := line.([]interface{}); ok {
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
}
}
}
var driverStatus [][2]string
if err := remoteInfo.GetJson("DriverStatus", &driverStatus); err != nil {
return err
}
for _, pair := range driverStatus {
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
}
if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))

View file

@ -51,7 +51,11 @@ func (env *Env) SetBool(key string, value bool) {
}
}
func (env *Env) GetInt(key string) int64 {
func (env *Env) GetInt(key string) int {
return int(env.GetInt64(key))
}
func (env *Env) GetInt64(key string) int64 {
s := strings.Trim(env.Get(key), " \t")
val, err := strconv.ParseInt(s, 10, 64)
if err != nil {
@ -60,7 +64,11 @@ func (env *Env) GetInt(key string) int64 {
return val
}
func (env *Env) SetInt(key string, value int64) {
func (env *Env) SetInt(key string, value int) {
env.Set(key, fmt.Sprintf("%d", value))
}
func (env *Env) SetInt64(key string, value int64) {
env.Set(key, fmt.Sprintf("%d", value))
}
@ -145,7 +153,7 @@ func (env *Env) SetAuto(k string, v interface{}) {
// encoding/json decodes integers to float64, but cannot encode them back.
// (See http://golang.org/src/pkg/encoding/json/decode.go#L46)
if fval, ok := v.(float64); ok {
env.SetInt(k, int64(fval))
env.SetInt64(k, int64(fval))
} else if sval, ok := v.(string); ok {
env.Set(k, sval)
} else if val, err := json.Marshal(v); err == nil {

View file

@ -113,11 +113,19 @@ func (job *Job) SetenvBool(key string, value bool) {
job.env.SetBool(key, value)
}
func (job *Job) GetenvInt(key string) int64 {
func (job *Job) GetenvInt64(key string) int64 {
return job.env.GetInt64(key)
}
func (job *Job) GetenvInt(key string) int {
return job.env.GetInt(key)
}
func (job *Job) SetenvInt(key string, value int64) {
func (job *Job) SetenvInt64(key string, value int64) {
job.env.SetInt64(key, value)
}
func (job *Job) SetenvInt(key string, value int) {
job.env.SetInt(key, value)
}

View file

@ -81,7 +81,7 @@ func TestGetInfo(t *testing.T) {
t.Fatal(err)
}
out.Close()
if images := i.GetInt("Images"); images != int64(len(initialImages)) {
if images := i.GetInt("Images"); images != len(initialImages) {
t.Errorf("Expected images: %d, %d found", len(initialImages), images)
}
}

View file

@ -616,11 +616,11 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
images, _ := srv.runtime.graph.Map()
var imgcount int64
var imgcount int
if images == nil {
imgcount = 0
} else {
imgcount = int64(len(images))
imgcount = len(images)
}
lxcVersion := ""
if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil {
@ -635,7 +635,7 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
}
v := &engine.Env{}
v.SetInt("Containers", int64(len(srv.runtime.List())))
v.SetInt("Containers", len(srv.runtime.List()))
v.SetInt("Images", imgcount)
v.Set("Driver", srv.runtime.driver.String())
v.SetJson("DriverStatus", srv.runtime.driver.Status())
@ -643,10 +643,10 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
v.SetBool("SwapLimit", srv.runtime.capabilities.SwapLimit)
v.SetBool("IPv4Forwarding", !srv.runtime.capabilities.IPv4ForwardingDisabled)
v.SetBool("Debug", os.Getenv("DEBUG") != "")
v.SetInt("NFd", int64(utils.GetTotalUsedFds()))
v.SetInt("NGoroutines", int64(runtime.NumGoroutine()))
v.SetInt("NFd", utils.GetTotalUsedFds())
v.SetInt("NGoroutines", runtime.NumGoroutine())
v.Set("LXCVersion", lxcVersion)
v.SetInt("NEventsListener", int64(len(srv.events)))
v.SetInt("NEventsListener", len(srv.events))
v.Set("KernelVersion", kernelVersion)
v.Set("IndexServerAddress", auth.IndexServerAddress())
if _, err := v.WriteTo(job.Stdout); err != nil {