mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-09-03 20:31:30 +00:00
In essense, this just involves marshalling structs back and forth to a remote process, via the plugin client. There are a couple of types that don't JSONify well, notably `net.IPNet`, so there is some translation to be done. To conform to the driverapi interface, we must give the list of endpoint interfaces to the remote process, and let it puzzle out what it's supposed to do; including the possibility of returning an error. The constraints on EndpointInfo are enforced by the remote driver implementation; namely: * It can't be nil * If it's got non-empty Interfaces(), the remote process can't put more in In the latter case, or if we fail to add an interface for some (future) reason, we try to roll the endpoint creation back. Likewise for join -- if we fail to set the fields of the JoinInfo, we roll the join back by leaving. Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
144 lines
2.3 KiB
Go
144 lines
2.3 KiB
Go
package remote
|
|
|
|
import "net"
|
|
|
|
type response struct {
|
|
Err string
|
|
}
|
|
|
|
type maybeError interface {
|
|
getError() string
|
|
}
|
|
|
|
func (r *response) getError() string {
|
|
return r.Err
|
|
}
|
|
|
|
type createNetworkRequest struct {
|
|
NetworkID string
|
|
Options map[string]interface{}
|
|
}
|
|
|
|
type createNetworkResponse struct {
|
|
response
|
|
}
|
|
|
|
type deleteNetworkRequest struct {
|
|
NetworkID string
|
|
}
|
|
|
|
type deleteNetworkResponse struct {
|
|
response
|
|
}
|
|
|
|
type createEndpointRequest struct {
|
|
NetworkID string
|
|
EndpointID string
|
|
Interfaces []*endpointInterface
|
|
Options map[string]interface{}
|
|
}
|
|
|
|
type endpointInterface struct {
|
|
ID int
|
|
Address string
|
|
AddressIPv6 string
|
|
MacAddress string
|
|
}
|
|
|
|
type createEndpointResponse struct {
|
|
response
|
|
Interfaces []*endpointInterface
|
|
}
|
|
|
|
func toAddr(ipAddr string) (*net.IPNet, error) {
|
|
ip, ipnet, err := net.ParseCIDR(ipAddr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ipnet.IP = ip
|
|
return ipnet, nil
|
|
}
|
|
|
|
type iface struct {
|
|
ID int
|
|
Address *net.IPNet
|
|
AddressIPv6 *net.IPNet
|
|
MacAddress net.HardwareAddr
|
|
}
|
|
|
|
func (r *createEndpointResponse) parseInterfaces() ([]*iface, error) {
|
|
var (
|
|
ifaces = make([]*iface, len(r.Interfaces))
|
|
)
|
|
for i, inIf := range r.Interfaces {
|
|
var err error
|
|
outIf := &iface{ID: inIf.ID}
|
|
if inIf.Address != "" {
|
|
if outIf.Address, err = toAddr(inIf.Address); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
if inIf.AddressIPv6 != "" {
|
|
if outIf.AddressIPv6, err = toAddr(inIf.AddressIPv6); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
if inIf.MacAddress != "" {
|
|
if outIf.MacAddress, err = net.ParseMAC(inIf.MacAddress); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
ifaces[i] = outIf
|
|
}
|
|
return ifaces, nil
|
|
}
|
|
|
|
type deleteEndpointRequest struct {
|
|
NetworkID string
|
|
EndpointID string
|
|
}
|
|
|
|
type deleteEndpointResponse struct {
|
|
response
|
|
}
|
|
|
|
type endpointInfoRequest struct {
|
|
NetworkID string
|
|
EndpointID string
|
|
}
|
|
|
|
type endpointInfoResponse struct {
|
|
response
|
|
Value map[string]interface{}
|
|
}
|
|
|
|
type joinRequest struct {
|
|
NetworkID string
|
|
EndpointID string
|
|
SandboxKey string
|
|
Options map[string]interface{}
|
|
}
|
|
|
|
type ifaceName struct {
|
|
SrcName string
|
|
DstName string
|
|
}
|
|
|
|
type joinResponse struct {
|
|
response
|
|
InterfaceNames []*ifaceName
|
|
Gateway string
|
|
GatewayIPv6 string
|
|
HostsPath string
|
|
ResolvConfPath string
|
|
}
|
|
|
|
type leaveRequest struct {
|
|
NetworkID string
|
|
EndpointID string
|
|
}
|
|
|
|
type leaveResponse struct {
|
|
response
|
|
}
|