Browse code

Expose old config field for api < 1.19

Signed-off-by: Antonio Murdaca <me@runcom.ninja>

Antonio Murdaca authored on 2015/06/03 06:37:59
Showing 3 changed files
... ...
@@ -1141,6 +1141,14 @@ func (s *Server) getContainersByName(version version.Version, w http.ResponseWri
1141 1141
 		return fmt.Errorf("Missing parameter")
1142 1142
 	}
1143 1143
 
1144
+	if version.LessThan("1.19") {
1145
+		containerJSONRaw, err := s.daemon.ContainerInspectRaw(vars["name"])
1146
+		if err != nil {
1147
+			return err
1148
+		}
1149
+		return writeJSON(w, http.StatusOK, containerJSONRaw)
1150
+	}
1151
+
1144 1152
 	containerJSON, err := s.daemon.ContainerInspect(vars["name"])
1145 1153
 	if err != nil {
1146 1154
 		return err
... ...
@@ -195,12 +195,11 @@ type ContainerState struct {
195 195
 }
196 196
 
197 197
 // GET "/containers/{name:.*}/json"
198
-type ContainerJSON struct {
198
+type ContainerJSONBase struct {
199 199
 	Id              string
200 200
 	Created         time.Time
201 201
 	Path            string
202 202
 	Args            []string
203
-	Config          *runconfig.Config
204 203
 	State           *ContainerState
205 204
 	Image           string
206 205
 	NetworkSettings *network.Settings
... ...
@@ -220,3 +219,24 @@ type ContainerJSON struct {
220 220
 	ExecIDs         []string
221 221
 	HostConfig      *runconfig.HostConfig
222 222
 }
223
+
224
+type ContainerJSON struct {
225
+	*ContainerJSONBase
226
+	Config *runconfig.Config
227
+}
228
+
229
+// backcompatibility struct along with ContainerConfig
230
+type ContainerJSONRaw struct {
231
+	*ContainerJSONBase
232
+	Config *ContainerConfig
233
+}
234
+
235
+type ContainerConfig struct {
236
+	*runconfig.Config
237
+
238
+	// backward compatibility, they now live in HostConfig
239
+	Memory     int64
240
+	MemorySwap int64
241
+	CpuShares  int64
242
+	Cpuset     string
243
+}
... ...
@@ -15,6 +15,40 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
15 15
 	container.Lock()
16 16
 	defer container.Unlock()
17 17
 
18
+	base, err := daemon.getInspectData(container)
19
+	if err != nil {
20
+		return nil, err
21
+	}
22
+
23
+	return &types.ContainerJSON{base, container.Config}, nil
24
+}
25
+
26
+func (daemon *Daemon) ContainerInspectRaw(name string) (*types.ContainerJSONRaw, error) {
27
+	container, err := daemon.Get(name)
28
+	if err != nil {
29
+		return nil, err
30
+	}
31
+
32
+	container.Lock()
33
+	defer container.Unlock()
34
+
35
+	base, err := daemon.getInspectData(container)
36
+	if err != nil {
37
+		return nil, err
38
+	}
39
+
40
+	config := &types.ContainerConfig{
41
+		container.Config,
42
+		container.hostConfig.Memory,
43
+		container.hostConfig.MemorySwap,
44
+		container.hostConfig.CpuShares,
45
+		container.hostConfig.CpusetCpus,
46
+	}
47
+
48
+	return &types.ContainerJSONRaw{base, config}, nil
49
+}
50
+
51
+func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSONBase, error) {
18 52
 	// make a copy to play with
19 53
 	hostConfig := *container.hostConfig
20 54
 
... ...
@@ -50,12 +84,11 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
50 50
 		volumesRW[m.Destination] = m.RW
51 51
 	}
52 52
 
53
-	contJSON := &types.ContainerJSON{
53
+	contJSONBase := &types.ContainerJSONBase{
54 54
 		Id:              container.ID,
55 55
 		Created:         container.Created,
56 56
 		Path:            container.Path,
57 57
 		Args:            container.Args,
58
-		Config:          container.Config,
59 58
 		State:           containerState,
60 59
 		Image:           container.ImageID,
61 60
 		NetworkSettings: container.NetworkSettings,
... ...
@@ -76,7 +109,7 @@ func (daemon *Daemon) ContainerInspect(name string) (*types.ContainerJSON, error
76 76
 		HostConfig:      &hostConfig,
77 77
 	}
78 78
 
79
-	return contJSON, nil
79
+	return contJSONBase, nil
80 80
 }
81 81
 
82 82
 func (daemon *Daemon) ContainerExecInspect(id string) (*execConfig, error) {