diff --git a/builder/cloudstack/step_configure_networking.go b/builder/cloudstack/step_configure_networking.go index 634b6dcf8..edc8ac037 100644 --- a/builder/cloudstack/step_configure_networking.go +++ b/builder/cloudstack/step_configure_networking.go @@ -2,19 +2,14 @@ package cloudstack import ( "fmt" - "math/rand" "strings" - "time" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" "github.com/xanzy/go-cloudstack/cloudstack" ) -type stepSetupNetworking struct { - privatePort int - publicPort int -} +type stepSetupNetworking struct{} func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction { client := state.Get("client").(*cloudstack.CloudStackClient) @@ -28,20 +23,6 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction ui.Message("Networking has been setup!") return multistep.ActionContinue } - // Generate a random public port used to configure our port forward. - rand.Seed(time.Now().UnixNano()) - s.publicPort = 50000 + rand.Intn(10000) - - // Set the currently configured port to be the private port. - s.privatePort = config.Comm.Port() - - // Set the SSH or WinRM port to be the randomly generated public port. - switch config.Comm.Type { - case "ssh": - config.Comm.SSHPort = s.publicPort - case "winrm": - config.Comm.WinRMPort = s.publicPort - } // Retrieve the instance ID from the previously saved state. instanceID, ok := state.Get("instance_id").(string) @@ -95,9 +76,9 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction ui.Message("Creating port forward...") p := client.Firewall.NewCreatePortForwardingRuleParams( config.PublicIPAddress, - s.privatePort, + config.Comm.Port(), "TCP", - s.publicPort, + config.Comm.Port(), instanceID, ) @@ -129,8 +110,8 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction p.SetAclid(network.Aclid) p.SetAction("allow") p.SetCidrlist(config.CIDRList) - p.SetStartport(s.publicPort) - p.SetEndport(s.publicPort) + p.SetStartport(config.Comm.Port()) + p.SetEndport(config.Comm.Port()) p.SetTraffictype("ingress") // Create the network ACL rule. @@ -150,8 +131,8 @@ func (s *stepSetupNetworking) Run(state multistep.StateBag) multistep.StepAction // Configure the firewall rule. p.SetCidrlist(config.CIDRList) - p.SetStartport(s.publicPort) - p.SetEndport(s.publicPort) + p.SetStartport(config.Comm.Port()) + p.SetEndport(config.Comm.Port()) fwRule, err := client.Firewall.CreateFirewallRule(p) if err != nil { diff --git a/builder/cloudstack/step_create_instance.go b/builder/cloudstack/step_create_instance.go index 7c8103899..7d1b687fa 100644 --- a/builder/cloudstack/step_create_instance.go +++ b/builder/cloudstack/step_create_instance.go @@ -32,6 +32,10 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction p.SetName(config.InstanceName) p.SetDisplayname("Created by Packer") + if config.Keypair != "" { + p.SetKeypair(config.Keypair) + } + // If we use an ISO, configure the disk offering. if config.SourceISO != "" { p.SetDiskofferingid(config.DiskOffering) @@ -60,10 +64,6 @@ func (s *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction p.SetProjectid(config.Project) } - if config.Keypair != "" { - p.SetKeypair(config.Keypair) - } - if config.UserData != "" { ud, err := getUserData(config.UserData, config.HTTPGetOnly) if err != nil {