use port as ints

This commit is contained in:
Adrien Delorme
2019-03-19 14:47:21 +01:00
parent f828b72c10
commit 5a6dffde9a
47 changed files with 112 additions and 113 deletions
+1 -1
View File
@@ -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"`
+2 -2
View File
@@ -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 {
+2 -2
View File
@@ -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)
}