Better error message when plugin cannot be found

This commit is contained in:
Zachary Gershman
2016-02-10 13:42:10 -08:00
parent 2d9695e976
commit 290717d6fe
6 changed files with 128 additions and 21 deletions

View File

@ -17,6 +17,7 @@ package ipam
import (
"fmt"
"os"
"strings"
"github.com/appc/cni/pkg/invoke"
"github.com/appc/cni/pkg/ip"
@ -29,14 +30,30 @@ func ExecAdd(plugin string, netconf []byte) (*types.Result, error) {
if os.Getenv("CNI_COMMAND") != "ADD" {
return nil, fmt.Errorf("CNI_COMMAND is not ADD")
}
return invoke.ExecPluginWithResult(invoke.Find(plugin), netconf, invoke.ArgsFromEnv())
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
pluginPath, err := invoke.FindInPath(plugin, paths)
if err != nil {
return nil, err
}
return invoke.ExecPluginWithResult(pluginPath, netconf, invoke.ArgsFromEnv())
}
func ExecDel(plugin string, netconf []byte) error {
if os.Getenv("CNI_COMMAND") != "DEL" {
return fmt.Errorf("CNI_COMMAND is not DEL")
}
return invoke.ExecPluginWithoutResult(invoke.Find(plugin), netconf, invoke.ArgsFromEnv())
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
pluginPath, err := invoke.FindInPath(plugin, paths)
if err != nil {
return err
}
return invoke.ExecPluginWithoutResult(pluginPath, netconf, invoke.ArgsFromEnv())
}
// ConfigureIface takes the result of IPAM plugin and