github.com/moby/docker@v26.1.3+incompatible/libnetwork/ipamapi/contract.go (about)

     1  // Package ipamapi specifies the contract the IPAM service (built-in or remote) needs to satisfy.
     2  package ipamapi
     3  
     4  import (
     5  	"net"
     6  
     7  	"github.com/docker/docker/libnetwork/types"
     8  )
     9  
    10  // IPAM plugin types
    11  const (
    12  	// DefaultIPAM is the name of the built-in default ipam driver
    13  	DefaultIPAM = "default"
    14  	// NullIPAM is the name of the built-in null ipam driver
    15  	NullIPAM = "null"
    16  	// PluginEndpointType represents the Endpoint Type used by Plugin system
    17  	PluginEndpointType = "IpamDriver"
    18  	// RequestAddressType represents the Address Type used when requesting an address
    19  	RequestAddressType = "RequestAddressType"
    20  )
    21  
    22  // Registerer provides a callback interface for registering IPAM instances into libnetwork.
    23  type Registerer interface {
    24  	// RegisterIpamDriver provides a way for drivers to dynamically register with libnetwork
    25  	RegisterIpamDriver(name string, driver Ipam) error
    26  	// RegisterIpamDriverWithCapabilities provides a way for drivers to dynamically register with libnetwork and specify capabilities
    27  	RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
    28  }
    29  
    30  // Well-known errors returned by IPAM
    31  var (
    32  	ErrInvalidAddressSpace = types.InvalidParameterErrorf("invalid address space")
    33  	ErrInvalidPool         = types.InvalidParameterErrorf("invalid address pool")
    34  	ErrInvalidSubPool      = types.InvalidParameterErrorf("invalid address subpool")
    35  	ErrNoAvailableIPs      = types.UnavailableErrorf("no available addresses on this pool")
    36  	ErrNoIPReturned        = types.UnavailableErrorf("no address returned")
    37  	ErrIPAlreadyAllocated  = types.ForbiddenErrorf("Address already in use")
    38  	ErrIPOutOfRange        = types.InvalidParameterErrorf("requested address is out of range")
    39  	ErrPoolOverlap         = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
    40  	ErrBadPool             = types.InvalidParameterErrorf("address space does not contain specified address pool")
    41  )
    42  
    43  // Ipam represents the interface the IPAM service plugins must implement
    44  // in order to allow injection/modification of IPAM database.
    45  type Ipam interface {
    46  	// GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
    47  	GetDefaultAddressSpaces() (string, string, error)
    48  	// RequestPool returns an address pool along with its unique id. Address space is a mandatory field
    49  	// which denotes a set of non-overlapping pools. requestedPool describes the pool of addresses in CIDR notation.
    50  	// requestedSubPool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
    51  	// Both requestedPool and requestedSubPool are non-mandatory fields. When they are not specified, Ipam driver may choose to
    52  	// return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
    53  	// that the driver would return the expected ip version pool.
    54  	RequestPool(addressSpace, requestedPool, requestedSubPool string, options map[string]string, v6 bool) (poolID string, pool *net.IPNet, meta map[string]string, err error)
    55  	// ReleasePool releases the address pool identified by the passed id
    56  	ReleasePool(poolID string) error
    57  	// RequestAddress request an address from the specified pool ID. Input options or required IP can be passed.
    58  	RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
    59  	// ReleaseAddress releases the address from the specified pool ID.
    60  	ReleaseAddress(string, net.IP) error
    61  
    62  	// IsBuiltIn returns true if it is a built-in driver.
    63  	IsBuiltIn() bool
    64  }
    65  
    66  // Capability represents the requirements and capabilities of the IPAM driver
    67  type Capability struct {
    68  	// Whether on address request, libnetwork must
    69  	// specify the endpoint MAC address
    70  	RequiresMACAddress bool
    71  	// Whether of daemon start, libnetwork must replay the pool
    72  	// request and the address request for current local networks
    73  	RequiresRequestReplay bool
    74  }