Skip to content

Commit

Permalink
use port as ints
Browse files Browse the repository at this point in the history
  • Loading branch information
azr committed Mar 19, 2019
1 parent f828b72 commit 5a6dffd
Show file tree
Hide file tree
Showing 47 changed files with 112 additions and 113 deletions.
2 changes: 1 addition & 1 deletion builder/cloudstack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions builder/cloudstack/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
18 changes: 9 additions & 9 deletions builder/cloudstack/step_configure_networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions builder/cloudstack/step_create_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions builder/cloudstack/step_create_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions builder/hyperv/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type bootCommandTemplateData struct {
HTTPIP string
HTTPPort uint
HTTPPort int
Name string
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion builder/hyperv/iso/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion builder/hyperv/vmcx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions builder/parallels/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type bootCommandTemplateData struct {
HTTPIP string
HTTPPort uint
HTTPPort int
Name string
}

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion builder/parallels/pvm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions builder/qemu/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions builder/qemu/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion builder/qemu/step_configure_vnc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions builder/qemu/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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")
Expand Down Expand Up @@ -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"+
Expand Down Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions builder/qemu/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const KeyLeftShift uint32 = 0xFFE1

type bootCommandTemplateData struct {
HTTPIP string
HTTPPort uint
HTTPPort int
Name string
}

Expand All @@ -29,7 +29,7 @@ type bootCommandTemplateData struct {
// config *config
// http_port int
// ui packer.Ui
// vnc_port uint
// vnc_port int
//
// Produces:
// <nothing>
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions builder/vagrant/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion builder/vagrant/step_ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions builder/virtualbox/common/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions builder/virtualbox/common/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions builder/virtualbox/common/ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions builder/virtualbox/common/step_configure_vrdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions builder/virtualbox/common/step_forward_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion builder/virtualbox/common/step_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down
4 changes: 2 additions & 2 deletions builder/virtualbox/common/step_type_boot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
Loading

0 comments on commit 5a6dffd

Please sign in to comment.