根据Sku层过滤Azure磁盘的API [英] An api to get azure disk filtered according to the Sku tier

查看:123
本文介绍了根据Sku层过滤Azure磁盘的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能建议REST API根据磁盘层(例如,超,标准)获取预订中的所有磁盘,并返回具有相同层的磁盘列表.

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.

推荐答案

据我所知,尚无此类API可以直接通过磁盘层(SKU)检索磁盘.您应该自己过滤结果.如果您使用的是.net,则使用Azure管理SDK会比使用REST API轻松获得所需的结果.

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();
        }
    }
}

结果:

如果您还有其他疑问,请随时告诉我.

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

这篇关于根据Sku层过滤Azure磁盘的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