Merge pull request #5436 from hashicorp/re5367

builder/vmware: Add `disable_vnc` option
This commit is contained in:
Matthew Hooker 2017-10-12 16:43:09 -07:00 committed by GitHub
commit 47cb0c334d
10 changed files with 61 additions and 14 deletions

View File

@ -8,8 +8,10 @@ import (
)
type RunConfig struct {
Headless bool `mapstructure:"headless"`
RawBootWait string `mapstructure:"boot_wait"`
Headless bool `mapstructure:"headless"`
RawBootWait string `mapstructure:"boot_wait"`
DisableVNC bool `mapstructure:"disable_vnc"`
BootCommand []string `mapstructure:"boot_command"`
VNCBindAddress string `mapstructure:"vnc_bind_address"`
VNCPortMin uint `mapstructure:"vnc_port_min"`
@ -38,6 +40,11 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
var errs []error
var err error
if len(c.BootCommand) > 0 && c.DisableVNC {
errs = append(errs,
fmt.Errorf("A boot command cannot be used when vnc is disabled."))
}
if c.RawBootWait != "" {
c.BootWait, err = time.ParseDuration(c.RawBootWait)
if err != nil {

View File

@ -21,6 +21,7 @@ import (
// <nothing>
type StepCleanVMX struct {
RemoveEthernetInterfaces bool
VNCEnabled bool
}
func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
@ -59,8 +60,10 @@ func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
vmxData[ide+"clientdevice"] = "TRUE"
}
ui.Message("Disabling VNC server...")
vmxData["remotedisplay.vnc.enabled"] = "FALSE"
if s.VNCEnabled {
ui.Message("Disabling VNC server...")
vmxData["remotedisplay.vnc.enabled"] = "FALSE"
}
if s.RemoveEthernetInterfaces {
ui.Message("Removing Ethernet Interfaces...")

View File

@ -21,6 +21,7 @@ import (
// Produces:
// vnc_port uint - The port that VNC is configured to listen on.
type StepConfigureVNC struct {
Enabled bool
VNCBindAddress string
VNCPortMin uint
VNCPortMax uint
@ -76,6 +77,11 @@ func VNCPassword(skipPassword bool) string {
}
func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
if !s.Enabled {
log.Println("Skipping VNC configuration step...")
return multistep.ActionContinue
}
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmxPath := state.Get("vmx_path").(string)

View File

@ -2,9 +2,10 @@ package common
import (
"fmt"
"time"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
"time"
)
// This step runs the created virtual machine.

View File

@ -36,12 +36,18 @@ type bootCommandTemplateData struct {
// Produces:
// <nothing>
type StepTypeBootCommand struct {
VNCEnabled bool
BootCommand []string
VMName string
Ctx interpolate.Context
}
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
if !s.VNCEnabled {
log.Println("Skipping boot command step...")
return multistep.ActionContinue
}
debug := state.Get("debug").(bool)
driver := state.Get("driver").(Driver)
httpPort := state.Get("http_port").(uint)

View File

@ -38,7 +38,6 @@ type Config struct {
vmwcommon.VMXConfig `mapstructure:",squash"`
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
BootCommand []string `mapstructure:"boot_command"`
DiskName string `mapstructure:"vmdk_name"`
DiskSize uint `mapstructure:"disk_size"`
DiskTypeId string `mapstructure:"disk_type_id"`
@ -149,6 +148,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
if b.config.RemotePort == 0 {
b.config.RemotePort = 22
}
if b.config.VMXTemplatePath != "" {
if err := b.validateVMXTemplatePath(); err != nil {
errs = packer.MultiErrorAppend(
@ -179,6 +179,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"will forcibly halt the virtual machine, which may result in data loss.")
}
if b.config.Headless && b.config.DisableVNC {
warnings = append(warnings,
"Headless mode uses VNC to retrieve output. Since VNC has been disabled,\n"+
"you won't be able to see any output.")
}
if errs != nil && len(errs.Errors) > 0 {
return warnings, errs
}
@ -259,6 +265,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMax: b.config.HTTPPortMax,
},
&vmwcommon.StepConfigureVNC{
Enabled: !b.config.DisableVNC,
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
@ -273,6 +280,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Headless: b.config.Headless,
},
&vmwcommon.StepTypeBootCommand{
VNCEnabled: !b.config.DisableVNC,
BootCommand: b.config.BootCommand,
VMName: b.config.VMName,
Ctx: b.config.ctx,
@ -303,6 +311,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&vmwcommon.StepCleanVMX{
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
VNCEnabled: !b.config.DisableVNC,
},
&StepUploadVMX{
RemoteType: b.config.RemoteType,

View File

@ -80,6 +80,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMax: b.config.HTTPPortMax,
},
&vmwcommon.StepConfigureVNC{
Enabled: !b.config.DisableVNC,
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
@ -91,6 +92,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Headless: b.config.Headless,
},
&vmwcommon.StepTypeBootCommand{
VNCEnabled: !b.config.DisableVNC,
BootCommand: b.config.BootCommand,
VMName: b.config.VMName,
Ctx: b.config.ctx,
@ -121,6 +123,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&vmwcommon.StepCleanVMX{
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
VNCEnabled: !b.config.DisableVNC,
},
}

View File

@ -24,11 +24,10 @@ type Config struct {
vmwcommon.ToolsConfig `mapstructure:",squash"`
vmwcommon.VMXConfig `mapstructure:",squash"`
BootCommand []string `mapstructure:"boot_command"`
RemoteType string `mapstructure:"remote_type"`
SkipCompaction bool `mapstructure:"skip_compaction"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
RemoteType string `mapstructure:"remote_type"`
SkipCompaction bool `mapstructure:"skip_compaction"`
SourcePath string `mapstructure:"source_path"`
VMName string `mapstructure:"vm_name"`
ctx interpolate.Context
}
@ -84,6 +83,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
"will forcibly halt the virtual machine, which may result in data loss.")
}
if c.Headless && c.DisableVNC {
warnings = append(warnings,
"Headless mode uses VNC to retrieve output. Since VNC has been disabled,\n"+
"you won't be able to see any output.")
}
// Check for any errors.
if errs != nil && len(errs.Errors) > 0 {
return nil, warnings, errs

View File

@ -114,6 +114,9 @@ builder.
User's Guide](https://www.vmware.com/pdf/VirtualDiskManager.pdf) for desktop
VMware clients. For ESXi, refer to the proper ESXi documentation.
* `disable_vnc` (bool) - Whether to create a VNC connection or not.
A `boot_command` cannot be used when this is `false`. Defaults to `false`.
- `floppy_files` (array of strings) - A list of files to place onto a floppy
disk that is attached when the VM is booted. This is most useful for
unattended Windows installs, which look for an `Autounattend.xml` file on
@ -449,7 +452,8 @@ point, the vSphere API may be used.
Packer also requires VNC to issue boot commands during a build, which may be
disabled on some remote VMware Hypervisors. Please consult the appropriate
documentation on how to update VMware Hypervisor's firewall to allow these
connections.
connections. VNC can be disabled by not setting a `boot_command` and setting
`disable_vnc` to `true`.
To use a remote VMware vSphere Hypervisor to build your virtual machine, fill in
the required `remote_*` configurations:
@ -481,8 +485,8 @@ modify as well:
- `format` (string) - Either "ovf", "ova" or "vmx", this specifies the output
format of the exported virtual machine. This defaults to "ovf".
Before using this option, you need to install `ovftool`. This option
works currently only with option remote_type set to "esx5".
Before using this option, you need to install `ovftool`. This option
works currently only with option remote_type set to "esx5".
### VNC port discovery

View File

@ -71,6 +71,9 @@ builder.
five seconds and one minute 30 seconds, respectively. If this isn't
specified, the default is 10 seconds.
* `disable_vnc` (bool) - Whether to create a VNC connection or not.
A `boot_command` cannot be used when this is `false`. Defaults to `false`.
- `floppy_files` (array of strings) - A list of files to place onto a floppy
disk that is attached when the VM is booted. This is most useful for
unattended Windows installs, which look for an `Autounattend.xml` file on