/// <summary> /// Deletes a vm disk if a name is known /// </summary> /// <param name="name">The name of the vm disk</param> public void DeleteNamedVirtualMachineDisk(string name) { bool diskErased = false; int count = 0; // keep this going until we delete the disk or time out! while (count < 100 && !diskErased) { try { var deleteVirtualMachineDisk = new DeleteVirtualMachineDiskCommand(name) { SubscriptionId = Properties.SubscriptionId, Certificate = Properties.Certificate }; deleteVirtualMachineDisk.Execute(); diskErased = true; } catch (Exception) { count++; Thread.Sleep(3000); } } }
private void DeleteDataDisks(IBlobClient client) { // delete the data disks in the reverse order if (_vmRole.HardDisks.HardDiskCollection == null) { return; } for (int i = _vmRole.HardDisks.HardDiskCollection.Count - 1; i >= 0; i--) { var dataDiskCommand = new DeleteVirtualMachineDiskCommand(_vmRole.HardDisks.HardDiskCollection[i].DiskName) { SubscriptionId = Properties.SubscriptionId, Certificate = Properties.Certificate }; dataDiskCommand.Execute(); int pos = _vmRole.HardDisks.HardDiskCollection[i].MediaLink.LastIndexOf('/'); string diskFile = _vmRole.HardDisks.HardDiskCollection[i].MediaLink.Substring(pos + 1); if (client != null) { client.DeleteBlob(diskFile); } } }