2018-08-13 17:52:59 +00:00
|
|
|
package base
|
2018-08-10 17:50:09 +00:00
|
|
|
|
|
|
|
import (
|
2018-10-17 02:21:15 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/base/proto"
|
2018-08-10 17:50:09 +00:00
|
|
|
"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.
|
2018-12-14 23:03:31 +00:00
|
|
|
SetConfig(c *Config) error
|
2018-08-10 17:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2018-12-14 23:03:31 +00:00
|
|
|
// PluginApiVersions returns the versions of the Nomad plugin API that the
|
|
|
|
// plugin supports.
|
|
|
|
PluginApiVersions []string
|
2018-08-10 17:50:09 +00:00
|
|
|
|
|
|
|
// PluginVersion is the version of the plugin.
|
|
|
|
PluginVersion string
|
|
|
|
|
|
|
|
// Name is the plugins name.
|
|
|
|
Name string
|
|
|
|
}
|
2018-10-17 02:21:15 +00:00
|
|
|
|
2018-12-14 23:03:31 +00:00
|
|
|
// 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 {
|
2018-10-30 01:34:34 +00:00
|
|
|
Driver *ClientDriverConfig
|
2018-10-19 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 01:34:34 +00:00
|
|
|
// ClientDriverConfig is the driver specific configuration for all driver plugins
|
|
|
|
type ClientDriverConfig struct {
|
2018-10-17 02:21:15 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-12-14 23:03:31 +00:00
|
|
|
func (c *AgentConfig) toProto() *proto.NomadConfig {
|
2018-10-17 02:21:15 +00:00
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-19 03:31:01 +00:00
|
|
|
|
|
|
|
cfg := &proto.NomadConfig{}
|
|
|
|
if c.Driver != nil {
|
|
|
|
|
|
|
|
cfg.Driver = &proto.NomadDriverConfig{
|
|
|
|
ClientMaxPort: uint32(c.Driver.ClientMaxPort),
|
|
|
|
ClientMinPort: uint32(c.Driver.ClientMinPort),
|
|
|
|
}
|
2018-10-17 02:21:15 +00:00
|
|
|
}
|
2018-10-19 03:31:01 +00:00
|
|
|
|
|
|
|
return cfg
|
2018-10-17 02:21:15 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 23:03:31 +00:00
|
|
|
func nomadConfigFromProto(pb *proto.NomadConfig) *AgentConfig {
|
2018-10-17 02:21:15 +00:00
|
|
|
if pb == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-10-19 03:31:01 +00:00
|
|
|
|
2018-12-14 23:03:31 +00:00
|
|
|
cfg := &AgentConfig{}
|
2018-10-19 03:31:01 +00:00
|
|
|
if pb.Driver != nil {
|
2018-10-30 01:34:34 +00:00
|
|
|
cfg.Driver = &ClientDriverConfig{
|
2018-10-19 03:31:01 +00:00
|
|
|
ClientMaxPort: uint(pb.Driver.ClientMaxPort),
|
|
|
|
ClientMinPort: uint(pb.Driver.ClientMinPort),
|
|
|
|
}
|
2018-10-17 02:21:15 +00:00
|
|
|
}
|
2018-10-19 03:31:01 +00:00
|
|
|
|
|
|
|
return cfg
|
2018-10-17 02:21:15 +00:00
|
|
|
}
|