Browse code

Standardize API keys: CamelCase

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)

Victor Vieux authored on 2014/05/31 10:13:37
Showing 6 changed files
... ...
@@ -848,6 +848,9 @@ func getContainersByName(eng *engine.Engine, version version.Version, w http.Res
848 848
 		return fmt.Errorf("Missing parameter")
849 849
 	}
850 850
 	var job = eng.Job("container_inspect", vars["name"])
851
+	if version.LessThan("1.12") {
852
+		job.SetenvBool("dirty", true)
853
+	}
851 854
 	streamJSON(job, w, false)
852 855
 	return job.Run()
853 856
 }
... ...
@@ -857,6 +860,9 @@ func getImagesByName(eng *engine.Engine, version version.Version, w http.Respons
857 857
 		return fmt.Errorf("Missing parameter")
858 858
 	}
859 859
 	var job = eng.Job("image_inspect", vars["name"])
860
+	if version.LessThan("1.12") {
861
+		job.SetenvBool("dirty", true)
862
+	}
860 863
 	streamJSON(job, w, false)
861 864
 	return job.Run()
862 865
 }
... ...
@@ -13,14 +13,40 @@ func (daemon *Daemon) ContainerInspect(job *engine.Job) engine.Status {
13 13
 	}
14 14
 	name := job.Args[0]
