use port as ints
This commit is contained in:
parent
f828b72c10
commit
5a6dffde9a
|
@ -37,7 +37,7 @@ type Config struct {
|
|||
Network string `mapstructure:"network"`
|
||||
Project string `mapstructure:"project"`
|
||||
PublicIPAddress string `mapstructure:"public_ip_address"`
|
||||
PublicPort uint `mapstructure:"public_port"`
|
||||
PublicPort int `mapstructure:"public_port"`
|
||||
SecurityGroups []string `mapstructure:"security_groups"`
|
||||
ServiceOffering string `mapstructure:"service_offering"`
|
||||
PreventFirewallChanges bool `mapstructure:"prevent_firewall_changes"`
|
||||
|
|
|
@ -15,8 +15,8 @@ func commHost(state multistep.StateBag) (string, error) {
|
|||
return ip, nil
|
||||
}
|
||||
|
||||
func commPort(state multistep.StateBag) (uint, error) {
|
||||
commPort, hasPort := state.Get("commPort").(uint)
|
||||
func commPort(state multistep.StateBag) (int, error) {
|
||||
commPort, hasPort := state.Get("commPort").(int)
|
||||
if !hasPort {
|
||||
return 0, fmt.Errorf("Failed to retrieve communication port")
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
)
|
||||
|
||||
type stepSetupNetworking struct {
|
||||
privatePort uint
|
||||
publicPort uint
|
||||
privatePort int
|
||||
publicPort int
|
||||
}
|
||||
|
||||
func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -36,7 +36,7 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
|||
} else {
|
||||
// Generate a random public port used to configure our port forward.
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
s.publicPort = uint(50000 + rand.Intn(10000))
|
||||
s.publicPort = 50000 + rand.Intn(10000)
|
||||
}
|
||||
state.Put("commPort", s.publicPort)
|
||||
|
||||
|
@ -99,9 +99,9 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
|||
ui.Message("Creating port forward...")
|
||||
p := client.Firewall.NewCreatePortForwardingRuleParams(
|
||||
config.PublicIPAddress,
|
||||
int(s.privatePort),
|
||||
s.privatePort,
|
||||
"TCP",
|
||||
int(s.publicPort),
|
||||
s.publicPort,
|
||||
instanceID,
|
||||
)
|
||||
|
||||
|
@ -143,8 +143,8 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
|||
p.SetAclid(network.Aclid)
|
||||
p.SetAction("allow")
|
||||
p.SetCidrlist(config.CIDRList)
|
||||
p.SetStartport(int(s.privatePort))
|
||||
p.SetEndport(int(s.privatePort))
|
||||
p.SetStartport(s.privatePort)
|
||||
p.SetEndport(s.privatePort)
|
||||
p.SetTraffictype("ingress")
|
||||
|
||||
// Create the network ACL rule.
|
||||
|
@ -166,8 +166,8 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
|||
|
||||
// Configure the firewall rule.
|
||||
p.SetCidrlist(config.CIDRList)
|
||||
p.SetStartport(int(s.publicPort))
|
||||
p.SetEndport(int(s.publicPort))
|
||||
p.SetStartport(s.publicPort)
|
||||
p.SetEndport(s.publicPort)
|
||||
|
||||
fwRule, err := client.Firewall.CreateFirewallRule(p)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
// userDataTemplateData represents variables for user_data interpolation
|
||||
type userDataTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
}
|
||||
|
||||
// stepCreateInstance represents a Packer build step that creates CloudStack instances.
|
||||
|
@ -86,7 +86,7 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
|
|||
}
|
||||
|
||||
if config.UserData != "" {
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
httpIP, err := hostIP()
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Failed to determine host IP: %s", err)
|
||||
|
|
|
@ -54,8 +54,8 @@ func (s *stepCreateSecurityGroup) Run(_ context.Context, state multistep.StateBa
|
|||
i.SetCidrlist(config.CIDRList)
|
||||
i.SetProtocol("TCP")
|
||||
i.SetSecuritygroupid(sg.Id)
|
||||
i.SetStartport(int(config.Comm.Port()))
|
||||
i.SetEndport(int(config.Comm.Port()))
|
||||
i.SetStartport(config.Comm.Port())
|
||||
i.SetEndport(config.Comm.Port())
|
||||
if config.Project != "" {
|
||||
i.SetProjectid(config.Project)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
type bootCommandTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
Name string
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ type StepTypeBootCommand struct {
|
|||
}
|
||||
|
||||
func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
|
|
@ -610,7 +610,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
|
|||
state.Put("config", &b.config)
|
||||
state.Put("driver", driver)
|
||||
state.Put("hook", hook)
|
||||
state.Put("http_port", uint(0))
|
||||
state.Put("http_port", 0)
|
||||
state.Put("ui", ui)
|
||||
state.Put("vmName", "packer-foo")
|
||||
|
||||
|
|
|
@ -511,7 +511,7 @@ func TestUserVariablesInBootCommand(t *testing.T) {
|
|||
state.Put("config", &b.config)
|
||||
state.Put("driver", driver)
|
||||
state.Put("hook", hook)
|
||||
state.Put("http_port", uint(0))
|
||||
state.Put("http_port", 0)
|
||||
state.Put("ui", ui)
|
||||
state.Put("vmName", "packer-foo")
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
type bootCommandTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
Name string
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ type StepTypeBootCommand struct {
|
|||
// Run types the boot command by sending key scancodes into the VM.
|
||||
func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
debug := state.Get("debug").(bool)
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
|||
state.Put("driver", driver)
|
||||
state.Put("hook", hook)
|
||||
state.Put("ui", ui)
|
||||
state.Put("http_port", uint(0))
|
||||
state.Put("http_port", 0)
|
||||
|
||||
// Build the steps.
|
||||
steps := []multistep.Step{
|
||||
|
|
|
@ -116,12 +116,12 @@ type Config struct {
|
|||
QemuArgs [][]string `mapstructure:"qemuargs"`
|
||||
QemuBinary string `mapstructure:"qemu_binary"`
|
||||
ShutdownCommand string `mapstructure:"shutdown_command"`
|
||||
SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
|
||||
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
|
||||
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
|
||||
SSHHostPortMax int `mapstructure:"ssh_host_port_max"`
|
||||
UseDefaultDisplay bool `mapstructure:"use_default_display"`
|
||||
VNCBindAddress string `mapstructure:"vnc_bind_address"`
|
||||
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
||||
VNCPortMax uint `mapstructure:"vnc_port_max"`
|
||||
VNCPortMin int `mapstructure:"vnc_port_min"`
|
||||
VNCPortMax int `mapstructure:"vnc_port_max"`
|
||||
VMName string `mapstructure:"vm_name"`
|
||||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
|
|
|
@ -8,7 +8,7 @@ func commHost(state multistep.StateBag) (string, error) {
|
|||
return "127.0.0.1", nil
|
||||
}
|
||||
|
||||
func commPort(state multistep.StateBag) (uint, error) {
|
||||
sshHostPort := state.Get("sshHostPort").(uint)
|
||||
return sshHostPort, nil
|
||||
func commPort(state multistep.StateBag) (int, error) {
|
||||
sshHostPort := state.Get("sshHostPort").(int)
|
||||
return int(sshHostPort), nil
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
// ui packer.Ui
|
||||
//
|
||||
// Produces:
|
||||
// vnc_port uint - The port that VNC is configured to listen on.
|
||||
// vnc_port int - The port that VNC is configured to listen on.
|
||||
type stepConfigureVNC struct {
|
||||
l *net.Listener
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ type stepRun struct {
|
|||
|
||||
type qemuArgsTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
HTTPDir string
|
||||
OutputDir string
|
||||
Name string
|
||||
SSHHostPort uint
|
||||
SSHHostPort int
|
||||
}
|
||||
|
||||
func (s *stepRun) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -63,7 +63,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
config := state.Get("config").(*Config)
|
||||
isoPath := state.Get("iso_path").(string)
|
||||
vncIP := state.Get("vnc_ip").(string)
|
||||
vncPort := state.Get("vnc_port").(uint)
|
||||
vncPort := state.Get("vnc_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
driver := state.Get("driver").(Driver)
|
||||
|
||||
|
@ -74,12 +74,12 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
defaultArgs := make(map[string]interface{})
|
||||
var deviceArgs []string
|
||||
var driveArgs []string
|
||||
var sshHostPort uint
|
||||
var sshHostPort int
|
||||
|
||||
defaultArgs["-name"] = vmName
|
||||
defaultArgs["-machine"] = fmt.Sprintf("type=%s", config.MachineType)
|
||||
if config.Comm.Type != "none" {
|
||||
sshHostPort = state.Get("sshHostPort").(uint)
|
||||
sshHostPort = state.Get("sshHostPort").(int)
|
||||
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0,hostfwd=tcp::%v-:%d", sshHostPort, config.Comm.Port())
|
||||
} else {
|
||||
defaultArgs["-netdev"] = fmt.Sprintf("user,id=user.0")
|
||||
|
@ -121,7 +121,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
|
||||
if vncIpOk && vncPortOk {
|
||||
vncIp := vncIpRaw.(string)
|
||||
vncPort := vncPortRaw.(uint)
|
||||
vncPort := vncPortRaw.(int)
|
||||
|
||||
ui.Message(fmt.Sprintf(
|
||||
"The VM will be run headless, without a GUI. If you want to\n"+
|
||||
|
@ -175,7 +175,7 @@ func getCommandArgs(bootDrive string, state multistep.StateBag) ([]string, error
|
|||
if len(config.QemuArgs) > 0 {
|
||||
ui.Say("Overriding defaults Qemu arguments with QemuArgs...")
|
||||
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ctx := config.ctx
|
||||
if config.Comm.Type != "none" {
|
||||
ctx.Data = qemuArgsTemplateData{
|
||||
|
|
|
@ -19,7 +19,7 @@ const KeyLeftShift uint32 = 0xFFE1
|
|||
|
||||
type bootCommandTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
Name string
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ type bootCommandTemplateData struct {
|
|||
// config *config
|
||||
// http_port int
|
||||
// ui packer.Ui
|
||||
// vnc_port uint
|
||||
// vnc_port int
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
|
@ -38,9 +38,9 @@ type stepTypeBootCommand struct{}
|
|||
func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("config").(*Config)
|
||||
debug := state.Get("debug").(bool)
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vncPort := state.Get("vnc_port").(uint)
|
||||
vncPort := state.Get("vnc_port").(int)
|
||||
vncIP := state.Get("vnc_ip").(string)
|
||||
|
||||
if config.VNCConfig.DisableVNC {
|
||||
|
|
|
@ -11,8 +11,8 @@ func CommHost() func(multistep.StateBag) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func SSHPort() func(multistep.StateBag) (uint, error) {
|
||||
return func(state multistep.StateBag) (uint, error) {
|
||||
func SSHPort() func(multistep.StateBag) (int, error) {
|
||||
return func(state multistep.StateBag) (int, error) {
|
||||
config := state.Get("config").(*Config)
|
||||
return config.Comm.SSHPort, nil
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func (s *StepSSHConfig) Run(_ context.Context, state multistep.StateBag) multist
|
|||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
config.Comm.SSHPort = uint(port)
|
||||
config.Comm.SSHPort = port
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ type RunConfig struct {
|
|||
Headless bool `mapstructure:"headless"`
|
||||
|
||||
VRDPBindAddress string `mapstructure:"vrdp_bind_address"`
|
||||
VRDPPortMin uint `mapstructure:"vrdp_port_min"`
|
||||
VRDPPortMax uint `mapstructure:"vrdp_port_max"`
|
||||
VRDPPortMin int `mapstructure:"vrdp_port_min"`
|
||||
VRDPPortMax int `mapstructure:"vrdp_port_max"`
|
||||
}
|
||||
|
||||
func (c *RunConfig) Prepare(ctx *interpolate.Context) (errs []error) {
|
||||
|
|
|
@ -10,7 +10,7 @@ func CommHost(host string) func(multistep.StateBag) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func SSHPort(state multistep.StateBag) (uint, error) {
|
||||
sshHostPort := state.Get("sshHostPort").(uint)
|
||||
func SSHPort(state multistep.StateBag) (int, error) {
|
||||
sshHostPort := state.Get("sshHostPort").(int)
|
||||
return sshHostPort, nil
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ import (
|
|||
type SSHConfig struct {
|
||||
Comm communicator.Config `mapstructure:",squash"`
|
||||
|
||||
SSHHostPortMin uint `mapstructure:"ssh_host_port_min"`
|
||||
SSHHostPortMax uint `mapstructure:"ssh_host_port_max"`
|
||||
SSHHostPortMin int `mapstructure:"ssh_host_port_min"`
|
||||
SSHHostPortMax int `mapstructure:"ssh_host_port_max"`
|
||||
SSHSkipNatMapping bool `mapstructure:"ssh_skip_nat_mapping"`
|
||||
|
||||
// These are deprecated, but we keep them around for BC
|
||||
|
|
|
@ -22,8 +22,8 @@ import (
|
|||
// vrdp_port unit - The port that VRDP is configured to listen on.
|
||||
type StepConfigureVRDP struct {
|
||||
VRDPBindAddress string
|
||||
VRDPPortMin uint
|
||||
VRDPPortMax uint
|
||||
VRDPPortMin int
|
||||
VRDPPortMax int
|
||||
|
||||
l *net.Listener
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ import (
|
|||
// Produces:
|
||||
type StepForwardSSH struct {
|
||||
CommConfig *communicator.Config
|
||||
HostPortMin uint
|
||||
HostPortMax uint
|
||||
HostPortMin int
|
||||
HostPortMax int
|
||||
SkipNatMapping bool
|
||||
|
||||
l *net.Listener
|
||||
|
@ -40,7 +40,7 @@ func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
guestPort := uint(s.CommConfig.Port())
|
||||
guestPort := s.CommConfig.Port()
|
||||
sshHostPort := guestPort
|
||||
if !s.SkipNatMapping {
|
||||
log.Printf("Looking for available communicator (SSH, WinRM, etc) port between %d and %d",
|
||||
|
|
|
@ -35,7 +35,7 @@ func (s *StepRun) Run(_ context.Context, state multistep.StateBag) multistep.Ste
|
|||
|
||||
if vrdpIpOk && vrdpPortOk {
|
||||
vrdpIp := vrdpIpRaw.(string)
|
||||
vrdpPort := vrdpPortRaw.(uint)
|
||||
vrdpPort := vrdpPortRaw.(int)
|
||||
|
||||
ui.Message(fmt.Sprintf(
|
||||
"The VM will be run headless, without a GUI. If you want to\n"+
|
||||
|
|
|
@ -22,7 +22,7 @@ type bootCommandTemplateData struct {
|
|||
HTTPIP string
|
||||
|
||||
// HTTPPort is the HTTP server port.
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
|
||||
// Name is the VM's name.
|
||||
Name string
|
||||
|
@ -43,7 +43,7 @@ type StepTypeBootCommand struct {
|
|||
func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
debug := state.Get("debug").(bool)
|
||||
driver := state.Get("driver").(Driver)
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ type DriverConfig struct {
|
|||
RemoteCacheDatastore string `mapstructure:"remote_cache_datastore"`
|
||||
RemoteCacheDirectory string `mapstructure:"remote_cache_directory"`
|
||||
RemoteHost string `mapstructure:"remote_host"`
|
||||
RemotePort uint `mapstructure:"remote_port"`
|
||||
RemotePort int `mapstructure:"remote_port"`
|
||||
RemoteUser string `mapstructure:"remote_username"`
|
||||
RemotePassword string `mapstructure:"remote_password"`
|
||||
RemotePrivateKey string `mapstructure:"remote_private_key_file"`
|
||||
|
|
|
@ -31,7 +31,7 @@ type ESX5Driver struct {
|
|||
base VmwareDriver
|
||||
|
||||
Host string
|
||||
Port uint
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
PrivateKeyFile string
|
||||
|
@ -360,8 +360,8 @@ func (d *ESX5Driver) GuestAddress(multistep.StateBag) (string, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (d *ESX5Driver) VNCAddress(ctx context.Context, _ string, portMin, portMax uint) (string, uint, error) {
|
||||
var vncPort uint
|
||||
func (d *ESX5Driver) VNCAddress(ctx context.Context, _ string, portMin, portMax int) (string, int, error) {
|
||||
var vncPort int
|
||||
|
||||
//Process ports ESXi is listening on to determine which are available
|
||||
//This process does best effort to detect ports that are unavailable,
|
||||
|
@ -427,7 +427,7 @@ func (d *ESX5Driver) VNCAddress(ctx context.Context, _ string, portMin, portMax
|
|||
}
|
||||
|
||||
// UpdateVMX, adds the VNC port to the VMX data.
|
||||
func (ESX5Driver) UpdateVMX(_, password string, port uint, data map[string]string) {
|
||||
func (ESX5Driver) UpdateVMX(_, password string, port int, data map[string]string) {
|
||||
// Do not set remotedisplay.vnc.ip - this breaks ESXi.
|
||||
data["remotedisplay.vnc.enabled"] = "TRUE"
|
||||
data["remotedisplay.vnc.port"] = fmt.Sprintf("%d", port)
|
||||
|
|
|
@ -50,7 +50,7 @@ func TestESX5Driver_HostIP(t *testing.T) {
|
|||
port := listen.Addr().(*net.TCPAddr).Port
|
||||
defer listen.Close()
|
||||
|
||||
driver := ESX5Driver{Host: "localhost", Port: uint(port)}
|
||||
driver := ESX5Driver{Host: "localhost", Port: port}
|
||||
state := new(multistep.BasicStateBag)
|
||||
|
||||
if host, _ := driver.HostIP(state); host != expected_host {
|
||||
|
|
|
@ -10,8 +10,8 @@ type RunConfig struct {
|
|||
Headless bool `mapstructure:"headless"`
|
||||
|
||||
VNCBindAddress string `mapstructure:"vnc_bind_address"`
|
||||
VNCPortMin uint `mapstructure:"vnc_port_min"`
|
||||
VNCPortMax uint `mapstructure:"vnc_port_max"`
|
||||
VNCPortMin int `mapstructure:"vnc_port_min"`
|
||||
VNCPortMax int `mapstructure:"vnc_port_max"`
|
||||
VNCDisablePassword bool `mapstructure:"vnc_disable_password"`
|
||||
}
|
||||
|
||||
|
|
|
@ -18,25 +18,25 @@ import (
|
|||
// vmx_path string
|
||||
//
|
||||
// Produces:
|
||||
// vnc_port uint - The port that VNC is configured to listen on.
|
||||
// vnc_port int - The port that VNC is configured to listen on.
|
||||
type StepConfigureVNC struct {
|
||||
Enabled bool
|
||||
VNCBindAddress string
|
||||
VNCPortMin uint
|
||||
VNCPortMax uint
|
||||
VNCPortMin int
|
||||
VNCPortMax int
|
||||
VNCDisablePassword bool
|
||||
|
||||
l *net.Listener
|
||||
}
|
||||
|
||||
type VNCAddressFinder interface {
|
||||
VNCAddress(context.Context, string, uint, uint) (string, uint, error)
|
||||
VNCAddress(context.Context, string, int, int) (string, int, error)
|
||||
|
||||
// UpdateVMX, sets driver specific VNC values to VMX data.
|
||||
UpdateVMX(vncAddress, vncPassword string, vncPort uint, vmxData map[string]string)
|
||||
UpdateVMX(vncAddress, vncPassword string, vncPort int, vmxData map[string]string)
|
||||
}
|
||||
|
||||
func (s *StepConfigureVNC) VNCAddress(ctx context.Context, vncBindAddress string, portMin, portMax uint) (string, uint, error) {
|
||||
func (s *StepConfigureVNC) VNCAddress(ctx context.Context, vncBindAddress string, portMin, portMax int) (string, int, error) {
|
||||
var err error
|
||||
s.l, err = net.ListenRangeConfig{
|
||||
Addr: s.VNCBindAddress,
|
||||
|
@ -125,7 +125,7 @@ func (s *StepConfigureVNC) Run(ctx context.Context, state multistep.StateBag) mu
|
|||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (StepConfigureVNC) UpdateVMX(address, password string, port uint, data map[string]string) {
|
||||
func (*StepConfigureVNC) UpdateVMX(address, password string, port int, data map[string]string) {
|
||||
data["remotedisplay.vnc.enabled"] = "TRUE"
|
||||
data["remotedisplay.vnc.port"] = fmt.Sprintf("%d", port)
|
||||
data["remotedisplay.vnc.ip"] = address
|
||||
|
|
|
@ -43,7 +43,7 @@ func (s *StepRun) Run(_ context.Context, state multistep.StateBag) multistep.Ste
|
|||
|
||||
if vncIpOk && vncPortOk && vncPasswordOk {
|
||||
vncIp := vncIpRaw.(string)
|
||||
vncPort := vncPortRaw.(uint)
|
||||
vncPort := vncPortRaw.(int)
|
||||
vncPassword := vncPasswordRaw.(string)
|
||||
|
||||
ui.Message(fmt.Sprintf(
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
// Uses:
|
||||
// http_port int
|
||||
// ui packer.Ui
|
||||
// vnc_port uint
|
||||
// vnc_port int
|
||||
//
|
||||
// Produces:
|
||||
// <nothing>
|
||||
|
@ -34,7 +34,7 @@ type StepTypeBootCommand struct {
|
|||
}
|
||||
type bootCommandTemplateData struct {
|
||||
HTTPIP string
|
||||
HTTPPort uint
|
||||
HTTPPort int
|
||||
Name string
|
||||
}
|
||||
|
||||
|
@ -46,10 +46,10 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag)
|
|||
|
||||
debug := state.Get("debug").(bool)
|
||||
driver := state.Get("driver").(Driver)
|
||||
httpPort := state.Get("http_port").(uint)
|
||||
httpPort := state.Get("http_port").(int)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vncIp := state.Get("vnc_ip").(string)
|
||||
vncPort := state.Get("vnc_port").(uint)
|
||||
vncPort := state.Get("vnc_port").(int)
|
||||
vncPassword := state.Get("vnc_password")
|
||||
|
||||
// Wait the for the vm to boot.
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
// HTTPConfig contains configuration for the local HTTP Server
|
||||
type HTTPConfig struct {
|
||||
HTTPDir string `mapstructure:"http_directory"`
|
||||
HTTPPortMin uint `mapstructure:"http_port_min"`
|
||||
HTTPPortMax uint `mapstructure:"http_port_max"`
|
||||
HTTPPortMin int `mapstructure:"http_port_min"`
|
||||
HTTPPortMax int `mapstructure:"http_port_max"`
|
||||
}
|
||||
|
||||
func (c *HTTPConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
|
|
|
@ -24,11 +24,11 @@ func TestHTTPConfigPrepare_Bounds(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
portMin := uint(8000)
|
||||
portMin := 8000
|
||||
if h.HTTPPortMin != portMin {
|
||||
t.Fatalf("HTTPPortMin: expected %d got %d", portMin, h.HTTPPortMin)
|
||||
}
|
||||
portMax := uint(9000)
|
||||
portMax := 9000
|
||||
if h.HTTPPortMax != portMax {
|
||||
t.Fatalf("HTTPPortMax: expected %d got %d", portMax, h.HTTPPortMax)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofrs/flock"
|
||||
|
||||
|
@ -24,7 +25,7 @@ type Listener struct {
|
|||
// Listener can be closed but Port will be file locked by packer until
|
||||
// Close is called.
|
||||
net.Listener
|
||||
Port uint
|
||||
Port int
|
||||
Address string
|
||||
lock *flock.Flock
|
||||
}
|
||||
|
@ -43,7 +44,7 @@ type ListenRangeConfig struct {
|
|||
// tcp", "udp"
|
||||
Network string
|
||||
Addr string
|
||||
Min, Max uint
|
||||
Min, Max int
|
||||
net.ListenConfig
|
||||
}
|
||||
|
||||
|
@ -64,9 +65,9 @@ func (lc ListenRangeConfig) Listen(ctx context.Context) (*Listener, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
port := uint(rand.Intn(portRange)) + lc.Min
|
||||
port := rand.Intn(portRange) + lc.Min
|
||||
|
||||
lockFilePath, err := packer.CachePath("port", fmt.Sprintf("%d", port))
|
||||
lockFilePath, err := packer.CachePath("port", strconv.Itoa(port))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ import (
|
|||
// http_port int - The port the HTTP server started on.
|
||||
type StepHTTPServer struct {
|
||||
HTTPDir string
|
||||
HTTPPortMin uint
|
||||
HTTPPortMax uint
|
||||
HTTPPortMin int
|
||||
HTTPPortMax int
|
||||
|
||||
l *net.Listener
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) mult
|
|||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if s.HTTPDir == "" {
|
||||
state.Put("http_port", uint(0))
|
||||
state.Put("http_port", 0)
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ type Communicator struct {
|
|||
func New(config *Config) (*Communicator, error) {
|
||||
endpoint := &winrm.Endpoint{
|
||||
Host: config.Host,
|
||||
Port: int(config.Port), // it's a uint
|
||||
Port: config.Port,
|
||||
HTTPS: config.Https,
|
||||
Insecure: config.Insecure,
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
// Config is used to configure the WinRM connection
|
||||
type Config struct {
|
||||
Host string
|
||||
Port uint
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
Timeout time.Duration
|
||||
|
|
|
@ -24,8 +24,8 @@ const PACKERSPACE = "-PACKERSPACE-"
|
|||
type config struct {
|
||||
DisableCheckpoint bool `json:"disable_checkpoint"`
|
||||
DisableCheckpointSignature bool `json:"disable_checkpoint_signature"`
|
||||
PluginMinPort uint
|
||||
PluginMaxPort uint
|
||||
PluginMinPort int
|
||||
PluginMaxPort int
|
||||
|
||||
Builders map[string]string
|
||||
PostProcessors map[string]string `json:"post-processors"`
|
||||
|
|
|
@ -25,7 +25,7 @@ type Config struct {
|
|||
|
||||
// SSH
|
||||
SSHHost string `mapstructure:"ssh_host"`
|
||||
SSHPort uint `mapstructure:"ssh_port"`
|
||||
SSHPort int `mapstructure:"ssh_port"`
|
||||
SSHUsername string `mapstructure:"ssh_username"`
|
||||
SSHPassword string `mapstructure:"ssh_password"`
|
||||
SSHKeyPairName string `mapstructure:"ssh_keypair_name"`
|
||||
|
@ -60,7 +60,7 @@ type Config struct {
|
|||
WinRMUser string `mapstructure:"winrm_username"`
|
||||
WinRMPassword string `mapstructure:"winrm_password"`
|
||||
WinRMHost string `mapstructure:"winrm_host"`
|
||||
WinRMPort uint `mapstructure:"winrm_port"`
|
||||
WinRMPort int `mapstructure:"winrm_port"`
|
||||
WinRMTimeout time.Duration `mapstructure:"winrm_timeout"`
|
||||
WinRMUseSSL bool `mapstructure:"winrm_use_ssl"`
|
||||
WinRMInsecure bool `mapstructure:"winrm_insecure"`
|
||||
|
@ -150,7 +150,7 @@ func (c *Config) SSHConfigFunc() func(multistep.StateBag) (*ssh.ClientConfig, er
|
|||
}
|
||||
|
||||
// Port returns the port that will be used for access based on config.
|
||||
func (c *Config) Port() uint {
|
||||
func (c *Config) Port() int {
|
||||
switch c.Type {
|
||||
case "ssh":
|
||||
return c.SSHPort
|
||||
|
|
|
@ -28,14 +28,14 @@ type StepConnect struct {
|
|||
// SSHConfig should return the default configuration for
|
||||
// connecting via SSH.
|
||||
SSHConfig func(multistep.StateBag) (*gossh.ClientConfig, error)
|
||||
SSHPort func(multistep.StateBag) (uint, error)
|
||||
SSHPort func(multistep.StateBag) (int, error)
|
||||
|
||||
// The fields below are callbacks to assist with connecting to WinRM.
|
||||
//
|
||||
// WinRMConfig should return the default configuration for
|
||||
// connecting via WinRM.
|
||||
WinRMConfig func(multistep.StateBag) (*WinRMConfig, error)
|
||||
WinRMPort func(multistep.StateBag) (uint, error)
|
||||
WinRMPort func(multistep.StateBag) (int, error)
|
||||
|
||||
// CustomConnect can be set to have custom connectors for specific
|
||||
// types. These take highest precedence so you can also override
|
||||
|
|
|
@ -27,7 +27,7 @@ type StepConnectSSH struct {
|
|||
Config *Config
|
||||
Host func(multistep.StateBag) (string, error)
|
||||
SSHConfig func(multistep.StateBag) (*gossh.ClientConfig, error)
|
||||
SSHPort func(multistep.StateBag) (uint, error)
|
||||
SSHPort func(multistep.StateBag) (int, error)
|
||||
}
|
||||
|
||||
func (s *StepConnectSSH) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
|
|
@ -30,7 +30,7 @@ type StepConnectWinRM struct {
|
|||
Config *Config
|
||||
Host func(multistep.StateBag) (string, error)
|
||||
WinRMConfig func(multistep.StateBag) (*WinRMConfig, error)
|
||||
WinRMPort func(multistep.StateBag) (uint, error)
|
||||
WinRMPort func(multistep.StateBag) (int, error)
|
||||
}
|
||||
|
||||
func (s *StepConnectWinRM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
|
|
@ -56,7 +56,7 @@ type ClientConfig struct {
|
|||
// The minimum and maximum port to use for communicating with
|
||||
// the subprocess. If not set, this defaults to 10,000 and 25,000
|
||||
// respectively.
|
||||
MinPort, MaxPort uint
|
||||
MinPort, MaxPort int
|
||||
|
||||
// StartTimeout is the timeout to wait for the plugin to say it
|
||||
// has started successfully.
|
||||
|
|
|
@ -52,7 +52,7 @@ type Config struct {
|
|||
EmptyGroups []string `mapstructure:"empty_groups"`
|
||||
HostAlias string `mapstructure:"host_alias"`
|
||||
User string `mapstructure:"user"`
|
||||
LocalPort uint `mapstructure:"local_port"`
|
||||
LocalPort int `mapstructure:"local_port"`
|
||||
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
|
||||
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
|
||||
SFTPCmd string `mapstructure:"sftp_command"`
|
||||
|
@ -271,12 +271,11 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
ui.Say(err.Error())
|
||||
continue
|
||||
}
|
||||
portUint64, err := strconv.ParseUint(portStr, 10, 0)
|
||||
p.config.LocalPort, err = strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
ui.Say(err.Error())
|
||||
continue
|
||||
}
|
||||
p.config.LocalPort = uint(portUint64)
|
||||
return l, nil
|
||||
}
|
||||
return nil, errors.New("Error setting up SSH proxy connection")
|
||||
|
|
|
@ -245,13 +245,13 @@ func TestProvisionerPrepare_LocalPort(t *testing.T) {
|
|||
config["ssh_authorized_key_file"] = publickey_file.Name()
|
||||
config["playbook_file"] = playbook_file.Name()
|
||||
|
||||
config["local_port"] = uint(65537)
|
||||
config["local_port"] = 65537
|
||||
err = p.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
||||
config["local_port"] = uint(22222)
|
||||
config["local_port"] = 22222
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
|
@ -52,7 +52,7 @@ type Config struct {
|
|||
Backend string `mapstructure:"backend"`
|
||||
User string `mapstructure:"user"`
|
||||
Host string `mapstructure:"host"`
|
||||
LocalPort uint `mapstructure:"local_port"`
|
||||
LocalPort int `mapstructure:"local_port"`
|
||||
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
|
||||
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
|
||||
}
|
||||
|
@ -264,12 +264,11 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
ui.Say(err.Error())
|
||||
continue
|
||||
}
|
||||
portUint64, err := strconv.ParseUint(portStr, 10, 0)
|
||||
p.config.LocalPort, err = strconv.Atoi(portStr)
|
||||
if err != nil {
|
||||
ui.Say(err.Error())
|
||||
continue
|
||||
}
|
||||
p.config.LocalPort = uint(portUint64)
|
||||
return l, nil
|
||||
}
|
||||
return nil, errors.New("Error setting up SSH proxy connection")
|
||||
|
@ -338,7 +337,7 @@ func (p *Provisioner) executeInspec(ui packer.Ui, comm packer.Communicator, priv
|
|||
args = append(args, "--key-files", privKeyFile)
|
||||
}
|
||||
args = append(args, "--user", p.config.User)
|
||||
args = append(args, "--port", strconv.FormatUint(uint64(p.config.LocalPort), 10))
|
||||
args = append(args, "--port", strconv.Itoa(p.config.LocalPort))
|
||||
}
|
||||
|
||||
args = append(args, "--attrs")
|
||||
|
|
|
@ -254,13 +254,13 @@ func TestProvisionerPrepare_LocalPort(t *testing.T) {
|
|||
config["ssh_authorized_key_file"] = publickey_file.Name()
|
||||
config["profile"] = profile_file.Name()
|
||||
|
||||
config["local_port"] = uint(65537)
|
||||
config["local_port"] = 65537
|
||||
err = p.Prepare(config)
|
||||
if err == nil {
|
||||
t.Fatal("should have error")
|
||||
}
|
||||
|
||||
config["local_port"] = uint(22222)
|
||||
config["local_port"] = 22222
|
||||
err = p.Prepare(config)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
|
|
Loading…
Reference in New Issue