...
1
2
3 package runconfig
4
5 import (
6 "github.com/docker/docker/api/types/container"
7 networktypes "github.com/docker/docker/api/types/network"
8 )
9
10
11
12 type ContainerConfigWrapper struct {
13 *container.Config
14 InnerHostConfig *container.HostConfig `json:"HostConfig,omitempty"`
15 Cpuset string `json:",omitempty"`
16 NetworkingConfig *networktypes.NetworkingConfig `json:"NetworkingConfig,omitempty"`
17 *container.HostConfig
18 }
19
20
21
22 func (w *ContainerConfigWrapper) getHostConfig() *container.HostConfig {
23 hc := w.HostConfig
24
25 if hc == nil && w.InnerHostConfig != nil {
26 hc = w.InnerHostConfig
27 } else if hc != nil && w.InnerHostConfig != nil {
28 if hc.Memory != 0 && w.InnerHostConfig.Memory == 0 {
29 w.InnerHostConfig.Memory = hc.Memory
30 }
31 if hc.MemorySwap != 0 && w.InnerHostConfig.MemorySwap == 0 {
32 w.InnerHostConfig.MemorySwap = hc.MemorySwap
33 }
34 if hc.CPUShares != 0 && w.InnerHostConfig.CPUShares == 0 {
35 w.InnerHostConfig.CPUShares = hc.CPUShares
36 }
37 if hc.CpusetCpus != "" && w.InnerHostConfig.CpusetCpus == "" {
38 w.InnerHostConfig.CpusetCpus = hc.CpusetCpus
39 }
40
41 if hc.VolumeDriver != "" && w.InnerHostConfig.VolumeDriver == "" {
42 w.InnerHostConfig.VolumeDriver = hc.VolumeDriver
43 }
44
45 hc = w.InnerHostConfig
46 }
47
48 if hc != nil {
49 if w.Cpuset != "" && hc.CpusetCpus == "" {
50 hc.CpusetCpus = w.Cpuset
51 }
52 }
53
54
55
56 SetDefaultNetModeIfBlank(hc)
57
58 return hc
59 }
60
View as plain text