2016-03-04 05:14:55 -05:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
2016-04-21 19:50:03 -04:00
|
|
|
// Licensed under the MIT License. See the LICENSE file in the project root for license information.
|
2016-03-04 05:14:55 -05:00
|
|
|
|
|
|
|
package arm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-03-10 20:46:22 -05:00
|
|
|
"github.com/mitchellh/packer/builder/azure/common/constants"
|
2016-04-21 19:50:03 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2016-03-04 05:14:55 -05:00
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepGetIPAddress struct {
|
|
|
|
client *AzureClient
|
|
|
|
get func(resourceGroupName string, ipAddressName string) (string, error)
|
|
|
|
say func(message string)
|
|
|
|
error func(e error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewStepGetIPAddress(client *AzureClient, ui packer.Ui) *StepGetIPAddress {
|
|
|
|
var step = &StepGetIPAddress{
|
|
|
|
client: client,
|
|
|
|
say: func(message string) { ui.Say(message) },
|
|
|
|
error: func(e error) { ui.Error(e.Error()) },
|
|
|
|
}
|
|
|
|
|
|
|
|
step.get = step.getIPAddress
|
|
|
|
return step
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepGetIPAddress) getIPAddress(resourceGroupName string, ipAddressName string) (string, error) {
|
|
|
|
res, err := s.client.PublicIPAddressesClient.Get(resourceGroupName, ipAddressName, "")
|
|
|
|
if err != nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return *res.Properties.IPAddress, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepGetIPAddress) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
s.say("Getting the public IP address ...")
|
|
|
|
|
|
|
|
var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string)
|
|
|
|
var ipAddressName = state.Get(constants.ArmPublicIPAddressName).(string)
|
|
|
|
|
|
|
|
s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName))
|
|
|
|
s.say(fmt.Sprintf(" -> PublicIPAddressName : '%s'", ipAddressName))
|
|
|
|
|
|
|
|
address, err := s.get(resourceGroupName, ipAddressName)
|
|
|
|
if err != nil {
|
|
|
|
state.Put(constants.Error, err)
|
|
|
|
s.error(err)
|
|
|
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2016-04-21 19:50:03 -04:00
|
|
|
s.say(fmt.Sprintf(" -> Public IP : '%s'", address))
|
2016-03-04 05:14:55 -05:00
|
|
|
state.Put(constants.SSHHost, address)
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*StepGetIPAddress) Cleanup(multistep.StateBag) {
|
|
|
|
}
|