英文:
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();
}
}
}
结果:
如果您有任何进一步的疑虑,请随时告诉我。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论