使用 Azure 服务管理(经典)API 获取区域中的虚拟机大小列表

本文关键字:区域 虚拟机 列表 获取 API 服务 Azure 管理 经典 使用 | 更新日期: 2023-09-27 17:57:08

如何获取特定 Azure 位置中可用虚拟机大小的列表。我已经看到资源管理器 API 中有一个可用于相同位置的端点:https://msdn.microsoft.com/en-us/library/azure/mt269440.aspx是否可以通过 Azure 服务管理(经典)API 获得相同的信息?

使用 Azure 服务管理(经典)API 获取区域中的虚拟机大小列表

请尝试使用以下代码,这将对我有用

AuthenticationContext authenticationContext = new AuthenticationContext(your - authserviceurl + your - tenantdomain);
UserCredential uc = new UserCredential(Api - username, Api - password);
token = authenticationContext.AcquireToken("https://management.core.windows.net/", API - nativetenantid, uc);
var credentials = new TokenCredentials(token);
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = Your - SubscriptionId };
var virtualMachineSize = computeClient.VirtualMachineSizes.List(locationName).ToList(); 

我正在使用Microsoft.Azure.Management.Compute.dll,v10.0.0.0版本。上面的示例我正在使用基于令牌的身份验证。您还可以尝试使用基于证书的身份验证。

以下参考文档建议这应该是可能的。

URI 参数

位置 - 可选。从指定位置返回 VM 映像。位置参数仅适用于版本 2014-05-01 或更高版本。