github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/builder/vmware/common/step_configure_vnc.go.rej (about)

     1  diff a/builder/vmware/common/step_configure_vnc.go b/builder/vmware/common/step_configure_vnc.go	(rejected hunks)
     2  @@ -52,6 +52,21 @@ func (StepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error)
     3   	return "127.0.0.1", vncPort, nil
     4   }
     5   
     6  +func VNCPassword() (string) {
     7  +	length := int(8)
     8  +
     9  +	charSet := []byte("1234567890-=qwertyuiop[]asdfghjkl;zxcvbnm,./!@#%^*()_+QWERTYUIOP{}|ASDFGHJKL:XCVBNM<>?")
    10  +	charSetLength := len(charSet)
    11  +
    12  +	password := make([]byte, length)
    13  +
    14  +	for i := 0; i < length; i++ {
    15  +		password[i] = charSet[ rand.Intn(charSetLength) ]
    16  +	}
    17  +
    18  +	return string(password)
    19  +}
    20  +
    21   func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
    22   	driver := state.Get("driver").(Driver)
    23   	ui := state.Get("ui").(packer.Ui)
    24  @@ -86,12 +101,14 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
    25   		ui.Error(err.Error())
    26   		return multistep.ActionHalt
    27   	}
    28  +	vncPassword := VNCPassword()
    29   
    30   	log.Printf("Found available VNC port: %d", vncPort)
    31   
    32   	vmxData := ParseVMX(string(vmxBytes))
    33   	vmxData["remotedisplay.vnc.enabled"] = "TRUE"
    34   	vmxData["remotedisplay.vnc.port"] = fmt.Sprintf("%d", vncPort)
    35  +	vmxData["remotedisplay.vnc.password"] = vncPassword
    36   
    37   	if err := WriteVMX(vmxPath, vmxData); err != nil {
    38   		err := fmt.Errorf("Error writing VMX data: %s", err)
    39  @@ -102,6 +119,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
    40   
    41   	state.Put("vnc_port", vncPort)
    42   	state.Put("vnc_ip", vncIp)
    43  +	state.Put("vnc_password", vncPassword)
    44   
    45   	return multistep.ActionContinue
    46   }