From 83f175cac70cb77d092c835f72f218a05840c9f9 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 6 Jul 2016 18:52:40 +0300 Subject: [PATCH 1/5] builder/qemu: dont fail on communicator - none Signed-off-by: Vasiliy Tolstov --- builder/qemu/builder.go | 35 ++++++++++++++++++++++++++++------- builder/qemu/step_run.go | 33 ++++++++++++++++++++++++--------- builder/qemu/step_shutdown.go | 25 ++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 19 deletions(-) diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index f151bf68c..413591899 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -376,19 +376,40 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe HTTPPortMin: b.config.HTTPPortMin, HTTPPortMax: b.config.HTTPPortMax, }, - new(stepForwardSSH), + ) + + if b.config.Comm.Type != "none" { + steps = append(steps, + new(stepForwardSSH), + ) + } + + steps = append(steps, new(stepConfigureVNC), steprun, &stepBootWait{}, &stepTypeBootCommand{}, - &communicator.StepConnect{ - Config: &b.config.Comm, - Host: commHost, - SSHConfig: sshConfig, - SSHPort: commPort, - }, + ) + + if b.config.Comm.Type != "none" { + steps = append(steps, + &communicator.StepConnect{ + Config: &b.config.Comm, + Host: commHost, + SSHConfig: sshConfig, + SSHPort: commPort, + }, + ) + } + + steps = append(steps, new(common.StepProvision), + ) + steps = append(steps, new(stepShutdown), + ) + + steps = append(steps, new(stepConvertDisk), ) diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index 82bcbe7c0..36ab074f5 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -63,7 +63,6 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error isoPath := state.Get("iso_path").(string) vncIP := state.Get("vnc_ip").(string) vncPort := state.Get("vnc_port").(uint) - sshHostPort := state.Get("sshHostPort").(uint) ui := state.Get("ui").(packer.Ui) driver := state.Get("driver").(Driver) @@ -74,10 +73,16 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error defaultArgs := make(map[string]interface{}) var deviceArgs []string var driveArgs []string + var sshHostPort uint defaultArgs["-name"] = vmName defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType) - defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port()) + if config.Comm.Type != "none" { + sshHostPort = state.Get("sshHostPort").(uint) + defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port()) + } else { + defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0") + } qemuVersion, err := driver.Version() if err != nil { @@ -157,13 +162,23 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error httpPort := state.Get("http_port").(uint) ctx := config.ctx - ctx.Data = qemuArgsTemplateData{ - "10.0.2.2", - httpPort, - config.HTTPDir, - config.OutputDir, - config.VMName, - sshHostPort, + if config.Comm.Type != "none" { + ctx.Data = qemuArgsTemplateData{ + "10.0.2.2", + httpPort, + config.HTTPDir, + config.OutputDir, + config.VMName, + sshHostPort, + } + } else { + ctx.Data = qemuArgsTemplateData{ + HTTPIP: "10.0.2.2", + HTTPPort: httpPort, + HTTPDir: config.HTTPDir, + OutputDir: config.OutputDir, + Name: config.VMName, + } } newQemuArgs, err := processArgs(config.QemuArgs, &ctx) if err != nil { diff --git a/builder/qemu/step_shutdown.go b/builder/qemu/step_shutdown.go index 127dcff12..2bca7a09e 100644 --- a/builder/qemu/step_shutdown.go +++ b/builder/qemu/step_shutdown.go @@ -3,10 +3,11 @@ package qemu import ( "errors" "fmt" - "github.com/mitchellh/multistep" - "github.com/mitchellh/packer/packer" "log" "time" + + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" ) // This step shuts down the machine. It first attempts to do so gracefully, @@ -23,11 +24,29 @@ import ( type stepShutdown struct{} func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { - comm := state.Get("communicator").(packer.Communicator) config := state.Get("config").(*Config) driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) + if state.Get("communicator") == nil { + cancelCh := make(chan struct{}, 1) + go func() { + defer close(cancelCh) + <-time.After(config.shutdownTimeout) + }() + ui.Say("Waiting for shutdown...") + if ok := driver.WaitForShutdown(cancelCh); ok { + log.Println("VM shut down.") + return multistep.ActionContinue + } else { + err := fmt.Errorf("Failed to shutdown") + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + + comm := state.Get("communicator").(packer.Communicator) if config.ShutdownCommand != "" { ui.Say("Gracefully halting virtual machine...") log.Printf("Executing shutdown command: %s", config.ShutdownCommand) From 923375cdbc1d6020fd4e559627aa2d0ad3052a6e Mon Sep 17 00:00:00 2001 From: Cameron Stokes Date: Wed, 20 Jul 2016 11:12:20 -0700 Subject: [PATCH 2/5] Clarify googlecompute#metadata usage. --- website/source/docs/builders/googlecompute.html.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/source/docs/builders/googlecompute.html.md b/website/source/docs/builders/googlecompute.html.md index c4842b976..6f0e4e496 100644 --- a/website/source/docs/builders/googlecompute.html.md +++ b/website/source/docs/builders/googlecompute.html.md @@ -140,7 +140,8 @@ builder. - `machine_type` (string) - The machine type. Defaults to `"n1-standard-1"`. -- `metadata` (object of key/value strings) +- `metadata` (object of key/value strings) - Metadata applied to the launched + instance. - `network` (string) - The Google Compute network to use for the launched instance. Defaults to `"default"`. From 94bf981d3bd0902ed5b3b06b2fbcc484bd90ca74 Mon Sep 17 00:00:00 2001 From: Robert Tarrall Date: Tue, 26 Jul 2016 08:15:44 -0600 Subject: [PATCH 3/5] Honor ssh_private_ip flag in EC2-Classic, not just VPC VpcId will be nil in Classic, but we may still wish to ssh to the instance's private IP address -- if for example we are using security groups to block SSH access via the public IP. --- builder/amazon/common/ssh.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index d689d5990..fdf983368 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -23,6 +23,8 @@ func SSHHost(e *ec2.EC2, private bool) func(multistep.StateBag) (string, error) } else { host = *i.PrivateIpAddress } + } else if private { + host = *i.PrivateIpAddress } else if i.PublicDnsName != nil && *i.PublicDnsName != "" { host = *i.PublicDnsName } From 9cf476289f6c327f19cf10d4b042336fd399f6e5 Mon Sep 17 00:00:00 2001 From: "Billie H. Cleek" Date: Tue, 13 Sep 2016 08:18:21 -0700 Subject: [PATCH 4/5] document ansible provisioner's option. --- website/source/docs/provisioners/ansible.html.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/docs/provisioners/ansible.html.md b/website/source/docs/provisioners/ansible.html.md index 2656130e9..6ca6ce614 100644 --- a/website/source/docs/provisioners/ansible.html.md +++ b/website/source/docs/provisioners/ansible.html.md @@ -47,6 +47,9 @@ Required Parameters: Optional Parameters: +- `command` (string) - The command to invoke ansible. + Defaults to `ansible-playbook`. + - `groups` (array of strings) - The groups into which the Ansible host should be placed. When unspecified, the host is not associated with any groups. From f6f50cd1df433a5bd7c24a81ad7001b3c223e24c Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Tue, 13 Sep 2016 23:08:00 +0200 Subject: [PATCH 5/5] Updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5681460c8..85f3154fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ BUG FIXES: * builder/amazon: Use `temporary_key_pair_name` when specified. [GH-3739] * builder/amazon: Add 0.5 cents to discovered spot price. [GH-3662] * builder/amazon: Fix packer crash when waiting for SSH. [GH-3865] + * builder/amazon: Honor ssh_private_ip flag in EC2-Classic. [GH-3752] * builder/azure: check for empty resource group [GH-3606] * builder/azure: fix token validity test [GH-3609] * builder/docker: fix docker builder with ansible provisioner. [GH-3476] @@ -82,6 +83,7 @@ BUG FIXES: * builder/vmware: Respect `ssh_host`/`winrm_host` on ESXi [GH-3738] * builder/vmware: Do not add remotedisplay.vnc.ip to VMX data on ESXi [GH-3740] + * builder/qemu: Don't fail on communicator set to `none`. [GH-3681] * website: improved rendering on iPad [GH-3780] ## 0.10.1 (May 7, 2016)