Skip to content

Commit

Permalink
Merge pull request #4816 from hashicorp/b-qemu
Browse files Browse the repository at this point in the history
qemu: fix build and register by default
  • Loading branch information
schmichael authored Oct 30, 2018
2 parents 4b08ef0 + 7d28d34 commit dd04ca6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
27 changes: 23 additions & 4 deletions drivers/qemu/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/drivers/utils"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/loader"
"golang.org/x/net/context"
)

Expand All @@ -49,6 +50,20 @@ const (
)

var (
// PluginID is the qemu plugin metadata registered in the plugin
// catalog.
PluginID = loader.PluginID{
Name: pluginName,
PluginType: base.PluginTypeDriver,
}

// PluginConfig is the qemu driver factory function registered in the
// plugin catalog.
PluginConfig = &loader.InternalPluginConfig{
Config: map[string]interface{}{},
Factory: func(l hclog.Logger) interface{} { return NewQemuDriver(l) },
}

reQemuVersion = regexp.MustCompile(`version (\d[\.\d+]+)`)

// Prior to qemu 2.10.1, monitor socket paths are truncated to 108 bytes.
Expand Down Expand Up @@ -123,6 +138,9 @@ type QemuDriver struct {
// coordinate shutdown
ctx context.Context

// nomadConf is the client agent's configuration
nomadConfig *base.ClientDriverConfig

// signalShutdown is called when the driver is shutting down and cancels the
// ctx passed to any subsystems
signalShutdown context.CancelFunc
Expand Down Expand Up @@ -152,8 +170,10 @@ func (d *QemuDriver) ConfigSchema() (*hclspec.Spec, error) {
return configSpec, nil
}

func (d *QemuDriver) SetConfig(data []byte) error {
// nothing to do, no driver config
func (d *QemuDriver) SetConfig(_ []byte, cfg *base.ClientAgentConfig) error {
if cfg != nil {
d.nomadConfig = cfg.Driver
}
return nil
}

Expand Down Expand Up @@ -391,8 +411,7 @@ func (d *QemuDriver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *c
LogLevel: "debug",
}

// TODO: best way to pass port ranges in from client config
execImpl, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, 14000, 14512, executorConfig)
execImpl, pluginClient, err := utils.CreateExecutor(os.Stderr, hclog.Debug, d.nomadConfig, executorConfig)
if err != nil {
return nil, nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion plugins/shared/catalog/register.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package catalog

import "github.com/hashicorp/nomad/drivers/rawexec"
import (
"github.com/hashicorp/nomad/drivers/qemu"
"github.com/hashicorp/nomad/drivers/rawexec"
)

// This file is where all builtin plugins should be registered in the catalog.
// Plugins with build restrictions should be placed in the appropriate
// register_XXX.go file.
func init() {
RegisterDeferredConfig(rawexec.PluginID, rawexec.PluginConfig, rawexec.PluginLoader)
Register(qemu.PluginID, qemu.PluginConfig)
}

0 comments on commit dd04ca6

Please sign in to comment.