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, "Containers: %d\n", remoteInfo.GetInt("Containers"))
fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images")) fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver")) fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver"))
var driverStatus [][2]string
//FIXME:Cleanup this mess if err := remoteInfo.GetJson("DriverStatus", &driverStatus); err != nil {
DriverStatus := remoteInfo.GetJson("DriverStatus") return err
if DriverStatus != nil { }
if tab, ok := DriverStatus.([]interface{}); ok { for _, pair := range driverStatus {
for _, line := range tab { fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
if pair, ok := line.([]interface{}); ok {
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
}
}
}
} }
if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" { if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("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") s := strings.Trim(env.Get(key), " \t")
val, err := strconv.ParseInt(s, 10, 64) val, err := strconv.ParseInt(s, 10, 64)
if err != nil { if err != nil {
@ -60,7 +64,11 @@ func (env *Env) GetInt(key string) int64 {
return val 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)) 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. // encoding/json decodes integers to float64, but cannot encode them back.
// (See http://golang.org/src/pkg/encoding/json/decode.go#L46) // (See http://golang.org/src/pkg/encoding/json/decode.go#L46)
if fval, ok := v.(float64); ok { if fval, ok := v.(float64); ok {
env.SetInt(k, int64(fval)) env.SetInt64(k, int64(fval))
} else if sval, ok := v.(string); ok { } else if sval, ok := v.(string); ok {
env.Set(k, sval) env.Set(k, sval)
} else if val, err := json.Marshal(v); err == nil { } 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) 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) 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) job.env.SetInt(key, value)
} }

View file

@ -81,7 +81,7 @@ func TestGetInfo(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
out.Close() 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) 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 { func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
images, _ := srv.runtime.graph.Map() images, _ := srv.runtime.graph.Map()
var imgcount int64 var imgcount int
if images == nil { if images == nil {
imgcount = 0 imgcount = 0
} else { } else {
imgcount = int64(len(images)) imgcount = len(images)
} }
lxcVersion := "" lxcVersion := ""
if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil { 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 := &engine.Env{}
v.SetInt("Containers", int64(len(srv.runtime.List()))) v.SetInt("Containers", len(srv.runtime.List()))
v.SetInt("Images", imgcount) v.SetInt("Images", imgcount)
v.Set("Driver", srv.runtime.driver.String()) v.Set("Driver", srv.runtime.driver.String())
v.SetJson("DriverStatus", srv.runtime.driver.Status()) 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("SwapLimit", srv.runtime.capabilities.SwapLimit)
v.SetBool("IPv4Forwarding", !srv.runtime.capabilities.IPv4ForwardingDisabled) v.SetBool("IPv4Forwarding", !srv.runtime.capabilities.IPv4ForwardingDisabled)
v.SetBool("Debug", os.Getenv("DEBUG") != "") v.SetBool("Debug", os.Getenv("DEBUG") != "")
v.SetInt("NFd", int64(utils.GetTotalUsedFds())) v.SetInt("NFd", utils.GetTotalUsedFds())
v.SetInt("NGoroutines", int64(runtime.NumGoroutine())) v.SetInt("NGoroutines", runtime.NumGoroutine())
v.Set("LXCVersion", lxcVersion) v.Set("LXCVersion", lxcVersion)
v.SetInt("NEventsListener", int64(len(srv.events))) v.SetInt("NEventsListener", len(srv.events))
v.Set("KernelVersion", kernelVersion) v.Set("KernelVersion", kernelVersion)
v.Set("IndexServerAddress", auth.IndexServerAddress()) v.Set("IndexServerAddress", auth.IndexServerAddress())
if _, err := v.WriteTo(job.Stdout); err != nil { if _, err := v.WriteTo(job.Stdout); err != nil {