github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/libnetwork/drivers/remote/api/api.go (about)

     1  /*
     2  Package api represents all requests and responses suitable for conversation
     3  with a remote driver.
     4  */
     5  package api
     6  
     7  import (
     8  	"net"
     9  
    10  	"github.com/docker/libnetwork/discoverapi"
    11  	"github.com/docker/libnetwork/driverapi"
    12  )
    13  
    14  // Response is the basic response structure used in all responses.
    15  type Response struct {
    16  	Err string
    17  }
    18  
    19  // GetError returns the error from the response, if any.
    20  func (r *Response) GetError() string {
    21  	return r.Err
    22  }
    23  
    24  // GetCapabilityResponse is the response of GetCapability request
    25  type GetCapabilityResponse struct {
    26  	Response
    27  	Scope string
    28  }
    29  
    30  // AllocateNetworkRequest requests allocation of new network by manager
    31  type AllocateNetworkRequest struct {
    32  	// A network ID that remote plugins are expected to store for future
    33  	// reference.
    34  	NetworkID string
    35  
    36  	// A free form map->object interface for communication of options.
    37  	Options map[string]string
    38  
    39  	// IPAMData contains the address pool information for this network
    40  	IPv4Data, IPv6Data []driverapi.IPAMData
    41  }
    42  
    43  // AllocateNetworkResponse is the response to the AllocateNetworkRequest.
    44  type AllocateNetworkResponse struct {
    45  	Response
    46  	// A free form plugin specific string->string object to be sent in
    47  	// CreateNetworkRequest call in the libnetwork agents
    48  	Options map[string]string
    49  }
    50  
    51  // FreeNetworkRequest is the request to free allocated network in the manager
    52  type FreeNetworkRequest struct {
    53  	// The ID of the network to be freed.
    54  	NetworkID string
    55  }
    56  
    57  // FreeNetworkResponse is the response to a request for freeing a network.
    58  type FreeNetworkResponse struct {
    59  	Response
    60  }
    61  
    62  // CreateNetworkRequest requests a new network.
    63  type CreateNetworkRequest struct {
    64  	// A network ID that remote plugins are expected to store for future
    65  	// reference.
    66  	NetworkID string
    67  
    68  	// A free form map->object interface for communication of options.
    69  	Options map[string]interface{}
    70  
    71  	// IPAMData contains the address pool information for this network
    72  	IPv4Data, IPv6Data []driverapi.IPAMData
    73  }
    74  
    75  // CreateNetworkResponse is the response to the CreateNetworkRequest.
    76  type CreateNetworkResponse struct {
    77  	Response
    78  }
    79  
    80  // DeleteNetworkRequest is the request to delete an existing network.
    81  type DeleteNetworkRequest struct {
    82  	// The ID of the network to delete.
    83  	NetworkID string
    84  }
    85  
    86  // DeleteNetworkResponse is the response to a request for deleting a network.
    87  type DeleteNetworkResponse struct {
    88  	Response
    89  }
    90  
    91  // CreateEndpointRequest is the request to create an endpoint within a network.
    92  type CreateEndpointRequest struct {
    93  	// Provided at create time, this will be the network id referenced.
    94  	NetworkID string
    95  	// The ID of the endpoint for later reference.
    96  	EndpointID string
    97  	Interface  *EndpointInterface
    98  	Options    map[string]interface{}
    99  }
   100  
   101  // EndpointInterface represents an interface endpoint.
   102  type EndpointInterface struct {
   103  	Address     string
   104  	AddressIPv6 string
   105  	MacAddress  string
   106  }
   107  
   108  // CreateEndpointResponse is the response to the CreateEndpoint action.
   109  type CreateEndpointResponse struct {
   110  	Response
   111  	Interface *EndpointInterface
   112  }
   113  
   114  // Interface is the representation of a linux interface.
   115  type Interface struct {
   116  	Address     *net.IPNet
   117  	AddressIPv6 *net.IPNet
   118  	MacAddress  net.HardwareAddr
   119  }
   120  
   121  // DeleteEndpointRequest describes the API for deleting an endpoint.
   122  type DeleteEndpointRequest struct {
   123  	NetworkID  string
   124  	EndpointID string
   125  }
   126  
   127  // DeleteEndpointResponse is the response to the DeleteEndpoint action.
   128  type DeleteEndpointResponse struct {
   129  	Response
   130  }
   131  
   132  // EndpointInfoRequest retrieves information about the endpoint from the network driver.
   133  type EndpointInfoRequest struct {
   134  	NetworkID  string
   135  	EndpointID string
   136  }
   137  
   138  // EndpointInfoResponse is the response to an EndpointInfoRequest.
   139  type EndpointInfoResponse struct {
   140  	Response
   141  	Value map[string]interface{}
   142  }
   143  
   144  // JoinRequest describes the API for joining an endpoint to a sandbox.
   145  type JoinRequest struct {
   146  	NetworkID  string
   147  	EndpointID string
   148  	SandboxKey string
   149  	Options    map[string]interface{}
   150  }
   151  
   152  // InterfaceName is the struct represetation of a pair of devices with source
   153  // and destination, for the purposes of putting an endpoint into a container.
   154  type InterfaceName struct {
   155  	SrcName   string
   156  	DstName   string
   157  	DstPrefix string
   158  }
   159  
   160  // StaticRoute is the plain JSON representation of a static route.
   161  type StaticRoute struct {
   162  	Destination string
   163  	RouteType   int
   164  	NextHop     string
   165  }
   166  
   167  // JoinResponse is the response to a JoinRequest.
   168  type JoinResponse struct {
   169  	Response
   170  	InterfaceName         *InterfaceName
   171  	Gateway               string
   172  	GatewayIPv6           string
   173  	StaticRoutes          []StaticRoute
   174  	DisableGatewayService bool
   175  }
   176  
   177  // LeaveRequest describes the API for detaching an endpoint from a sandbox.
   178  type LeaveRequest struct {
   179  	NetworkID  string
   180  	EndpointID string
   181  }
   182  
   183  // LeaveResponse is the answer to LeaveRequest.
   184  type LeaveResponse struct {
   185  	Response
   186  }
   187  
   188  // ProgramExternalConnectivityRequest describes the API for programming the external connectivity for the given endpoint.
   189  type ProgramExternalConnectivityRequest struct {
   190  	NetworkID  string
   191  	EndpointID string
   192  	Options    map[string]interface{}
   193  }
   194  
   195  // ProgramExternalConnectivityResponse is the answer to ProgramExternalConnectivityRequest.
   196  type ProgramExternalConnectivityResponse struct {
   197  	Response
   198  }
   199  
   200  // RevokeExternalConnectivityRequest describes the API for revoking the external connectivity for the given endpoint.
   201  type RevokeExternalConnectivityRequest struct {
   202  	NetworkID  string
   203  	EndpointID string
   204  }
   205  
   206  // RevokeExternalConnectivityResponse is the answer to RevokeExternalConnectivityRequest.
   207  type RevokeExternalConnectivityResponse struct {
   208  	Response
   209  }
   210  
   211  // DiscoveryNotification represents a discovery notification
   212  type DiscoveryNotification struct {
   213  	DiscoveryType discoverapi.DiscoveryType
   214  	DiscoveryData interface{}
   215  }
   216  
   217  // DiscoveryResponse is used by libnetwork to log any plugin error processing the discovery notifications
   218  type DiscoveryResponse struct {
   219  	Response
   220  }