github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/driver/plugins.go (about) 1 package driver 2 3 import ( 4 "io" 5 "log" 6 "net" 7 "strings" 8 9 "github.com/hashicorp/go-plugin" 10 "github.com/hashicorp/logutils" 11 ) 12 13 var HandshakeConfig = plugin.HandshakeConfig{ 14 ProtocolVersion: 1, 15 MagicCookieKey: "NOMAD_PLUGIN_MAGIC_COOKIE", 16 MagicCookieValue: "e4327c2e01eabfd75a8a67adb114fb34a757d57eee7728d857a8cec6e91a7255", 17 } 18 19 func GetPluginMap(w io.Writer, logLevel string) map[string]plugin.Plugin { 20 e := new(ExecutorPlugin) 21 filter := &logutils.LevelFilter{ 22 Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"}, 23 MinLevel: logutils.LogLevel(strings.ToUpper(logLevel)), 24 Writer: w, 25 } 26 27 e.logger = log.New(filter, "", log.LstdFlags|log.Lmicroseconds) 28 29 return map[string]plugin.Plugin{ 30 "executor": e, 31 } 32 } 33 34 // ExecutorReattachConfig is the config that we seralize and de-serialize and 35 // store in disk 36 type PluginReattachConfig struct { 37 Pid int 38 AddrNet string 39 AddrName string 40 } 41 42 // PluginConfig returns a config from an ExecutorReattachConfig 43 func (c *PluginReattachConfig) PluginConfig() *plugin.ReattachConfig { 44 var addr net.Addr 45 switch c.AddrNet { 46 case "unix", "unixgram", "unixpacket": 47 addr, _ = net.ResolveUnixAddr(c.AddrNet, c.AddrName) 48 case "tcp", "tcp4", "tcp6": 49 addr, _ = net.ResolveTCPAddr(c.AddrNet, c.AddrName) 50 } 51 return &plugin.ReattachConfig{Pid: c.Pid, Addr: addr} 52 } 53 54 func NewPluginReattachConfig(c *plugin.ReattachConfig) *PluginReattachConfig { 55 return &PluginReattachConfig{Pid: c.Pid, AddrNet: c.Addr.Network(), AddrName: c.Addr.String()} 56 }