-
Notifications
You must be signed in to change notification settings - Fork 241
/
plugin.go
74 lines (61 loc) · 1.59 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2017 Microsoft. All rights reserved.
// MIT License
package common
import (
"github.com/Azure/azure-container-networking/store"
)
// Plugin is the parent class that implements behavior common to all plugins.
type Plugin struct {
Name string
Version string
Options map[string]interface{}
ErrChan chan error
Store store.KeyValueStore
}
// Plugin base interface.
type PluginApi interface {
Start(*PluginConfig) error
Stop()
GetOption(string) interface{}
SetOption(string, interface{})
}
// Network internal interface.
type NetApi interface {
AddExternalInterface(ifName string, subnet string) error
}
// IPAM internal interface.
type IpamApi interface{}
// Plugin common configuration.
type PluginConfig struct {
Version string
NetApi NetApi
IpamApi IpamApi
Listener *Listener
ErrChan chan error
Store store.KeyValueStore
}
// NewPlugin creates a new Plugin object.
func NewPlugin(name, version string) (*Plugin, error) {
return &Plugin{
Name: name,
Version: version,
Options: make(map[string]interface{}),
}, nil
}
// Initialize initializes the plugin.
func (plugin *Plugin) Initialize(config *PluginConfig) error {
plugin.ErrChan = config.ErrChan
plugin.Store = config.Store
return nil
}
// Uninitialize cleans up the plugin.
func (plugin *Plugin) Uninitialize() {
}
// GetOption gets the option value for the given key.
func (plugin *Plugin) GetOption(key string) interface{} {
return plugin.Options[key]
}
// SetOption sets the option value for the given key.
func (plugin *Plugin) SetOption(key string, value interface{}) {
plugin.Options[key] = value
}