Reputation: 132
the point is, i have to detach a disk in azure, using c# and the resourcemanager provided by azure.
atm i have following...
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var disk = new DataDisk(ObjVirtualMachines.StorageProfile.DataDisks.Count,
DiskCreateOptionTypes.Empty,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
I didn't get it. Its primary used to attach a disk, with different parameters. There is no deattach function, so i tried, setting it to Empty. But that wont work either.
I also experimented with the disk itself. But i have to detach the disk from it, so working on the disk alone will not reach to the goal.
Any Ideas how to solve this problem ?
Upvotes: 3
Views: 225
Reputation: 132
ok, got a Solution that works...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var disktodetach = ObjVirtualMachines.StorageProfile.DataDisks.FirstOrDefault(p => p.Name == name);
ObjVirtualMachines.StorageProfile.DataDisks.Remove(disktodetach);
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines).Result;
Upvotes: 2