config_unix.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // +build !windows
  2. package runconfig
  3. // ContainerConfigWrapper is a Config wrapper that hold the container Config (portable)
  4. // and the corresponding HostConfig (non-portable).
  5. type ContainerConfigWrapper struct {
  6. *Config
  7. InnerHostConfig *HostConfig `json:"HostConfig,omitempty"`
  8. Cpuset string `json:",omitempty"` // Deprecated. Exported for backwards compatibility.
  9. *HostConfig // Deprecated. Exported to read attributes from json that are not in the inner host config structure.
  10. }
  11. // getHostConfig gets the HostConfig of the Config.
  12. // It's mostly there to handle Deprecated fields of the ContainerConfigWrapper
  13. func (w *ContainerConfigWrapper) getHostConfig() *HostConfig {
  14. hc := w.HostConfig
  15. if hc == nil && w.InnerHostConfig != nil {
  16. hc = w.InnerHostConfig
  17. } else if w.InnerHostConfig != nil {
  18. if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
  19. w.InnerHostConfig.Memory = hc.Memory
  20. }
  21. if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
  22. w.InnerHostConfig.MemorySwap = hc.MemorySwap
  23. }
  24. if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 {
  25. w.InnerHostConfig.CPUShares = hc.CPUShares
  26. }
  27. if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" {
  28. w.InnerHostConfig.CpusetCpus = hc.CpusetCpus
  29. }
  30. if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" {
  31. w.InnerHostConfig.VolumeDriver = hc.VolumeDriver
  32. }
  33. hc = w.InnerHostConfig
  34. }
  35. if hc != nil {
  36. if w.Cpuset != "" && hc.CpusetCpus == "" {
  37. hc.CpusetCpus = w.Cpuset
  38. }
  39. }
  40. // Make sure NetworkMode has an acceptable value. We do this to ensure
  41. // backwards compatible API behaviour.
  42. hc = SetDefaultNetModeIfBlank(hc)
  43. return hc
  44. }