// NewClientFromSettingsFile returns a new Azure management // client created using a publish settings file. func (c *Config) NewClientFromSettingsFile() (*Client, error) { if _, err := os.Stat(c.SettingsFile); os.IsNotExist(err) { return nil, fmt.Errorf("Publish Settings file %q does not exist!", c.SettingsFile) } mc, err := management.ClientFromPublishSettingsFile(c.SettingsFile, c.SubscriptionID) if err != nil { return nil, nil } return &Client{ mgmtClient: mc, affinityGroupClient: affinitygroup.NewClient(mc), hostedServiceClient: hostedservice.NewClient(mc), secGroupClient: networksecuritygroup.NewClient(mc), osImageClient: osimage.NewClient(mc), sqlClient: sql.NewClient(mc), storageServiceClient: storageservice.NewClient(mc), vmClient: virtualmachine.NewClient(mc), vmDiskClient: virtualmachinedisk.NewClient(mc), vmImageClient: virtualmachineimage.NewClient(mc), vnetClient: virtualnetwork.NewClient(mc), mutex: &sync.Mutex{}, }, nil }
func (c *Config) NewClientFromSettingsData() (*Client, error) { mc, err := management.ClientFromPublishSettingsData(c.Settings, c.SubscriptionID) if err != nil { return nil, nil } return &Client{ mgmtClient: mc, affinityGroupClient: affinitygroup.NewClient(mc), hostedServiceClient: hostedservice.NewClient(mc), secGroupClient: networksecuritygroup.NewClient(mc), osImageClient: osimage.NewClient(mc), sqlClient: sql.NewClient(mc), storageServiceClient: storageservice.NewClient(mc), vmClient: virtualmachine.NewClient(mc), vmDiskClient: virtualmachinedisk.NewClient(mc), vmImageClient: virtualmachineimage.NewClient(mc), vnetClient: virtualnetwork.NewClient(mc), mutex: &sync.Mutex{}, }, nil }
func (s *StepCreateImage) Cleanup(state multistep.StateBag) { client := state.Get(constants.RequestManager).(management.Client) ui := state.Get(constants.Ui).(packer.Ui) var err error var res int if res = state.Get(constants.VmExists).(int); res == 1 { //VM was not removed at image creation step return } // Since VM was successfully removed - remove it's media as well if res = state.Get(constants.DiskExists).(int); res == 1 { ui.Message("Removing Temporary Azure Disk...") errorMsg := "Error Removing Temporary Azure Disk: %s" diskName, ok := state.Get(constants.HardDiskName).(string) if ok { if len(diskName) == 0 { err := fmt.Errorf(errorMsg, err) ui.Error(err.Error()) return } if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) { return vmdisk.NewClient(client).DeleteDisk(diskName, true) }, retry.ConstantBackoffRule("busy", func(err management.AzureError) bool { return strings.Contains(err.Message, "is currently performing an operation on deployment") || strings.Contains(err.Message, "is currently in use by virtual machine") }, 30*time.Second, 10)); err != nil { err := fmt.Errorf(errorMsg, err) ui.Error(err.Error()) return } state.Put(constants.DiskExists, 0) } } }