github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/step_get_os_disk.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/Azure/azure-sdk-for-go/arm/compute" 10 11 "github.com/mitchellh/packer/builder/azure/common/constants" 12 13 "github.com/mitchellh/multistep" 14 "github.com/mitchellh/packer/packer" 15 ) 16 17 type StepGetOSDisk struct { 18 client *AzureClient 19 query func(resourceGroupName string, computeName string) (compute.VirtualMachine, error) 20 say func(message string) 21 error func(e error) 22 } 23 24 func NewStepGetOSDisk(client *AzureClient, ui packer.Ui) *StepGetOSDisk { 25 var step = &StepGetOSDisk{ 26 client: client, 27 say: func(message string) { ui.Say(message) }, 28 error: func(e error) { ui.Error(e.Error()) }, 29 } 30 31 step.query = step.queryCompute 32 return step 33 } 34 35 func (s *StepGetOSDisk) queryCompute(resourceGroupName string, computeName string) (compute.VirtualMachine, error) { 36 return s.client.VirtualMachinesClient.Get(resourceGroupName, computeName, "") 37 } 38 39 func (s *StepGetOSDisk) Run(state multistep.StateBag) multistep.StepAction { 40 s.say("Querying the machine's properties ...") 41 42 var resourceGroupName = state.Get(constants.ArmResourceGroupName).(string) 43 var computeName = state.Get(constants.ArmComputeName).(string) 44 45 s.say(fmt.Sprintf(" -> ResourceGroupName : '%s'", resourceGroupName)) 46 s.say(fmt.Sprintf(" -> ComputeName : '%s'", computeName)) 47 48 vm, err := s.query(resourceGroupName, computeName) 49 if err != nil { 50 state.Put(constants.Error, err) 51 s.error(err) 52 53 return multistep.ActionHalt 54 } 55 56 s.say(fmt.Sprintf(" -> OS Disk : '%s'", *vm.Properties.StorageProfile.OsDisk.Vhd.URI)) 57 state.Put(constants.ArmOSDiskVhd, *vm.Properties.StorageProfile.OsDisk.Vhd.URI) 58 59 return multistep.ActionContinue 60 } 61 62 func (*StepGetOSDisk) Cleanup(multistep.StateBag) { 63 }