github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/step_get_ip_address.go (about) 1 // Copyright (c) Microsoft Corporation. All rights reserved. 2 // Licensed under the MIT License. See the LICENSE file in builder/azure for license information. 3 4 package arm 5 6 import ( 7 "fmt" 8 9 "github.com/mitchellh/multistep" 10 "github.com/mitchellh/packer/builder/azure/common/constants" 11 "github.com/mitchellh/packer/packer" 12 ) 13 14 type StepGetIPAddress struct { 15 client *AzureClient 16 get func(resourceGroupName string, ipAddressName string) (string, error) 17 say func(message string) 18 error func(e error) 19 } 20 21 func NewStepGetIPAddress(client *AzureClient, ui packer.Ui) *StepGetIPAddress { 22 var step = &StepGetIPAddress{ 23 client: client, 24 say: func(message string) { ui.Say(message) }, 25 error: func(e error) { ui.Error(e.Error()) }, 26 } 27 28 step.get = step.getIPAddress 29 return step 30 } 31 32 func (s *StepGetIPAddress) getIPAddress(resourceGroupName string, ipAddressName string) (string, error) { 33 res, err := s.client.PublicIPAddressesClient.Get(resourceGroupName, ipAddressName, "") 34 if err != nil { 35 return "", nil 36 } 37 38 return *res.Properties.IPAddress, nil 39 } 40 41 func (s *StepGetIPAddress) Run(state multistep.StateBag) multistep.StepAction { 42 s.say("Getting the public IP address ...") 43 44 var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string) 45 var ipAddressName = state.Get(constants.ArmPublicIPAddressName).(string) 46 47 s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName)) 48 s.say(fmt.Sprintf(" -> PublicIPAddressName : '%s'", ipAddressName)) 49 50 address, err := s.get(resourceGroupName, ipAddressName) 51 if err != nil { 52 state.Put(constants.Error, err) 53 s.error(err) 54 55 return multistep.ActionHalt 56 } 57 58 s.say(fmt.Sprintf(" -> SSHHost : '%s'", address)) 59 state.Put(constants.SSHHost, address) 60 61 return multistep.ActionContinue 62 } 63 64 func (*StepGetIPAddress) Cleanup(multistep.StateBag) { 65 }