4

我是 .net 的 Azure 管理库的新手。我们如何枚举与订阅相关的可用 VM 实例大小,或者通常使用 .Net 或 Rest API 的 Azure 管理库?请建议。

4

3 回答 3

5

您可以通过调用获取某个区域的 VM 大小列表

https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Compute/locations/{location}/vmSizes?api-version={api-version}

如此处所述 -列出区域中所有可用的虚拟机大小

还有一个相同的.Net类,但我没有找到任何使用它的例子 - 记录在这里 - VirtualMachineSizeOperationsExtensions.List

于 2016-01-21T18:30:19.133 回答
0

您可以按区域填充器获取 VM 大小列表

AuthenticationContext authenticationContext = new AuthenticationContext("https://login.windows.net/tenantdomainname.onmicrosoft.com"]);
UserCredential uc = new UserCredential(authusername,authpassword);
token = authenticationContext.AcquireToken("https://management.core.windows.net/", nativetenantid, uc);

var credentials = new TokenCredentials(token);
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = subscriptionid};
var virtualMachineSize = computeClient.VirtualMachineSizes.List(region_name).ToList();

您必须在 Azure Active Directory 上创建一个本机客户端 API 以进行基于令牌的身份验证,否则您还可以使用基于证书的身份验证进行客户端授权。

我正在使用Microsoft.Azure.Management.Compute.dll,v10.0.0.0作为计算资源。

你可以在这里下载:https ://www.nuget.org/packages/Microsoft.Azure.Management.Compute/13.0.4-prerelease

于 2016-07-21T10:46:54.133 回答
0

您可以使用证书库身份验证获取 VM 大小列表

获取证书方法

private static X509Certificate2 GetStoreCertificate(string subscriptionId, string thumbprint)
    {
        List<StoreLocation> locations = new List<StoreLocation>
        { 
            StoreLocation.CurrentUser, 
            StoreLocation.LocalMachine
        };

        foreach (var location in locations)
        {
            X509Store store = new X509Store(StoreName.My, location);
            try
            {
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                X509Certificate2Collection certificates = store.Certificates.Find(
                X509FindType.FindByThumbprint, thumbprint, false);
                if (certificates.Count == 1)
                {
                    return certificates[0];
                }
            }
            finally
            {
                store.Close();
            }
        }

        throw new ArgumentException(string.Format("A Certificate with Thumbprint '{0}' could not be located.",thumbprint));
    }

在这里,我描述了获取 VM 大小的相同方法

private static X509Certificate2 Certificate = GetStoreCertificate(Your-subscriptionid,Your-thumbprint);
Microsoft.Azure.CertificateCloudCredentials credentials = new Microsoft.Azure.CertificateCloudCredentials(Your-subscriptionid, Certificate);

 var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = Your-subscriptionid};
 var virtualMachineSize = computeClient.VirtualMachineSizes.List(Your-region_name).ToList();
于 2016-07-22T07:55:34.580 回答