2021-06-07 19:03:09 +01:00
|
|
|
package util
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
// ErrIPAM indicates an unsupported IPAM driver was used
|
|
|
|
|
ErrIPAM = errors.New("only the null IPAM driver is supported")
|
|
|
|
|
// ErrBridgeRequired indicates a network bridge was not provided for network creation
|
|
|
|
|
ErrBridgeRequired = errors.New("bridge required")
|
2021-06-29 11:37:58 +01:00
|
|
|
// ErrNotBridge indicates that the provided network interface is not a bridge
|
|
|
|
|
ErrNotBridge = errors.New("network interface is not a bridge")
|
2021-06-07 19:03:09 +01:00
|
|
|
// ErrBridgeUsed indicates that a bridge is already in use
|
|
|
|
|
ErrBridgeUsed = errors.New("bridge already in use by Docker")
|
|
|
|
|
// ErrMACAddress indicates an invalid MAC address
|
|
|
|
|
ErrMACAddress = errors.New("invalid MAC address")
|
2026-02-25 21:50:26 -06:00
|
|
|
// ErrInvalidMode indicates an unrecognised network mode was specified
|
|
|
|
|
ErrInvalidMode = errors.New("invalid mode: must be 'bridge', 'macvlan', or 'ipvlan'")
|
2021-06-07 19:03:09 +01:00
|
|
|
// ErrNoLease indicates a DHCP lease was not obtained from udhcpc
|
|
|
|
|
ErrNoLease = errors.New("udhcpc did not output a lease")
|
2021-06-08 14:17:17 +01:00
|
|
|
// ErrNoHint indicates missing state from the CreateEndpoint stage in Join
|
|
|
|
|
ErrNoHint = errors.New("missing CreateEndpoint hints")
|
2021-06-08 15:00:29 +01:00
|
|
|
// ErrNotVEth indicates a host link was unexpectedly not a veth interface
|
|
|
|
|
ErrNotVEth = errors.New("host link is not a veth interface")
|
2021-06-08 21:38:22 +01:00
|
|
|
// ErrNoContainer indicates a container was unexpectedly not found
|
|
|
|
|
ErrNoContainer = errors.New("couldn't find container by endpoint on the network")
|
|
|
|
|
// ErrNoSandbox indicates missing state from the Join stage
|
|
|
|
|
ErrNoSandbox = errors.New("missing joined endpoint state")
|
2021-06-07 19:03:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ErrToStatus(err error) int {
|
|
|
|
|
switch {
|
2021-06-29 11:37:58 +01:00
|
|
|
case errors.Is(err, ErrIPAM), errors.Is(err, ErrBridgeRequired), errors.Is(err, ErrNotBridge),
|
2026-02-25 21:50:26 -06:00
|
|
|
errors.Is(err, ErrBridgeUsed), errors.Is(err, ErrMACAddress), errors.Is(err, ErrInvalidMode):
|
2021-06-07 19:03:09 +01:00
|
|
|
return http.StatusBadRequest
|
|
|
|
|
default:
|
|
|
|
|
return http.StatusInternalServerError
|
|
|
|
|
}
|
|
|
|
|
}
|