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
Vincent Demeester 5170a2c096 Lint fixes on runconfig
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2015-07-27 21:23:15 +02:00

58 lines
1.5 KiB
Go

// +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
}