An api to get azure disk filtered according to the Sku tier

岁酱吖の 提交于 2020-01-25 05:04:21

问题


Can anyone suggest a REST API to fetch all the disks in a subscription according to the disk tier( eg- ultra,standard) and return a list of disks having the same tier.


回答1:


As far as I know, there is no such API that could retrieve disks by disk tier(SKU) directly . You should filter the result yourself. If you are using .net , use Azure management SDK will be a way that much easier to get the result you need than using REST API.

I write a simple console app for you, try the code below :

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AzureMgmtTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var subscriotionId = "<azure subscrioption ID>";
            var clientId = "<azure ad app id>";
            var clientSecret = "<azure ad app secret>";
            var tenantId = "<your tenant name/id>";
            var sku = "<the disk sku you want to query>";   //all skus : Standard_LRS,Premium_LRS,StandardSSD_LRS,UltraSSD_LRS



            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId,clientSecret,tenantId,AzureEnvironment.AzureGlobalCloud);

            var azure = Azure
                .Configure()
                .Authenticate(credentials)
                .WithSubscription(subscriotionId);
            Console.WriteLine("using subscription: " + subscriotionId);

            var disks = azure.Disks.List().Where(disk => disk.Sku.ToString().Equals(sku));

            Console.WriteLine("disks with sku :" + sku);
            foreach (var disk in disks) {
                Console.WriteLine("name:"+ disk.Name + "      resource_group:"+ disk.ResourceGroupName );
            }

            Console.ReadKey();
        }
    }
}

Result :

If you have any further concerns, pls feel free to let me know.



来源:https://stackoverflow.com/questions/59609147/an-api-to-get-azure-disk-filtered-according-to-the-sku-tier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!