Browse code

add GetenvInt64 ans SetenvInt64

Victor Vieux authored on 2013/12/13 06:35:50
Showing 5 changed files
... ...
@@ -448,17 +448,12 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
448 448
 	fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
449 449
 	fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
450 450
 	fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver"))
451
-
452
-	//FIXME:Cleanup this mess
453
-	DriverStatus := remoteInfo.GetJson("DriverStatus")
454
-	if DriverStatus != nil {
455
-		if tab, ok := DriverStatus.([]interface{}); ok {
456
-			for _, line := range tab {
457
-				if pair, ok := line.([]interface{}); ok {
458
-					fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
459
-				}
460
-			}
461
-		}
451
+	var driverStatus [][2]string
452
+	if err := remoteInfo.GetJson("DriverStatus", &driverStatus); err != nil {
453
+		return err
454
+	}
455
+	for _, pair := range driverStatus {
456
+		fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
462 457
 	}
463 458
 	if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
464 459
 		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))
... ...
@@ -51,7 +51,11 @@ func (env *Env) SetBool(key string, value bool) {
51 51
 	}
52 52
 }
53 53
 
54
-func (env *Env) GetInt(key string) int64 {
54
+func (env *Env) GetInt(key string) int {
55
+	return int(env.GetInt64(key))
56
+}
57
+
58
+func (env *Env) GetInt64(key string) int64 {
55 59
 	s := strings.Trim(env.Get(key), " \t")
56 60
 	val, err := strconv.ParseInt(s, 10, 64)
57 61
 	if err != nil {
... ...
@@ -60,7 +64,11 @@ func (env *Env) GetInt(key string) int64 {
60 60
 	return val
61 61
 }
62 62
 
63
-func (env *Env) SetInt(key string, value int64) {
63
+func (env *Env) SetInt(key string, value int) {
64
+	env.Set(key, fmt.Sprintf("%d", value))
65
+}
66
+
67
+func (env *Env) SetInt64(key string, value int64) {
64 68
 	env.Set(key, fmt.Sprintf("%d", value))
65 69
 }
66 70
 
... ...
@@ -145,7 +153,7 @@ func (env *Env) SetAuto(k string, v interface{}) {
145 145
 	// encoding/json decodes integers to float64, but cannot encode them back.
146 146
 	// (See http://golang.org/src/pkg/encoding/json/decode.go#L46)
147 147
 	if fval, ok := v.(float64); ok {
148
-		env.SetInt(k, int64(fval))
148
+		env.SetInt64(k, int64(fval))
149 149
 	} else if sval, ok := v.(string); ok {
150 150
 		env.Set(k, sval)
151 151
 	} else if val, err := json.Marshal(v); err == nil {
... ...
@@ -113,11 +113,19 @@ func (job *Job) SetenvBool(key string, value bool) {
113 113
 	job.env.SetBool(key, value)
114 114
 }
115 115
 
116
-func (job *Job) GetenvInt(key string) int64 {
116
+func (job *Job) GetenvInt64(key string) int64 {
117
+	return job.env.GetInt64(key)
118
+}
119
+
120
+func (job *Job) GetenvInt(key string) int {
117 121
 	return job.env.GetInt(key)
118 122
 }
119 123
 
120
-func (job *Job) SetenvInt(key string, value int64) {
124
+func (job *Job) SetenvInt64(key string, value int64) {
125
+	job.env.SetInt64(key, value)
126
+}
127
+
128
+func (job *Job) SetenvInt(key string, value int) {
121 129
 	job.env.SetInt(key, value)
122 130
 }
123 131
 
... ...
@@ -81,7 +81,7 @@ func TestGetInfo(t *testing.T) {
81 81
 		t.Fatal(err)
82 82
 	}
83 83
 	out.Close()
84
-	if images := i.GetInt("Images"); images != int64(len(initialImages)) {
84
+	if images := i.GetInt("Images"); images != len(initialImages) {
85 85
 		t.Errorf("Expected images: %d, %d found", len(initialImages), images)
86 86
 	}
87 87
 }
... ...
@@ -616,11 +616,11 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
616 616
 
617 617
 func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
618 618
 	images, _ := srv.runtime.graph.Map()
619
-	var imgcount int64
619
+	var imgcount int
620 620
 	if images == nil {
621 621
 		imgcount = 0
622 622
 	} else {
623
-		imgcount = int64(len(images))
623
+		imgcount = len(images)
624 624
 	}
625 625
 	lxcVersion := ""
626 626
 	if output, err := exec.Command("lxc-version").CombinedOutput(); err == nil {
... ...
@@ -635,7 +635,7 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
635 635
 	}
636 636
 
637 637
 	v := &engine.Env{}
638
-	v.SetInt("Containers", int64(len(srv.runtime.List())))
638
+	v.SetInt("Containers", len(srv.runtime.List()))
639 639
 	v.SetInt("Images", imgcount)
640 640
 	v.Set("Driver", srv.runtime.driver.String())
641 641
 	v.SetJson("DriverStatus", srv.runtime.driver.Status())
... ...
@@ -643,10 +643,10 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
643 643
 	v.SetBool("SwapLimit", srv.runtime.capabilities.SwapLimit)
644 644
 	v.SetBool("IPv4Forwarding", !srv.runtime.capabilities.IPv4ForwardingDisabled)
645 645
 	v.SetBool("Debug", os.Getenv("DEBUG") != "")
646
-	v.SetInt("NFd", int64(utils.GetTotalUsedFds()))
647
-	v.SetInt("NGoroutines", int64(runtime.NumGoroutine()))
646
+	v.SetInt("NFd", utils.GetTotalUsedFds())
647
+	v.SetInt("NGoroutines", runtime.NumGoroutine())
648 648
 	v.Set("LXCVersion", lxcVersion)
649
-	v.SetInt("NEventsListener", int64(len(srv.events)))
649
+	v.SetInt("NEventsListener", len(srv.events))
650 650
 	v.Set("KernelVersion", kernelVersion)
651 651
 	v.Set("IndexServerAddress", auth.IndexServerAddress())
652 652
 	if _, err := v.WriteTo(job.Stdout); err != nil {