QEMU: Remove QMPEnable and depend upon VNC password usage for QMP enablement.
This commit is contained in:
parent
4b0a7b0af7
commit
7f5fd4851e
@ -117,7 +117,6 @@ type Config struct {
|
|||||||
OutputDir string `mapstructure:"output_directory"`
|
OutputDir string `mapstructure:"output_directory"`
|
||||||
QemuArgs [][]string `mapstructure:"qemuargs"`
|
QemuArgs [][]string `mapstructure:"qemuargs"`
|
||||||
QemuBinary string `mapstructure:"qemu_binary"`
|
QemuBinary string `mapstructure:"qemu_binary"`
|
||||||
QMPEnable bool `mapstructure:"qmp_enable"`
|
|
||||||
QMPSocketPath string `mapstructure:"qmp_socket_path"`
|
QMPSocketPath string `mapstructure:"qmp_socket_path"`
|
||||||
ShutdownCommand string `mapstructure:"shutdown_command"`
|
ShutdownCommand string `mapstructure:"shutdown_command"`
|
||||||
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
|
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
|
||||||
@ -358,11 +357,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||||||
errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
|
errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.config.VNCUsePassword && !b.config.QMPEnable {
|
if b.config.VNCUsePassword && b.config.QMPSocketPath == "" {
|
||||||
b.config.QMPEnable = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if b.config.QMPEnable && b.config.QMPSocketPath == "" {
|
|
||||||
socketName := fmt.Sprintf("%s.monitor", b.config.VMName)
|
socketName := fmt.Sprintf("%s.monitor", b.config.VMName)
|
||||||
b.config.QMPSocketPath = filepath.Join(b.config.OutputDir, socketName)
|
b.config.QMPSocketPath = filepath.Join(b.config.OutputDir, socketName)
|
||||||
}
|
}
|
||||||
|
@ -114,25 +114,6 @@ func TestBuilderPrepare_VNCBindAddress(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_VNCPassword(t *testing.T) {
|
|
||||||
var b Builder
|
|
||||||
config := testConfig()
|
|
||||||
|
|
||||||
// Test a default boot_wait
|
|
||||||
config["vnc_use_password"] = true
|
|
||||||
warns, err := b.Prepare(config)
|
|
||||||
if len(warns) > 0 {
|
|
||||||
t.Fatalf("bad: %#v", warns)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("err: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !b.config.QMPEnable {
|
|
||||||
t.Fatalf("QMP should be enabled.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuilderPrepare_DiskCompaction(t *testing.T) {
|
func TestBuilderPrepare_DiskCompaction(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
@ -619,12 +600,11 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_QMP(t *testing.T) {
|
func TestBuilderPrepare_VNCPassword(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
||||||
// QMP Defaults
|
config["vnc_use_password"] = true
|
||||||
config["qmp_enable"] = true
|
|
||||||
config["output_directory"] = "not-a-real-directory"
|
config["output_directory"] = "not-a-real-directory"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
warns, err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
@ -26,7 +26,7 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu
|
|||||||
config := state.Get("config").(*Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
if !config.QMPEnable {
|
if !config.VNCUsePassword {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,49 +35,46 @@ func (s *stepConfigureQMP) Run(ctx context.Context, state multistep.StateBag) mu
|
|||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
|
|
||||||
// Only initialize and open QMP when we have a use for it.
|
// Only initialize and open QMP when we have a use for it.
|
||||||
// Handles cases where user may want the socket, but we don't
|
// Open QMP socket
|
||||||
if config.VNCUsePassword {
|
var err error
|
||||||
// Open QMP socket
|
var cmd []byte
|
||||||
var err error
|
var result []byte
|
||||||
var cmd []byte
|
s.monitor, err = qmp.NewSocketMonitor("unix", config.QMPSocketPath, 2*time.Second)
|
||||||
var result []byte
|
if err != nil {
|
||||||
s.monitor, err = qmp.NewSocketMonitor("unix", config.QMPSocketPath, 2*time.Second)
|
err := fmt.Errorf("Error opening QMP socket: %s", err)
|
||||||
if err != nil {
|
state.Put("error", err)
|
||||||
err := fmt.Errorf("Error opening QMP socket: %s", err)
|
ui.Error(err.Error())
|
||||||
state.Put("error", err)
|
return multistep.ActionHalt
|
||||||
ui.Error(err.Error())
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
QMPMonitor := s.monitor
|
|
||||||
vncPassword := state.Get("vnc_password")
|
|
||||||
|
|
||||||
// Connect to QMP
|
|
||||||
// function automatically calls capabilities so is immediately ready for commands
|
|
||||||
err = QMPMonitor.Connect()
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("Error connecting to QMP socket: %s", err)
|
|
||||||
state.Put("error", err)
|
|
||||||
ui.Error(err.Error())
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
log.Printf("QMP socket open SUCCESS")
|
|
||||||
|
|
||||||
cmd = []byte(fmt.Sprintf("{ \"execute\": \"change-vnc-password\", \"arguments\": { \"password\": \"%s\" } }",
|
|
||||||
vncPassword))
|
|
||||||
result, err = QMPMonitor.Run(cmd)
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("Error connecting to QMP socket: %s", err)
|
|
||||||
state.Put("error", err)
|
|
||||||
ui.Error(err.Error())
|
|
||||||
return multistep.ActionHalt
|
|
||||||
}
|
|
||||||
msg = fmt.Sprintf("QMP Command: %s\nResult: %s", cmd, result)
|
|
||||||
log.Printf(msg)
|
|
||||||
|
|
||||||
// Put QMP monitor in statebag in case there is a use in a following step
|
|
||||||
// Uncomment for future case as it is unused for now
|
|
||||||
//state.Put("qmp_monitor", QMPMonitor)
|
|
||||||
}
|
}
|
||||||
|
QMPMonitor := s.monitor
|
||||||
|
vncPassword := state.Get("vnc_password")
|
||||||
|
|
||||||
|
// Connect to QMP
|
||||||
|
// function automatically calls capabilities so is immediately ready for commands
|
||||||
|
err = QMPMonitor.Connect()
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error connecting to QMP socket: %s", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
log.Printf("QMP socket open SUCCESS")
|
||||||
|
|
||||||
|
cmd = []byte(fmt.Sprintf("{ \"execute\": \"change-vnc-password\", \"arguments\": { \"password\": \"%s\" } }",
|
||||||
|
vncPassword))
|
||||||
|
result, err = QMPMonitor.Run(cmd)
|
||||||
|
if err != nil {
|
||||||
|
err := fmt.Errorf("Error connecting to QMP socket: %s", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
msg = fmt.Sprintf("QMP Command: %s\nResult: %s", cmd, result)
|
||||||
|
log.Printf(msg)
|
||||||
|
|
||||||
|
// Put QMP monitor in statebag in case there is a use in a following step
|
||||||
|
// Uncomment for future case as it is unused for now
|
||||||
|
//state.Put("qmp_monitor", QMPMonitor)
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||||||
vnc = fmt.Sprintf("%s:%d", vncIP, vncPort-5900)
|
vnc = fmt.Sprintf("%s:%d", vncIP, vncPort-5900)
|
||||||
} else {
|
} else {
|
||||||
vnc = fmt.Sprintf("%s:%d,password", vncIP, vncPort-5900)
|
vnc = fmt.Sprintf("%s:%d,password", vncIP, vncPort-5900)
|
||||||
|
defaultArgs["-qmp"] = fmt.Sprintf("unix:%s,server,nowait", config.QMPSocketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultArgs["-name"] = vmName
|
defaultArgs["-name"] = vmName
|
||||||
@ -90,10 +91,6 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||||||
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
|
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.QMPEnable {
|
|
||||||
defaultArgs["-qmp"] = fmt.Sprintf("unix:%s,server,nowait", config.QMPSocketPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
rawVersion, err := driver.Version()
|
rawVersion, err := driver.Version()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -282,11 +282,7 @@ Linux server and have not enabled X11 forwarding (`ssh -X`).
|
|||||||
switch/value pairs. Any value specified as an empty string is ignored. All
|
switch/value pairs. Any value specified as an empty string is ignored. All
|
||||||
values after the switch are concatenated with no separator.
|
values after the switch are concatenated with no separator.
|
||||||
|
|
||||||
- `qmp_enable` (bool) - Enable QMP socket. Location is specified by
|
- `qmp_socket_path` (string) - QMP Socket Path when `vnc_use_password` is true.
|
||||||
`qmp_socket_path`.
|
|
||||||
Defaults to false.
|
|
||||||
|
|
||||||
- `qmp_socket_path` (string) - QMP Socket Path when `qmp_enable` is true.
|
|
||||||
Defaults to `output_directory`/`vm_name`.monitor.
|
Defaults to `output_directory`/`vm_name`.monitor.
|
||||||
|
|
||||||
~> **Warning:** The qemu command line allows extreme flexibility, so beware
|
~> **Warning:** The qemu command line allows extreme flexibility, so beware
|
||||||
@ -398,7 +394,7 @@ default port of `5985` or whatever value you have the service set to listen on.
|
|||||||
default this is `5900` to `6000`. The minimum and maximum ports are inclusive.
|
default this is `5900` to `6000`. The minimum and maximum ports are inclusive.
|
||||||
|
|
||||||
- `vnc_use_password` (bool) - Whether or not to set a password on the VNC server.
|
- `vnc_use_password` (bool) - Whether or not to set a password on the VNC server.
|
||||||
This option automatically sets `qmp_enable` to true.
|
This option automatically enables the QMP socket. See `qmp_socket_path`.
|
||||||
Defaults to `false`.
|
Defaults to `false`.
|
||||||
|
|
||||||
## Boot Command
|
## Boot Command
|
||||||
|
Loading…
x
Reference in New Issue
Block a user