mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Invert network disable flag and logic (unbreaks TestAllocate*PortLocalhost)
This commit is contained in:
parent
964e826a9b
commit
bc172e5e5f
2 changed files with 46 additions and 46 deletions
84
container.go
84
container.go
|
@ -58,26 +58,26 @@ type Container struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Hostname string
|
Hostname string
|
||||||
User string
|
User string
|
||||||
Memory int64 // Memory limit (in bytes)
|
Memory int64 // Memory limit (in bytes)
|
||||||
MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
|
MemorySwap int64 // Total memory usage (memory + swap); set `-1' to disable swap
|
||||||
CpuShares int64 // CPU shares (relative weight vs. other containers)
|
CpuShares int64 // CPU shares (relative weight vs. other containers)
|
||||||
AttachStdin bool
|
AttachStdin bool
|
||||||
AttachStdout bool
|
AttachStdout bool
|
||||||
AttachStderr bool
|
AttachStderr bool
|
||||||
PortSpecs []string
|
PortSpecs []string
|
||||||
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
Tty bool // Attach standard streams to a tty, including stdin if it is not closed.
|
||||||
OpenStdin bool // Open stdin
|
OpenStdin bool // Open stdin
|
||||||
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
StdinOnce bool // If true, close stdin after the 1 attached client disconnects.
|
||||||
Env []string
|
Env []string
|
||||||
Cmd []string
|
Cmd []string
|
||||||
Dns []string
|
Dns []string
|
||||||
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
||||||
Volumes map[string]struct{}
|
Volumes map[string]struct{}
|
||||||
VolumesFrom string
|
VolumesFrom string
|
||||||
Entrypoint []string
|
Entrypoint []string
|
||||||
NetworkEnabled bool
|
NetworkDisabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type HostConfig struct {
|
type HostConfig struct {
|
||||||
|
@ -176,24 +176,24 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Hostname: *flHostname,
|
Hostname: *flHostname,
|
||||||
PortSpecs: flPorts,
|
PortSpecs: flPorts,
|
||||||
User: *flUser,
|
User: *flUser,
|
||||||
Tty: *flTty,
|
Tty: *flTty,
|
||||||
NetworkEnabled: *flNetwork,
|
NetworkDisabled: !*flNetwork,
|
||||||
OpenStdin: *flStdin,
|
OpenStdin: *flStdin,
|
||||||
Memory: *flMemory,
|
Memory: *flMemory,
|
||||||
CpuShares: *flCpuShares,
|
CpuShares: *flCpuShares,
|
||||||
AttachStdin: flAttach.Get("stdin"),
|
AttachStdin: flAttach.Get("stdin"),
|
||||||
AttachStdout: flAttach.Get("stdout"),
|
AttachStdout: flAttach.Get("stdout"),
|
||||||
AttachStderr: flAttach.Get("stderr"),
|
AttachStderr: flAttach.Get("stderr"),
|
||||||
Env: flEnv,
|
Env: flEnv,
|
||||||
Cmd: runCmd,
|
Cmd: runCmd,
|
||||||
Dns: flDns,
|
Dns: flDns,
|
||||||
Image: image,
|
Image: image,
|
||||||
Volumes: flVolumes,
|
Volumes: flVolumes,
|
||||||
VolumesFrom: *flVolumesFrom,
|
VolumesFrom: *flVolumesFrom,
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
}
|
}
|
||||||
hostConfig := &HostConfig{
|
hostConfig := &HostConfig{
|
||||||
Binds: binds,
|
Binds: binds,
|
||||||
|
@ -515,7 +515,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if container.runtime.networkManager.disabled {
|
if container.runtime.networkManager.disabled {
|
||||||
container.Config.NetworkEnabled = false
|
container.Config.NetworkDisabled = true
|
||||||
} else {
|
} else {
|
||||||
if err := container.allocateNetwork(); err != nil {
|
if err := container.allocateNetwork(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -633,7 +633,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
if container.Config.NetworkEnabled {
|
if !container.Config.NetworkDisabled {
|
||||||
params = append(params, "-g", container.network.Gateway.String())
|
params = append(params, "-g", container.network.Gateway.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ func (container *Container) StderrPipe() (io.ReadCloser, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) allocateNetwork() error {
|
func (container *Container) allocateNetwork() error {
|
||||||
if !container.Config.NetworkEnabled {
|
if container.Config.NetworkDisabled {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,7 +766,7 @@ func (container *Container) allocateNetwork() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) releaseNetwork() {
|
func (container *Container) releaseNetwork() {
|
||||||
if !container.Config.NetworkEnabled {
|
if container.Config.NetworkDisabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
container.network.Release()
|
container.network.Release()
|
||||||
|
|
|
@ -13,7 +13,10 @@ lxc.utsname = {{.Id}}
|
||||||
{{end}}
|
{{end}}
|
||||||
#lxc.aa_profile = unconfined
|
#lxc.aa_profile = unconfined
|
||||||
|
|
||||||
{{if .Config.NetworkEnabled}}
|
{{if .Config.NetworkDisabled}}
|
||||||
|
# network is disabled (-n=false)
|
||||||
|
lxc.network.type = empty
|
||||||
|
{{else}}
|
||||||
# network configuration
|
# network configuration
|
||||||
lxc.network.type = veth
|
lxc.network.type = veth
|
||||||
lxc.network.flags = up
|
lxc.network.flags = up
|
||||||
|
@ -21,9 +24,6 @@ lxc.network.link = {{.NetworkSettings.Bridge}}
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
lxc.network.mtu = 1500
|
lxc.network.mtu = 1500
|
||||||
lxc.network.ipv4 = {{.NetworkSettings.IPAddress}}/{{.NetworkSettings.IPPrefixLen}}
|
lxc.network.ipv4 = {{.NetworkSettings.IPAddress}}/{{.NetworkSettings.IPPrefixLen}}
|
||||||
{{else}}
|
|
||||||
# Network configuration disabled
|
|
||||||
lxc.network.type = empty
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
# root filesystem
|
# root filesystem
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue