Enable to disable vnc password for VMware builder

pull/3821/head
Rickard von Essen 10 years ago
parent f961ce701b
commit 3e1aed9a6f

@ -11,9 +11,10 @@ type RunConfig struct {
Headless bool `mapstructure:"headless"`
RawBootWait string `mapstructure:"boot_wait"`
VNCBindAddress string `mapstructure:"vnc_bind_address"`
VNCPortMin uint `mapstructure:"vnc_port_min"`
VNCPortMax uint `mapstructure:"vnc_port_max"`
VNCBindAddress string `mapstructure:"vnc_bind_address"`
VNCPortMin uint `mapstructure:"vnc_port_min"`
VNCPortMax uint `mapstructure:"vnc_port_max"`
VNCDisablePassword bool `mapstructure:"vnc_disable_password"`
BootWait time.Duration ``
}

@ -21,9 +21,10 @@ import (
// Produces:
// vnc_port uint - The port that VNC is configured to listen on.
type StepConfigureVNC struct {
VNCBindAddress string
VNCPortMin uint
VNCPortMax uint
VNCBindAddress string
VNCPortMin uint
VNCPortMax uint
VNCDisablePassword bool
}
type VNCAddressFinder interface {
@ -56,7 +57,10 @@ func (StepConfigureVNC) VNCAddress(vncBindAddress string, portMin, portMax uint)
return vncBindAddress, vncPort, nil
}
func VNCPassword() string {
func VNCPassword(skipPassword bool) string {
if skipPassword {
return ""
}
length := int(8)
charSet := []byte("1234567890-=qwertyuiop[]asdfghjkl;zxcvbnm,./!@#%^*()_+QWERTYUIOP{}|ASDFGHJKL:XCVBNM<>?")
@ -106,7 +110,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
vncPassword := VNCPassword()
vncPassword := VNCPassword(s.VNCDisablePassword)
log.Printf("Found available VNC port: %d", vncPort)
@ -131,7 +135,9 @@ func (StepConfigureVNC) UpdateVMX(address, password string, port uint, data map[
data["remotedisplay.vnc.enabled"] = "TRUE"
data["remotedisplay.vnc.port"] = fmt.Sprintf("%d", port)
data["remotedisplay.vnc.ip"] = address
data["remotedisplay.vnc.password"] = password
if len(password) > 0 {
data["remotedisplay.vnc.password"] = password
}
}
func (StepConfigureVNC) Cleanup(multistep.StateBag) {

@ -47,7 +47,7 @@ func (s *StepRun) Run(state multistep.StateBag) multistep.StepAction {
ui.Message(fmt.Sprintf(
"The VM will be run headless, without a GUI. If you want to\n"+
"view the screen of the VM, connect via VNC with the password %s to\n"+
"view the screen of the VM, connect via VNC with the password \"%s\" to\n"+
"%s:%d", vncPassword, vncIp, vncPort))
} else {
ui.Message("The VM will be run headless, without a GUI, as configured.\n" +

@ -66,10 +66,10 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
var auth []vnc.ClientAuth
if vncPassword != nil {
if vncPassword != nil && len(vncPassword.(string)) > 0 {
auth = []vnc.ClientAuth{&vnc.PasswordAuth{Password: vncPassword.(string)}}
} else {
auth = []vnc.ClientAuth{}
auth = []vnc.ClientAuth{new(vnc.ClientAuthNone)}
}
c, err := vnc.Client(nc, &vnc.ClientConfig{Auth: auth, Exclusive: true})

@ -256,9 +256,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMax: b.config.HTTPPortMax,
},
&vmwcommon.StepConfigureVNC{
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
VNCDisablePassword: b.config.VNCDisablePassword,
},
&StepRegister{
Format: b.config.Format,

@ -235,7 +235,9 @@ func (ESX5Driver) UpdateVMX(_, password string, port uint, data map[string]strin
// Do not set remotedisplay.vnc.ip - this breaks ESXi.
data["remotedisplay.vnc.enabled"] = "TRUE"
data["remotedisplay.vnc.port"] = fmt.Sprintf("%d", port)
data["remotedisplay.vnc.password"] = password
if len(password) > 0 {
data["remotedisplay.vnc.password"] = password
}
}
func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) {

@ -79,9 +79,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMax: b.config.HTTPPortMax,
},
&vmwcommon.StepConfigureVNC{
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
VNCBindAddress: b.config.VNCBindAddress,
VNCPortMin: b.config.VNCPortMin,
VNCPortMax: b.config.VNCPortMax,
VNCDisablePassword: b.config.VNCDisablePassword,
},
&vmwcommon.StepRun{
BootWait: b.config.BootWait,

@ -267,8 +267,11 @@ builder.
`vmx_data` first.
- `vnc_bind_address` (string / IP address) - The IP address that should be binded
to for VNC. By default packer will use 127.0.0.1 for this. If you wish to bind
to all interfaces use 0.0.0.0
to for VNC. By default packer will use 127.0.0.1 for this. If you wish to bind
to all interfaces use 0.0.0.0
- `vnc_disable_password` (boolean) - Don't auto-generate a VNC password that is
used to secure the VNC communication with the VM.
- `vnc_port_min` and `vnc_port_max` (integer) - The minimum and maximum port
to use for VNC access to the virtual machine. The builder uses VNC to type

@ -148,6 +148,9 @@ builder.
- `vnc_bind_address` (string / IP address) - The IP address that should be binded
to for VNC. By default packer will use 127.0.0.1 for this.
- `vnc_disable_password` (boolean) - Don't auto-generate a VNC password that is
used to secure the VNC communication with the VM.
- `vnc_port_min` and `vnc_port_max` (integer) - The minimum and maximum port
to use for VNC access to the virtual machine. The builder uses VNC to type
the initial `boot_command`. Because Packer generally runs in parallel,

Loading…
Cancel
Save