Allow configurable VNC bind IP for VirtualBox builders
Signed-off-by: Ian Duffy <ian@ianduffy.ie>
This commit is contained in:
parent
873760e69e
commit
9ec319e296
|
@ -11,6 +11,7 @@ type RunConfig struct {
|
||||||
Headless bool `mapstructure:"headless"`
|
Headless bool `mapstructure:"headless"`
|
||||||
RawBootWait string `mapstructure:"boot_wait"`
|
RawBootWait string `mapstructure:"boot_wait"`
|
||||||
|
|
||||||
|
VRDPBindAddress string `mapstructure:"vrdp_bind_address"`
|
||||||
VRDPPortMin uint `mapstructure:"vrdp_port_min"`
|
VRDPPortMin uint `mapstructure:"vrdp_port_min"`
|
||||||
VRDPPortMax uint `mapstructure:"vrdp_port_max"`
|
VRDPPortMax uint `mapstructure:"vrdp_port_max"`
|
||||||
|
|
||||||
|
@ -22,6 +23,10 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
c.RawBootWait = "10s"
|
c.RawBootWait = "10s"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.VRDPBindAddress == "" {
|
||||||
|
c.VRDPBindAddress = "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
if c.VRDPPortMin == 0 {
|
if c.VRDPPortMin == 0 {
|
||||||
c.VRDPPortMin = 5900
|
c.VRDPPortMin = 5900
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,3 +35,27 @@ func TestRunConfigPrepare_BootWait(t *testing.T) {
|
||||||
t.Fatalf("should not have error: %s", errs)
|
t.Fatalf("should not have error: %s", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunConfigPrepare_VRDPBindAddress(t *testing.T) {
|
||||||
|
var c *RunConfig
|
||||||
|
var errs []error
|
||||||
|
|
||||||
|
// Test a default VRDPBindAddress
|
||||||
|
c = new(RunConfig)
|
||||||
|
errs = c.Prepare(testConfigTemplate(t))
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatalf("should not have error: %s", errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.VRDPBindAddress != "127.0.0.1" {
|
||||||
|
t.Fatalf("bad value: %s", c.VRDPBindAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test with a good one
|
||||||
|
c = new(RunConfig)
|
||||||
|
c.VRDPBindAddress = "192.168.0.1"
|
||||||
|
errs = c.Prepare(testConfigTemplate(t))
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatalf("should not have error: %s", errs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
// Produces:
|
// Produces:
|
||||||
// vrdp_port unit - The port that VRDP is configured to listen on.
|
// vrdp_port unit - The port that VRDP is configured to listen on.
|
||||||
type StepConfigureVRDP struct {
|
type StepConfigureVRDP struct {
|
||||||
|
VRDPBindAddress string
|
||||||
VRDPPortMin uint
|
VRDPPortMin uint
|
||||||
VRDPPortMax uint
|
VRDPPortMax uint
|
||||||
}
|
}
|
||||||
|
@ -30,7 +31,7 @@ func (s *StepConfigureVRDP) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
vmName := state.Get("vmName").(string)
|
vmName := state.Get("vmName").(string)
|
||||||
|
|
||||||
log.Printf("Looking for available port between %d and %d", s.VRDPPortMin, s.VRDPPortMax)
|
log.Printf("Looking for available port between %d and %d on %s", s.VRDPPortMin, s.VRDPPortMax, s.VRDPBindAddress)
|
||||||
var vrdpPort uint
|
var vrdpPort uint
|
||||||
portRange := int(s.VRDPPortMax - s.VRDPPortMin)
|
portRange := int(s.VRDPPortMax - s.VRDPPortMin)
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ func (s *StepConfigureVRDP) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Trying port: %d", vrdpPort)
|
log.Printf("Trying port: %d", vrdpPort)
|
||||||
l, err := net.Listen("tcp", fmt.Sprintf(":%d", vrdpPort))
|
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.VRDPBindAddress, vrdpPort))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
break
|
break
|
||||||
|
@ -51,7 +52,7 @@ func (s *StepConfigureVRDP) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
command := []string{
|
command := []string{
|
||||||
"modifyvm", vmName,
|
"modifyvm", vmName,
|
||||||
"--vrdeaddress", "127.0.0.1",
|
"--vrdeaddress", fmt.Sprintf("%s", s.VRDPBindAddress),
|
||||||
"--vrdeauthtype", "null",
|
"--vrdeauthtype", "null",
|
||||||
"--vrde", "on",
|
"--vrde", "on",
|
||||||
"--vrdeport",
|
"--vrdeport",
|
||||||
|
@ -64,7 +65,7 @@ func (s *StepConfigureVRDP) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
state.Put("vrdpIp", "127.0.0.1")
|
state.Put("vrdpIp", s.VRDPBindAddress)
|
||||||
state.Put("vrdpPort", vrdpPort)
|
state.Put("vrdpPort", vrdpPort)
|
||||||
|
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
|
|
|
@ -209,6 +209,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
||||||
},
|
},
|
||||||
&vboxcommon.StepConfigureVRDP{
|
&vboxcommon.StepConfigureVRDP{
|
||||||
|
VRDPBindAddress: b.config.VRDPBindAddress,
|
||||||
VRDPPortMin: b.config.VRDPPortMin,
|
VRDPPortMin: b.config.VRDPPortMin,
|
||||||
VRDPPortMax: b.config.VRDPPortMax,
|
VRDPPortMax: b.config.VRDPPortMax,
|
||||||
},
|
},
|
||||||
|
|
|
@ -78,6 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
GuestAdditionsMode: b.config.GuestAdditionsMode,
|
||||||
},
|
},
|
||||||
&vboxcommon.StepConfigureVRDP{
|
&vboxcommon.StepConfigureVRDP{
|
||||||
|
VRDPBindAddress: b.config.VRDPBindAddress,
|
||||||
VRDPPortMin: b.config.VRDPPortMin,
|
VRDPPortMin: b.config.VRDPPortMin,
|
||||||
VRDPPortMax: b.config.VRDPPortMax,
|
VRDPPortMax: b.config.VRDPPortMax,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue