2018-08-17 22:19:44 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/nomad/plugins/device"
|
2018-11-27 19:04:43 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/drivers"
|
2018-08-17 22:19:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PluginFactory returns a new plugin instance
|
|
|
|
type PluginFactory func(log log.Logger) interface{}
|
|
|
|
|
|
|
|
// Serve is used to serve a new Nomad plugin
|
|
|
|
func Serve(f PluginFactory) {
|
|
|
|
logger := log.New(&log.LoggerOptions{
|
|
|
|
Level: log.Trace,
|
|
|
|
JSONFormat: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
plugin := f(logger)
|
|
|
|
switch p := plugin.(type) {
|
|
|
|
case device.DevicePlugin:
|
|
|
|
device.Serve(p, logger)
|
2018-11-27 19:04:43 +00:00
|
|
|
case drivers.DriverPlugin:
|
|
|
|
drivers.Serve(p, logger)
|
2018-08-17 22:19:44 +00:00
|
|
|
default:
|
|
|
|
fmt.Println("Unsupported plugin type")
|
|
|
|
}
|
|
|
|
}
|