Merge pull request #5436 from hashicorp/re5367
builder/vmware: Add `disable_vnc` option
This commit is contained in:
commit
47cb0c334d
@ -8,8 +8,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RunConfig struct {
|
type RunConfig struct {
|
||||||
Headless bool `mapstructure:"headless"`
|
Headless bool `mapstructure:"headless"`
|
||||||
RawBootWait string `mapstructure:"boot_wait"`
|
RawBootWait string `mapstructure:"boot_wait"`
|
||||||
|
DisableVNC bool `mapstructure:"disable_vnc"`
|
||||||
|
BootCommand []string `mapstructure:"boot_command"`
|
||||||
|
|
||||||
VNCBindAddress string `mapstructure:"vnc_bind_address"`
|
VNCBindAddress string `mapstructure:"vnc_bind_address"`
|
||||||
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
||||||
@ -38,6 +40,11 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
|||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
var err 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 != "" {
|
if c.RawBootWait != "" {
|
||||||
c.BootWait, err = time.ParseDuration(c.RawBootWait)
|
c.BootWait, err = time.ParseDuration(c.RawBootWait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
// <nothing>
|
// <nothing>
|
||||||
type StepCleanVMX struct {
|
type StepCleanVMX struct {
|
||||||
RemoveEthernetInterfaces bool
|
RemoveEthernetInterfaces bool
|
||||||
|
VNCEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StepCleanVMX) Run(state multistep.StateBag) multistep.StepAction {
|
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"
|
vmxData[ide+"clientdevice"] = "TRUE"
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Message("Disabling VNC server...")
|
if s.VNCEnabled {
|
||||||
vmxData["remotedisplay.vnc.enabled"] = "FALSE"
|
ui.Message("Disabling VNC server...")
|
||||||
|
vmxData["remotedisplay.vnc.enabled"] = "FALSE"
|
||||||
|
}
|
||||||
|
|
||||||
if s.RemoveEthernetInterfaces {
|
if s.RemoveEthernetInterfaces {
|
||||||
ui.Message("Removing Ethernet Interfaces...")
|
ui.Message("Removing Ethernet Interfaces...")
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
// Produces:
|
// Produces:
|
||||||
// vnc_port uint - The port that VNC is configured to listen on.
|
// vnc_port uint - The port that VNC is configured to listen on.
|
||||||
type StepConfigureVNC struct {
|
type StepConfigureVNC struct {
|
||||||
|
Enabled bool
|
||||||
VNCBindAddress string
|
VNCBindAddress string
|
||||||
VNCPortMin uint
|
VNCPortMin uint
|
||||||
VNCPortMax uint
|
VNCPortMax uint
|
||||||
@ -76,6 +77,11 @@ func VNCPassword(skipPassword bool) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
|
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)
|
driver := state.Get("driver").(Driver)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
vmxPath := state.Get("vmx_path").(string)
|
vmxPath := state.Get("vmx_path").(string)
|
||||||
|
@ -2,9 +2,10 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// This step runs the created virtual machine.
|
// This step runs the created virtual machine.
|
||||||
|
@ -36,12 +36,18 @@ type bootCommandTemplateData struct {
|
|||||||
// Produces:
|
// Produces:
|
||||||
// <nothing>
|
// <nothing>
|
||||||
type StepTypeBootCommand struct {
|
type StepTypeBootCommand struct {
|
||||||
|
VNCEnabled bool
|
||||||
BootCommand []string
|
BootCommand []string
|
||||||
VMName string
|
VMName string
|
||||||
Ctx interpolate.Context
|
Ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
|
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)
|
debug := state.Get("debug").(bool)
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
httpPort := state.Get("http_port").(uint)
|
httpPort := state.Get("http_port").(uint)
|
||||||
|
@ -38,7 +38,6 @@ type Config struct {
|
|||||||
vmwcommon.VMXConfig `mapstructure:",squash"`
|
vmwcommon.VMXConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
|
AdditionalDiskSize []uint `mapstructure:"disk_additional_size"`
|
||||||
BootCommand []string `mapstructure:"boot_command"`
|
|
||||||
DiskName string `mapstructure:"vmdk_name"`
|
DiskName string `mapstructure:"vmdk_name"`
|
||||||
DiskSize uint `mapstructure:"disk_size"`
|
DiskSize uint `mapstructure:"disk_size"`
|
||||||
DiskTypeId string `mapstructure:"disk_type_id"`
|
DiskTypeId string `mapstructure:"disk_type_id"`
|
||||||
@ -149,6 +148,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||||||
if b.config.RemotePort == 0 {
|
if b.config.RemotePort == 0 {
|
||||||
b.config.RemotePort = 22
|
b.config.RemotePort = 22
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.config.VMXTemplatePath != "" {
|
if b.config.VMXTemplatePath != "" {
|
||||||
if err := b.validateVMXTemplatePath(); err != nil {
|
if err := b.validateVMXTemplatePath(); err != nil {
|
||||||
errs = packer.MultiErrorAppend(
|
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.")
|
"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 {
|
if errs != nil && len(errs.Errors) > 0 {
|
||||||
return warnings, errs
|
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,
|
HTTPPortMax: b.config.HTTPPortMax,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepConfigureVNC{
|
&vmwcommon.StepConfigureVNC{
|
||||||
|
Enabled: !b.config.DisableVNC,
|
||||||
VNCBindAddress: b.config.VNCBindAddress,
|
VNCBindAddress: b.config.VNCBindAddress,
|
||||||
VNCPortMin: b.config.VNCPortMin,
|
VNCPortMin: b.config.VNCPortMin,
|
||||||
VNCPortMax: b.config.VNCPortMax,
|
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,
|
Headless: b.config.Headless,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepTypeBootCommand{
|
&vmwcommon.StepTypeBootCommand{
|
||||||
|
VNCEnabled: !b.config.DisableVNC,
|
||||||
BootCommand: b.config.BootCommand,
|
BootCommand: b.config.BootCommand,
|
||||||
VMName: b.config.VMName,
|
VMName: b.config.VMName,
|
||||||
Ctx: b.config.ctx,
|
Ctx: b.config.ctx,
|
||||||
@ -303,6 +311,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
},
|
},
|
||||||
&vmwcommon.StepCleanVMX{
|
&vmwcommon.StepCleanVMX{
|
||||||
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
||||||
|
VNCEnabled: !b.config.DisableVNC,
|
||||||
},
|
},
|
||||||
&StepUploadVMX{
|
&StepUploadVMX{
|
||||||
RemoteType: b.config.RemoteType,
|
RemoteType: b.config.RemoteType,
|
||||||
|
@ -80,6 +80,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
HTTPPortMax: b.config.HTTPPortMax,
|
HTTPPortMax: b.config.HTTPPortMax,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepConfigureVNC{
|
&vmwcommon.StepConfigureVNC{
|
||||||
|
Enabled: !b.config.DisableVNC,
|
||||||
VNCBindAddress: b.config.VNCBindAddress,
|
VNCBindAddress: b.config.VNCBindAddress,
|
||||||
VNCPortMin: b.config.VNCPortMin,
|
VNCPortMin: b.config.VNCPortMin,
|
||||||
VNCPortMax: b.config.VNCPortMax,
|
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,
|
Headless: b.config.Headless,
|
||||||
},
|
},
|
||||||
&vmwcommon.StepTypeBootCommand{
|
&vmwcommon.StepTypeBootCommand{
|
||||||
|
VNCEnabled: !b.config.DisableVNC,
|
||||||
BootCommand: b.config.BootCommand,
|
BootCommand: b.config.BootCommand,
|
||||||
VMName: b.config.VMName,
|
VMName: b.config.VMName,
|
||||||
Ctx: b.config.ctx,
|
Ctx: b.config.ctx,
|
||||||
@ -121,6 +123,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
},
|
},
|
||||||
&vmwcommon.StepCleanVMX{
|
&vmwcommon.StepCleanVMX{
|
||||||
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
RemoveEthernetInterfaces: b.config.VMXConfig.VMXRemoveEthernet,
|
||||||
|
VNCEnabled: !b.config.DisableVNC,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,11 +24,10 @@ type Config struct {
|
|||||||
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
||||||
vmwcommon.VMXConfig `mapstructure:",squash"`
|
vmwcommon.VMXConfig `mapstructure:",squash"`
|
||||||
|
|
||||||
BootCommand []string `mapstructure:"boot_command"`
|
RemoteType string `mapstructure:"remote_type"`
|
||||||
RemoteType string `mapstructure:"remote_type"`
|
SkipCompaction bool `mapstructure:"skip_compaction"`
|
||||||
SkipCompaction bool `mapstructure:"skip_compaction"`
|
SourcePath string `mapstructure:"source_path"`
|
||||||
SourcePath string `mapstructure:"source_path"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
|
||||||
|
|
||||||
ctx interpolate.Context
|
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.")
|
"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.
|
// Check for any errors.
|
||||||
if errs != nil && len(errs.Errors) > 0 {
|
if errs != nil && len(errs.Errors) > 0 {
|
||||||
return nil, warnings, errs
|
return nil, warnings, errs
|
||||||
|
@ -114,6 +114,9 @@ builder.
|
|||||||
User's Guide](https://www.vmware.com/pdf/VirtualDiskManager.pdf) for desktop
|
User's Guide](https://www.vmware.com/pdf/VirtualDiskManager.pdf) for desktop
|
||||||
VMware clients. For ESXi, refer to the proper ESXi documentation.
|
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
|
- `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
|
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
|
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
|
Packer also requires VNC to issue boot commands during a build, which may be
|
||||||
disabled on some remote VMware Hypervisors. Please consult the appropriate
|
disabled on some remote VMware Hypervisors. Please consult the appropriate
|
||||||
documentation on how to update VMware Hypervisor's firewall to allow these
|
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
|
To use a remote VMware vSphere Hypervisor to build your virtual machine, fill in
|
||||||
the required `remote_*` configurations:
|
the required `remote_*` configurations:
|
||||||
@ -482,7 +486,7 @@ modify as well:
|
|||||||
- `format` (string) - Either "ovf", "ova" or "vmx", this specifies the output
|
- `format` (string) - Either "ovf", "ova" or "vmx", this specifies the output
|
||||||
format of the exported virtual machine. This defaults to "ovf".
|
format of the exported virtual machine. This defaults to "ovf".
|
||||||
Before using this option, you need to install `ovftool`. This option
|
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
|
### VNC port discovery
|
||||||
|
|
||||||
|
@ -71,6 +71,9 @@ builder.
|
|||||||
five seconds and one minute 30 seconds, respectively. If this isn't
|
five seconds and one minute 30 seconds, respectively. If this isn't
|
||||||
specified, the default is 10 seconds.
|
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
|
- `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
|
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
|
unattended Windows installs, which look for an `Autounattend.xml` file on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user