--- /dev/null
+package invoke
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/appc/cni/pkg/types"
+)
+
+func DelegateAdd(delegatePlugin string, netconf []byte) (*types.Result, error) {
+ if os.Getenv("CNI_COMMAND") != "ADD" {
+ return nil, fmt.Errorf("CNI_COMMAND is not ADD")
+ }
+
+ paths := strings.Split(os.Getenv("CNI_PATH"), ":")
+
+ pluginPath, err := FindInPath(delegatePlugin, paths)
+ if err != nil {
+ return nil, err
+ }
+
+ return ExecPluginWithResult(pluginPath, netconf, ArgsFromEnv())
+}
+
+func DelegateDel(delegatePlugin string, netconf []byte) error {
+ if os.Getenv("CNI_COMMAND") != "DEL" {
+ return fmt.Errorf("CNI_COMMAND is not DEL")
+ }
+
+ paths := strings.Split(os.Getenv("CNI_PATH"), ":")
+
+ pluginPath, err := FindInPath(delegatePlugin, paths)
+ if err != nil {
+ return err
+ }
+
+ return ExecPluginWithoutResult(pluginPath, netconf, ArgsFromEnv())
+}
import (
"fmt"
"os"
- "strings"
"github.com/appc/cni/pkg/invoke"
"github.com/appc/cni/pkg/ip"
)
func ExecAdd(plugin string, netconf []byte) (*types.Result, error) {
- if os.Getenv("CNI_COMMAND") != "ADD" {
- return nil, fmt.Errorf("CNI_COMMAND is not ADD")
- }
-
- 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())
+ return invoke.DelegateAdd(plugin, netconf)
}
func ExecDel(plugin string, netconf []byte) error {
- if os.Getenv("CNI_COMMAND") != "DEL" {
- return fmt.Errorf("CNI_COMMAND is not DEL")
- }
-
- 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())
+ return invoke.DelegateDel(plugin, netconf)
}
// ConfigureIface takes the result of IPAM plugin and
"strconv"
"strings"
- "github.com/appc/cni/pkg/ipam"
+ "github.com/appc/cni/pkg/invoke"
"github.com/appc/cni/pkg/skel"
"github.com/appc/cni/pkg/types"
)
return err
}
- result, err := ipam.ExecAdd(netconf["type"].(string), netconfBytes)
+ result, err := invoke.DelegateAdd(netconf["type"].(string), netconfBytes)
if err != nil {
return err
}
return fmt.Errorf("failed to parse netconf: %v", err)
}
- return ipam.ExecDel(n.Type, netconfBytes)
+ return invoke.DelegateDel(n.Type, netconfBytes)
}
func main() {