-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathplugin.go
55 lines (44 loc) · 1.27 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Microsoft Corp.
// All rights reserved.
package cni
import (
"github.com/Microsoft/windows-container-networking/common"
cniSkel "github.com/containernetworking/cni/pkg/skel"
cniVers "github.com/containernetworking/cni/pkg/version"
)
// Plugin is the parent class for CNI plugins.
type Plugin struct {
*common.Plugin
}
// NewPlugin creates a new CNI plugin.
func NewPlugin(name, version string) (*Plugin, error) {
// Setup base plugin.
plugin, err := common.NewPlugin(name, version)
if err != nil {
return nil, err
}
return &Plugin{
Plugin: plugin,
}, nil
}
// Initialize initializes the plugin.
func (plugin *Plugin) Initialize(config *common.PluginConfig) error {
// Initialize the base plugin.
return plugin.Plugin.Initialize(config)
}
// Uninitialize uninitializes the plugin.
func (plugin *Plugin) Uninitialize() {
plugin.Plugin.Uninitialize()
}
// Execute executes the CNI command.
func (plugin *Plugin) Execute(api PluginApi) error {
// Set supported CNI versions.
pluginInfo := cniVers.PluginSupports(VersionsSupported...)
// Parse args and call the appropriate cmd handler.
cniErr := cniSkel.PluginMainWithError(api.Add, api.Check, api.Delete, pluginInfo, "CNI plugin WinCni")
if cniErr != nil {
cniErr.Print()
return cniErr
}
return nil
}