add new disable_vnc option

This commit is contained in:
Matthew Hooker 2017-10-09 17:12:33 -07:00
parent 6a238a3ef3
commit 106408f6be
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
9 changed files with 49 additions and 20 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,7 +21,7 @@ import (
// Produces:
// vnc_port uint - The port that VNC is configured to listen on.
type StepConfigureVNC struct {
Skip bool
Enabled bool
VNCBindAddress string
VNCPortMin uint
VNCPortMax uint
@ -77,7 +77,7 @@ func VNCPassword(skipPassword bool) string {
}
func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
if s.Skip {
if !s.Enabled {
log.Println("Skipping VNC configuration step...")
return multistep.ActionContinue
}

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,14 +36,14 @@ type bootCommandTemplateData struct {
// Produces:
// <nothing>
type StepTypeBootCommand struct {
VNCEnabled bool
BootCommand []string
VMName string
Ctx interpolate.Context
Skip bool
}
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
if s.Skip {
if !s.VNCEnabled {
log.Println("Skipping boot command step...")
return multistep.ActionContinue
}

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,7 +265,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMax: b.config.HTTPPortMax,
},
&vmwcommon.StepConfigureVNC{
Skip: b.config.BootCommand == nil,
Enabled: !b.config.DisableVNC,
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
@ -274,7 +280,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Headless: b.config.Headless,
},
&vmwcommon.StepTypeBootCommand{
Skip: b.config.BootCommand == nil,
VNCEnabled: !b.config.DisableVNC,
BootCommand: b.config.BootCommand,
VMName: b.config.VMName,
Ctx: b.config.ctx,
@ -305,7 +311,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
&vmwcommon.StepCleanVMX{
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
SkipVNCDisable: b.config.BootCommand == nil,
SkipVNCDisable: 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,
SkipVNCDisable: 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
@ -446,10 +449,11 @@ various files locally, and uploads these to the remote machine. Packer currently
uses SSH to communicate to the ESXi machine rather than the vSphere API. At some
point, the vSphere API may be used.
Packer also requires VNC if issuing boot commands during a build, which may be
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:
@ -482,7 +486,7 @@ 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".
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