Implement EndpointOperInfo

pull/3/head
Jack O'Sullivan 3 years ago
parent 13b0de08d9
commit f6e0d0b7b7

@ -122,7 +122,7 @@ func (p *Plugin) apiEndpointOperInfo(w http.ResponseWriter, r *http.Request) {
return
}
res, err := p.EndpointOperInfo(req)
res, err := p.EndpointOperInfo(r.Context(), req)
if err != nil {
util.JSONErrResponse(w, err, 0)
return

@ -6,6 +6,7 @@ import (
"net"
dTypes "github.com/docker/docker/api/types"
"github.com/mitchellh/mapstructure"
log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
@ -250,10 +251,37 @@ func (p *Plugin) CreateEndpoint(ctx context.Context, r CreateEndpointRequest) (C
return res, nil
}
type operInfo struct {
Bridge string `mapstructure:"bridge"`
HostVEth string `mapstructure:"veth_host"`
HostVEthMAC string `mapstructure:"veth_host_mac"`
}
// EndpointOperInfo retrieves some info about an existing endpoint
func (p *Plugin) EndpointOperInfo(r InfoRequest) (InfoResponse, error) {
// TODO: Return some useful information
return InfoResponse{}, nil
func (p *Plugin) EndpointOperInfo(ctx context.Context, r InfoRequest) (InfoResponse, error) {
res := InfoResponse{}
opts, err := p.netOptions(ctx, r.NetworkID)
if err != nil {
return res, fmt.Errorf("failed to get network options: %w", err)
}
hostName, _ := vethPairNames(r.EndpointID)
hostLink, err := netlink.LinkByName(hostName)
if err != nil {
return res, fmt.Errorf("failed to find host side of veth pair: %w", err)
}
info := operInfo{
Bridge: opts.Bridge,
HostVEth: hostName,
HostVEthMAC: hostLink.Attrs().HardwareAddr.String(),
}
if err := mapstructure.Decode(info, &res.Value); err != nil {
return res, fmt.Errorf("failed to encode OperInfo: %w", err)
}
return res, nil
}
// DeleteEndpoint deletes the veth pair

@ -20,6 +20,8 @@ var (
ErrNoLease = errors.New("udhcpc did not output a lease")
// ErrNoHint indicates missing state from the CreateEndpoint stage in Join
ErrNoHint = errors.New("missing CreateEndpoint hints")
// ErrNotVEth indicates a host link was unexpectedly not a veth interface
ErrNotVEth = errors.New("host link is not a veth interface")
)
func ErrToStatus(err error) int {

Loading…
Cancel
Save