2016-01-21 87 views

回答

4

你可以通过调用

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

作为记录在这里得到VM尺寸区域的名单 - List all available virtual machine sizes in a region

还有一个.NET类的一样,但我还没有发现它的任何实例中使用 - 这里记录 - VirtualMachineSizeOperationsExtensions.List

+0

伟大...什么来api版本顺便说一句? –

+0

@MuhammadMuradHaider页面顶部有一个链接,提供[必需的标题和参数](https://msdn.microsoft.com/en-us/library/azure/mt163630.aspx),包括api版本 - 只是为了破坏这个惊喜,它是'2015-05-01-preview';) –

0

您可以通过区域fillter得到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

+0

你可以请一些基于证书的认证? –

+0

这是我基于证书示例 –

+0

的另一个答案谢谢,它似乎需要首先上传AD应用程序的证书。它通过PowerShell完成还是还有其他方法? –

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(); 
相关问题