6 "github.com/docker/docker/api/types/container"
7 networktypes "github.com/docker/docker/api/types/network"
10 // ContainerConfigWrapper is a Config wrapper that holds the container Config (portable)
11 // and the corresponding HostConfig (non-portable).
12 type ContainerConfigWrapper struct {
14 InnerHostConfig *container.HostConfig `json:"HostConfig,omitempty"`
15 Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
16 NetworkingConfig *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"`
17 *container.HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure.
20 // getHostConfig gets the HostConfig of the Config.
21 // It's mostly there to handle Deprecated fields of the ContainerConfigWrapper
22 func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig {
25 if hc == nil && w.InnerHostConfig != nil {
26 hc = w.InnerHostConfig
27 } else if w.InnerHostConfig != nil {
28 if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
29 w.InnerHostConfig.Memory = hc.Memory
31 if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
32 w.InnerHostConfig.MemorySwap = hc.MemorySwap
34 if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 {
35 w.InnerHostConfig.CPUShares = hc.CPUShares
37 if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" {
38 w.InnerHostConfig.CpusetCpus = hc.CpusetCpus
41 if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" {
42 w.InnerHostConfig.VolumeDriver = hc.VolumeDriver
45 hc = w.InnerHostConfig
49 if w.Cpuset != "" && hc.CpusetCpus == "" {
50 hc.CpusetCpus = w.Cpuset
54 // Make sure NetworkMode has an acceptable value. We do this to ensure
55 // backwards compatible API behavior.
56 SetDefaultNetModeIfBlank(hc)