Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure: Poweroff VM before deletion #206

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 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,24 @@ 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(2).Infof("VM poweroff was successful for %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(2).Infof("VM deletion was successful for %s", vmName)

} else {
glog.Warningf("VM was not found for %s", vmName)
}
glog.V(3).Infof("Deleted VM %s", vmName)

listOfResources = make(map[string]string)
d.getnics(d.MachineID, listOfResources)
Expand All @@ -234,19 +245,23 @@ func (d *AzureDriver) Delete() error {
if err != nil {
return err
}
glog.V(2).Infof("NIC deletion was successful for %s", nicName)
} else {
glog.Warningf("NIC was not found for %s", nicName)
}
glog.V(3).Infof("Deleted NIC %s", nicName)

listOfResources = make(map[string]string)
d.getdisks(d.MachineID, listOfResources)
if len(listOfResources) != 0 {
_, errChan := diskClient.Delete(resourceGroup, diskName, cancel)
err = onErrorFail(<-errChan, fmt.Sprintf("diskClient.Delete for NIC '%s' failed", nicName))
err = onErrorFail(<-errChan, fmt.Sprintf("diskClient.Delete for NIC '%s' failed", diskName))
if err != nil {
return err
}
glog.V(2).Infof("OS-Disk deletion was successful for %s", diskName)
} else {
glog.Warningf("OS-Disk was not found for %s", diskName)
}
glog.V(3).Infof("Deleted OS-Disk %s", nicName)

return err
}
Expand Down