1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/runconfig/parse_unix.go

59 lines
1.5 KiB
Go
Raw Normal View History

// +build !windows
package runconfig
import (
"fmt"
"strings"
)
func parseNetMode(netMode string) (NetworkMode, error) {
parts := strings.Split(netMode, ":")
switch mode := parts[0]; mode {
case "default", "bridge", "none", "host":
case "container":
if len(parts) < 2 || parts[1] == "" {
return "", fmt.Errorf("invalid container format container:<name|id>")
}
default:
return "", fmt.Errorf("invalid --net: %s", netMode)
}
return NetworkMode(netMode), nil
}
func validateNetMode(vals *validateNM) error {
if (vals.netMode.IsHost() || vals.netMode.IsContainer()) && *vals.flHostname != "" {
return ErrConflictNetworkHostname
}
if vals.netMode.IsHost() && vals.flLinks.Len() > 0 {
return ErrConflictHostNetworkAndLinks
}
if vals.netMode.IsContainer() && vals.flLinks.Len() > 0 {
return ErrConflictContainerNetworkAndLinks
}
if (vals.netMode.IsHost() || vals.netMode.IsContainer()) && vals.flDNS.Len() > 0 {
return ErrConflictNetworkAndDNS
}
if (vals.netMode.IsContainer() || vals.netMode.IsHost()) && vals.flExtraHosts.Len() > 0 {
return ErrConflictNetworkHosts
}
if (vals.netMode.IsContainer() || vals.netMode.IsHost()) && *vals.flMacAddress != "" {
return ErrConflictContainerNetworkAndMac
}
if vals.netMode.IsContainer() && (vals.flPublish.Len() > 0 || *vals.flPublishAll == true) {
return ErrConflictNetworkPublishPorts
}
if vals.netMode.IsContainer() && vals.flExpose.Len() > 0 {
return ErrConflictNetworkExposePorts
}
return nil
}