github.com/rawahars/moby@v24.0.4+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  	"github.com/docker/docker/pkg/plugingetter"
     9  )
    10  
    11  // IPAM plugin types
    12  const (
    13  	// DefaultIPAM is the name of the built-in default ipam driver
    14  	DefaultIPAM = "default"
    15  	// NullIPAM is the name of the built-in null ipam driver
    16  	NullIPAM = "null"
    17  	// PluginEndpointType represents the Endpoint Type used by Plugin system
    18  	PluginEndpointType = "IpamDriver"
    19  	// RequestAddressType represents the Address Type used when requesting an address
    20  	RequestAddressType = "RequestAddressType"
    21  )
    22  
    23  // Registerer provides a callback interface for registering IPAM instances into libnetwork.
    24  type Registerer interface {
    25  	// RegisterIpamDriver provides a way for drivers to dynamically register with libnetwork
    26  	RegisterIpamDriver(name string, driver Ipam) error
    27  	// RegisterIpamDriverWithCapabilities provides a way for drivers to dynamically register with libnetwork and specify capabilities
    28  	RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
    29  }
    30  
    31  // Callback is a legacy interface for registering an IPAM instance into LibNetwork.
    32  //
    33  // The narrower [Registerer] interface is preferred for new code.
    34  type Callback interface {
    35  	Registerer
    36  	// GetPluginGetter returns the pluginv2 getter.
    37  	GetPluginGetter() plugingetter.PluginGetter
    38  }
    39  
    40  // Well-known errors returned by IPAM
    41  var (
    42  	ErrIpamInternalError   = types.InternalErrorf("IPAM Internal Error")
    43  	ErrInvalidAddressSpace = types.BadRequestErrorf("Invalid Address Space")
    44  	ErrInvalidPool         = types.BadRequestErrorf("Invalid Address Pool")
    45  	ErrInvalidSubPool      = types.BadRequestErrorf("Invalid Address SubPool")
    46  	ErrInvalidRequest      = types.BadRequestErrorf("Invalid Request")
    47  	ErrPoolNotFound        = types.BadRequestErrorf("Address Pool not found")
    48  	ErrOverlapPool         = types.ForbiddenErrorf("Address pool overlaps with existing pool on this address space")
    49  	ErrNoAvailablePool     = types.NoServiceErrorf("No available pool")
    50  	ErrNoAvailableIPs      = types.NoServiceErrorf("No available addresses on this pool")
    51  	ErrNoIPReturned        = types.NoServiceErrorf("No address returned")
    52  	ErrIPAlreadyAllocated  = types.ForbiddenErrorf("Address already in use")
    53  	ErrIPOutOfRange        = types.BadRequestErrorf("Requested address is out of range")
    54  	ErrPoolOverlap         = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
    55  	ErrBadPool             = types.BadRequestErrorf("Address space does not contain specified address pool")
    56  )
    57  
    58  // Ipam represents the interface the IPAM service plugins must implement
    59  // in order to allow injection/modification of IPAM database.
    60  type Ipam interface {
    61  	// GetDefaultAddressSpaces returns the default local and global address spaces for this ipam
    62  	GetDefaultAddressSpaces() (string, string, error)
    63  	// RequestPool returns an address pool along with its unique id. Address space is a mandatory field
    64  	// which denotes a set of non-overlapping pools. pool describes the pool of addresses in CIDR notation.
    65  	// subpool indicates a smaller range of addresses from the pool, for now it is specified in CIDR notation.
    66  	// Both pool and subpool are non mandatory fields. When they are not specified, Ipam driver may choose to
    67  	// return a self chosen pool for this request. In such case the v6 flag needs to be set appropriately so
    68  	// that the driver would return the expected ip version pool.
    69  	RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error)
    70  	// ReleasePool releases the address pool identified by the passed id
    71  	ReleasePool(poolID string) error
    72  	// RequestAddress request an address from the specified pool ID. Input options or required IP can be passed.
    73  	RequestAddress(string, net.IP, map[string]string) (*net.IPNet, map[string]string, error)
    74  	// ReleaseAddress releases the address from the specified pool ID.
    75  	ReleaseAddress(string, net.IP) error
    76  
    77  	// IsBuiltIn returns true if it is a built-in driver.
    78  	IsBuiltIn() bool
    79  }
    80  
    81  // Capability represents the requirements and capabilities of the IPAM driver
    82  type Capability struct {
    83  	// Whether on address request, libnetwork must
    84  	// specify the endpoint MAC address
    85  	RequiresMACAddress bool
    86  	// Whether of daemon start, libnetwork must replay the pool
    87  	// request and the address request for current local networks
    88  	RequiresRequestReplay bool
    89  }