15 15
 	if container := daemon.Get(name); container != nil {
16
-		b, err := json.Marshal(&struct {
17
-			*Container
18
-			HostConfig *runconfig.HostConfig
19
-		}{container, container.HostConfig()})
20
-		if err != nil {
16
+		if job.GetenvBool("dirty") {
17
+			b, err := json.Marshal(&struct {
18
+				*Container
19
+				HostConfig *runconfig.HostConfig
20
+			}{container, container.HostConfig()})
21
+			if err != nil {
22
+				return job.Error(err)
23
+			}
24
+			job.Stdout.Write(b)
25
+			return engine.StatusOK
26
+		}
27
+
28
+		out := &engine.Env{}
29
+		out.Set("Id", container.ID)
30
+		out.SetAuto("Created", container.Created)
31
+		out.Set("Path", container.Path)
32
+		out.SetList("Args", container.Args)
33
+		out.SetJson("Config", container.Config)
34
+		out.SetJson("State", container.State)
35
+		out.Set("Image", container.Image)
36
+		out.SetJson("NetworkSettings", container.NetworkSettings)
37
+		out.Set("ResolvConfPath", container.ResolvConfPath)
38
+		out.Set("HostnamePath", container.HostnamePath)
39
+		out.Set("HostsPath", container.HostsPath)
40
+		out.Set("Name", container.Name)
41
+		out.Set("Driver", container.Driver)
42
+		out.Set("ExecDriver", container.ExecDriver)
43
+		out.Set("MountLabel", container.MountLabel)
44
+		out.Set("ProcessLabel", container.ProcessLabel)
45
+		out.SetJson("VolumesRW", container.VolumesRW)
46
+		out.SetJson("HostConfig", container.hostConfig)
47
+		if _, err := out.WriteTo(job.Stdout); err != nil {
21 48
 			return job.Error(err)
22 49
 		}
23
-		job.Stdout.Write(b)
24 50
 		return engine.StatusOK
25 51
 	}
26 52
 	return job.Errorf("No such container: %s", name)
... ...
@@ -2,7 +2,6 @@ package graph
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"fmt"
6 5
 	"io"
7 6
 
8 7
 	"github.com/dotcloud/docker/engine"
... ...
@@ -117,12 +116,12 @@ func (s *TagStore) CmdGet(job *engine.Job) engine.Status {
117 117
 		//	- Comment: initially created to fulfill the "every image is a git commit"
118 118
 		//		metaphor, in practice people either ignore it or use it as a
119 119
 		//		generic description field which it isn't. On deprecation shortlist.
120
-		res.Set("created", fmt.Sprintf("%v", img.Created))
121
-		res.Set("author", img.Author)
122
-		res.Set("os", img.OS)
123
-		res.Set("architecture", img.Architecture)
124
-		res.Set("docker_version", img.DockerVersion)
125
-		res.Set("ID", img.ID)
120
+		res.SetAuto("Created", img.Created)
121
+		res.Set("Author", img.Author)
122
+		res.Set("Os", img.OS)
123
+		res.Set("Architecture", img.Architecture)
124
+		res.Set("DockerVersion", img.DockerVersion)
125
+		res.Set("Id", img.ID)
126 126
 		res.Set("Parent", img.Parent)
127 127
 	}
128 128
 	res.WriteTo(job.Stdout)
... ...
@@ -136,11 +135,31 @@ func (s *TagStore) CmdLookup(job *engine.Job) engine.Status {
136 136
 	}
137 137
 	name := job.Args[0]
138 138
 	if image, err := s.LookupImage(name); err == nil && image != nil {
139
-		b, err := json.Marshal(image)
140
-		if err != nil {
139
+		if job.GetenvBool("dirty") {
140
+			b, err := json.Marshal(image)
141
+			if err != nil {
142
+				return job.Error(err)
143
+			}
144
+			job.Stdout.Write(b)
145
+			return engine.StatusOK
146
+		}
147
+
148
+		out := &engine.Env{}
149
+		out.Set("Id", image.ID)
150
+		out.Set("Parent", image.Parent)
151
+		out.Set("Comment", image.Comment)
152
+		out.SetAuto("Created", image.Created)
153
+		out.Set("Container", image.Container)
154
+		out.SetJson("ContainerConfig", image.ContainerConfig)
155
+		out.Set("DockerVersion", image.DockerVersion)
156
+		out.Set("Author", image.Author)
157
+		out.SetJson("Config", image.Config)
158
+		out.Set("Architecture", image.Architecture)
159
+		out.Set("Os", image.OS)
160
+		out.SetInt64("Size", image.Size)
161
+		if _, err = out.WriteTo(job.Stdout); err != nil {
141 162
 			return job.Error(err)
142 163
 		}
143
-		job.Stdout.Write(b)
144 164
 		return engine.StatusOK
145 165
 	}
146 166
 	return job.Errorf("No such image: %s", name)
... ...
@@ -439,7 +439,7 @@ func TestBuildWithVolume(t *testing.T) {
439 439
 		VOLUME /test
440 440
 		`,
441 441
 		"testbuildimg",
442
-		"{{json .config.Volumes}}",
442
+		"{{json .Config.Volumes}}",
443 443
 		`{"/test":{}}`)
444 444
 
445 445
 	deleteImages("testbuildimg")
... ...
@@ -453,7 +453,7 @@ func TestBuildMaintainer(t *testing.T) {
453 453
         MAINTAINER dockerio
454 454
 		`,
455 455
 		"testbuildimg",
456
-		"{{json .author}}",
456
+		"{{json .Author}}",
457 457
 		`"dockerio"`)
458 458
 
459 459
 	deleteImages("testbuildimg")
... ...
@@ -469,7 +469,7 @@ func TestBuildUser(t *testing.T) {
469 469
 		RUN [ $(whoami) = 'dockerio' ]
470 470
 		`,
471 471
 		"testbuildimg",
472
-		"{{json .config.User}}",
472
+		"{{json .Config.User}}",
473 473
 		`"dockerio"`)
474 474
 
475 475
 	deleteImages("testbuildimg")
... ...
@@ -489,7 +489,7 @@ func TestBuildRelativeWorkdir(t *testing.T) {
489 489
 		RUN [ "$PWD" = '/test2/test3' ]
490 490
 		`,
491 491
 		"testbuildimg",
492
-		"{{json .config.WorkingDir}}",
492
+		"{{json .Config.WorkingDir}}",
493 493
 		`"/test2/test3"`)
494 494
 
495 495
 	deleteImages("testbuildimg")
... ...
@@ -504,7 +504,7 @@ func TestBuildEnv(t *testing.T) {
504 504
 		RUN [ $(env | grep PORT) = 'PORT=4243' ]
505 505
         `,
506 506
 		"testbuildimg",
507
-		"{{json .config.Env}}",
507
+		"{{json .Config.Env}}",
508 508
 		`["HOME=/","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","PORT=4243"]`)
509 509
 
510 510
 	deleteImages("testbuildimg")
... ...
@@ -518,7 +518,7 @@ func TestBuildCmd(t *testing.T) {
518 518
         CMD ["/bin/echo", "Hello World"]
519 519
         `,
520 520
 		"testbuildimg",
521
-		"{{json .config.Cmd}}",
521
+		"{{json .Config.Cmd}}",
522 522
 		`["/bin/echo","Hello World"]`)
523 523
 
524 524
 	deleteImages("testbuildimg")
... ...
@@ -533,7 +533,7 @@ func TestBuildExpose(t *testing.T) {
533 533
         `,
534 534
 
535 535
 		"testbuildimg",
536
-		"{{json .config.ExposedPorts}}",
536
+		"{{json .Config.ExposedPorts}}",
537 537
 		`{"4243/tcp":{}}`)
538 538
 
539 539
 	deleteImages("testbuildimg")
... ...
@@ -547,7 +547,7 @@ func TestBuildEntrypoint(t *testing.T) {
547 547
         ENTRYPOINT ["/bin/echo"]
548 548
         `,
549 549
 		"testbuildimg",
550
-		"{{json .config.Entrypoint}}",
550
+		"{{json .Config.Entrypoint}}",
551 551
 		`["/bin/echo"]`)
552 552
 
553 553
 	deleteImages("testbuildimg")
... ...
@@ -27,7 +27,7 @@ func TestTagUnprefixedRepoByName(t *testing.T) {
27 27
 
28 28
 // tagging an image by ID in a new unprefixed repo should work
29 29
 func TestTagUnprefixedRepoByID(t *testing.T) {
30
-	getIDCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.id}}", "busybox")
30
+	getIDCmd := exec.Command(dockerBinary, "inspect", "-f", "{{.Id}}", "busybox")
31 31
 	out, _, err := runCommandWithOutput(getIDCmd)
32 32
 	errorOut(err, t, fmt.Sprintf("failed to get the image ID of busybox: %v", err))
33 33
 
... ...
@@ -1057,7 +1057,7 @@ func TestContainerOrphaning(t *testing.T) {
1057 1057
 		if err := job.Run(); err != nil {
1058 1058
 			t.Fatal(err)
1059 1059
 		}
1060
-		return info.Get("ID")
1060
+		return info.Get("Id")
1061 1061
 	}
1062 1062
 
1063 1063
 	// build an image