-
Notifications
You must be signed in to change notification settings - Fork 2k
/
base.go
98 lines (77 loc) · 2.47 KB
/
base.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package base
import (
"github.com/hashicorp/nomad/plugins/base/proto"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
)
// BasePlugin is the interface that all Nomad plugins must support.
type BasePlugin interface {
// PluginInfo describes the type and version of a plugin.
PluginInfo() (*PluginInfoResponse, error)
// ConfigSchema returns the schema for parsing the plugins configuration.
ConfigSchema() (*hclspec.Spec, error)
// SetConfig is used to set the configuration by passing a MessagePack
// encoding of it.
SetConfig(c *Config) error
}
// PluginInfoResponse returns basic information about the plugin such that Nomad
// can decide whether to load the plugin or not.
type PluginInfoResponse struct {
// Type returns the plugins type
Type string
// PluginApiVersions returns the versions of the Nomad plugin API that the
// plugin supports.
PluginApiVersions []string
// PluginVersion is the version of the plugin.
PluginVersion string
// Name is the plugins name.
Name string
}
// Config contains the configuration for the plugin.
type Config struct {
// ApiVersion is the negotiated plugin API version to use.
ApiVersion string
// PluginConfig is the MessagePack encoding of the plugins user
// configuration.
PluginConfig []byte
// AgentConfig is the Nomad agents configuration as applicable to plugins
AgentConfig *AgentConfig
}
// AgentConfig is the Nomad agent's configuration sent to all plugins
type AgentConfig struct {
Driver *ClientDriverConfig
}
// ClientDriverConfig is the driver specific configuration for all driver plugins
type ClientDriverConfig struct {
// ClientMaxPort is the upper range of the ports that the client uses for
// communicating with plugin subsystems over loopback
ClientMaxPort uint
// ClientMinPort is the lower range of the ports that the client uses for
// communicating with plugin subsystems over loopback
ClientMinPort uint
}
func (c *AgentConfig) toProto() *proto.NomadConfig {
if c == nil {
return nil
}
cfg := &proto.NomadConfig{}
if c.Driver != nil {
cfg.Driver = &proto.NomadDriverConfig{
ClientMaxPort: uint32(c.Driver.ClientMaxPort),
ClientMinPort: uint32(c.Driver.ClientMinPort),
}
}
return cfg
}
func nomadConfigFromProto(pb *proto.NomadConfig) *AgentConfig {
if pb == nil {
return nil
}
cfg := &AgentConfig{}
if pb.Driver != nil {
cfg.Driver = &ClientDriverConfig{
ClientMaxPort: uint(pb.Driver.ClientMaxPort),
ClientMinPort: uint(pb.Driver.ClientMinPort),
}
}
return cfg
}