public async Task CreateDisk() { #region Snippet:Managing_Disks_CreateADisk ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the disk collection from the resource group ManagedDiskCollection diskCollection = resourceGroup.GetManagedDisks(); // Use the same location as the resource group string diskName = "myDisk"; var input = new ManagedDiskData(resourceGroup.Data.Location) { Sku = new DiskSku() { Name = DiskStorageAccountTypes.StandardLRS }, CreationData = new DiskCreationData(DiskCreateOption.Empty), DiskSizeGB = 1, }; ArmOperation <ManagedDiskResource> lro = await diskCollection.CreateOrUpdateAsync(WaitUntil.Completed, diskName, input); ManagedDiskResource disk = lro.Value; #endregion Snippet:Managing_Disks_CreateADisk }
public async Task DeleteDisk() { #region Snippet:Managing_Disks_DeleteDisk ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the disk collection from the resource group ManagedDiskCollection diskCollection = resourceGroup.GetManagedDisks(); string diskName = "myDisk"; ManagedDiskResource disk = await diskCollection.GetAsync(diskName); await disk.DeleteAsync(WaitUntil.Completed); #endregion Snippet:Managing_Disks_DeleteDisk }
public async Task ListDisks() { #region Snippet:Managing_Disks_ListAllDisks ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the disk collection from the resource group ManagedDiskCollection diskCollection = resourceGroup.GetManagedDisks(); // With ListAsync(), we can get a list of the disks AsyncPageable <ManagedDiskResource> response = diskCollection.GetAllAsync(); await foreach (ManagedDiskResource disk in response) { Console.WriteLine(disk.Data.Name); } #endregion Snippet:Managing_Disks_ListAllDisks }