一个用于根据Sku层级筛选Azure磁盘的API。

huangapple go评论100阅读模式
英文:

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

问题

Sure, here's the translation:

有人可以建议一个REST API来根据磁盘层级(例如- ultra、standard)获取订阅中的所有磁盘,并返回具有相同层级的磁盘列表。

英文:

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

得分: 0

根据我所了解,没有直接获取磁盘按磁盘层级(SKU)检索的 API。您需要自行筛选结果。如果您使用 .NET,使用 Azure 管理 SDK 将比使用 REST API 更容易获得所需的结果。

我为您编写了一个简单的控制台应用程序,请尝试以下代码:

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 订阅 ID>";
            var clientId = "<azure ad 应用程序 ID>";
            var clientSecret = "<azure ad 应用程序密钥>";
            var tenantId = "<您的租户名称/ID>";
            var sku = "<要查询的磁盘 SKU>"; // 所有 SKU: 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("使用订阅:" + subscriotionId);

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

            Console.WriteLine("具有 SKU 的磁盘:" + sku);
            foreach (var disk in disks)
            {
                Console.WriteLine("名称:" + disk.Name + "      资源组:" + disk.ResourceGroupName);
            }

            Console.ReadKey();
        }
    }
}

结果:

一个用于根据Sku层级筛选Azure磁盘的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 = &quot;&lt;azure subscrioption ID&gt;&quot;;
            var clientId = &quot;&lt;azure ad app id&gt;&quot;;
            var clientSecret = &quot;&lt;azure ad app secret&gt;&quot;;
            var tenantId = &quot;&lt;your tenant name/id&gt;&quot;;
            var sku = &quot;&lt;the disk sku you want to query&gt;&quot;;   //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(&quot;using subscription: &quot; + subscriotionId);

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

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

            Console.ReadKey();
        }
    }
}

Result :

一个用于根据Sku层级筛选Azure磁盘的API。

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

huangapple
  • 本文由 发表于 2020年1月6日 16:55:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定