Skip to content

Commit

Permalink
Azure: Poweroff VM before deletion
Browse files Browse the repository at this point in the history
- Azure VM deletion takes too long when a running VM is deleted
- Stopping (Powering off) the VM before deletion should help this process
  • Loading branch information
prashanth26 committed Dec 24, 2018
1 parent c5c9bac commit 87355d3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/driver/driver_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (d *AzureDriver) Create() (string, string, error) {
Name: &nicName,
InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
PrivateIPAllocationMethod: network.Dynamic,
Subnet: &subnet,
Subnet: &subnet,
},
},
},
Expand Down Expand Up @@ -218,13 +218,21 @@ func (d *AzureDriver) Delete() error {
listOfResources := make(map[string]string)
d.getvms(d.MachineID, listOfResources)
if len(listOfResources) != 0 {
_, errChan := vmClient.Delete(resourceGroup, vmName, cancel)

_, errChan := vmClient.PowerOff(resourceGroup, vmName, cancel)
err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.PowerOff failed for '%s'", vmName))
if err != nil {
return err
}
glog.V(3).Infof("PowerOff VM %s", vmName)

_, errChan = vmClient.Delete(resourceGroup, vmName, cancel)
err = onErrorFail(<-errChan, fmt.Sprintf("vmClient.Delete failed for '%s'", vmName))
if err != nil {
return err
}
glog.V(3).Infof("Deleted VM %s", vmName)
}
glog.V(3).Infof("Deleted VM %s", vmName)

listOfResources = make(map[string]string)
d.getnics(d.MachineID, listOfResources)
Expand All @@ -234,8 +242,8 @@ func (d *AzureDriver) Delete() error {
if err != nil {
return err
}
glog.V(3).Infof("Deleted NIC %s", nicName)
}
glog.V(3).Infof("Deleted NIC %s", nicName)

listOfResources = make(map[string]string)
d.getdisks(d.MachineID, listOfResources)
Expand All @@ -245,8 +253,8 @@ func (d *AzureDriver) Delete() error {
if err != nil {
return err
}
glog.V(3).Infof("Deleted OS-Disk %s", nicName)
}
glog.V(3).Infof("Deleted OS-Disk %s", nicName)

return err
}
Expand Down

0 comments on commit 87355d3

Please sign in to comment.