2015-07-09 22:12:36 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package runconfig
|
|
|
|
|
2016-01-08 00:18:34 +00:00
|
|
|
import (
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
|
|
|
networktypes "github.com/docker/docker/api/types/network"
|
2016-01-08 00:18:34 +00:00
|
|
|
)
|
2015-12-18 18:36:17 +00:00
|
|
|
|
2016-03-09 16:17:57 +00:00
|
|
|
// ContainerConfigWrapper is a Config wrapper that holds the container Config (portable)
|
2015-07-09 22:12:36 +00:00
|
|
|
// and the corresponding HostConfig (non-portable).
|
|
|
|
type ContainerConfigWrapper struct {
|
2015-12-18 18:36:17 +00:00
|
|
|
*container.Config
|
2016-01-08 00:18:34 +00:00
|
|
|
InnerHostConfig *container.HostConfig `json:"HostConfig,omitempty"`
|
|
|
|
Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
|
|
|
|
NetworkingConfig *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"`
|
|
|
|
*container.HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure.
|
2015-07-09 22:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getHostConfig gets the HostConfig of the Config.
|
|
|
|
// It's mostly there to handle Deprecated fields of the ContainerConfigWrapper
|
2015-12-18 18:36:17 +00:00
|
|
|
func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig {
|
2015-07-09 22:12:36 +00:00
|
|
|
hc := w.HostConfig
|
|
|
|
|
|
|
|
if hc == nil && w.InnerHostConfig != nil {
|
|
|
|
hc = w.InnerHostConfig
|
|
|
|
} else if w.InnerHostConfig != nil {
|
|
|
|
if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
|
|
|
|
w.InnerHostConfig.Memory = hc.Memory
|
|
|
|
}
|
|
|
|
if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
|
|
|
|
w.InnerHostConfig.MemorySwap = hc.MemorySwap
|
|
|
|
}
|
|
|
|
if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 {
|
|
|
|
w.InnerHostConfig.CPUShares = hc.CPUShares
|
|
|
|
}
|
|
|
|
if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" {
|
|
|
|
w.InnerHostConfig.CpusetCpus = hc.CpusetCpus
|
|
|
|
}
|
|
|
|
|
2015-08-24 17:57:39 +00:00
|
|
|
if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" {
|
|
|
|
w.InnerHostConfig.VolumeDriver = hc.VolumeDriver
|
|
|
|
}
|
|
|
|
|
2015-07-09 22:12:36 +00:00
|
|
|
hc = w.InnerHostConfig
|
|
|
|
}
|
|
|
|
|
2015-08-24 17:57:39 +00:00
|
|
|
if hc != nil {
|
|
|
|
if w.Cpuset != "" && hc.CpusetCpus == "" {
|
|
|
|
hc.CpusetCpus = w.Cpuset
|
|
|
|
}
|
2015-07-09 22:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure NetworkMode has an acceptable value. We do this to ensure
|
2015-12-13 16:00:39 +00:00
|
|
|
// backwards compatible API behavior.
|
2015-07-09 22:12:36 +00:00
|
|
|
hc = SetDefaultNetModeIfBlank(hc)
|
|
|
|
|
|
|
|
return hc
|
|
|
|
}
|