我是用于.NET的Azure管理库的新手。我们如何枚举可用于订阅的可用VM实例大小,或者一般情况下使用.Net或Rest API的Azure管理库? 请建议。以编程方式获取天蓝色虚拟机大小的列表
回答
你可以通过调用
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
您可以通过区域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
你可以请一些基于证书的认证? –
这是我基于证书示例 –
的另一个答案谢谢,它似乎需要首先上传AD应用程序的证书。它通过PowerShell完成还是还有其他方法? –
您可以通过使用证书基本身份验证获得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();
- 1. REST URI以获取天蓝色虚拟机的IP地址
- 2. 如何获得天蓝色的虚拟机系列?
- 3. 天蓝色虚拟机的出站绑定虚拟ip
- 4. 从我的天蓝色虚拟机上的github获取代码的脚本
- 5. 如何通过Power Shell获取天蓝色虚拟机的CPU使用情况
- 6. 虚拟机使用天蓝色的详细属性?
- 7. 如何以编程方式读取天蓝色的Web作业日志
- 8. 多台虚拟机可以使用天蓝色的单个网卡吗?
- 9. 将虚拟机的副本复制到其他虚拟机的天蓝
- 10. 加入蔚蓝虚拟商品给顾客天蓝色广告
- 11. 如何以编程方式启动虚拟机?
- 12. 以编程方式在Azure虚拟机上托管SSRS
- 13. 以编程方式打印到虚拟打印机(XPS)
- 14. 以编程方式在Wildfly/Undertow中创建虚拟主机
- 15. 获取Windows Azure虚拟机的API大小
- 16. 如何从虚拟机管理程序以编程方式查找虚拟机的IpAddress?
- 17. 如何确定SharePoint列表的大小以编程方式
- 18. 如何以编程方式获取Linux内核页面大小
- 19. 当前的天蓝色存储不允许创建新的虚拟机
- 20. 如何以编程方式获取iPhone的蓝牙MAC地址?
- 21. 以编程方式禁止注册表虚拟化
- 22. 以编程方式获取表控件
- 23. 以编程方式从颜色中获取选择的颜色
- 24. 如何以编程方式获取ImageView的色调颜色?
- 25. 无法为门户网站创建天蓝色的pfSense虚拟机
- 26. 有可能创建几个DNS或子域到天蓝色的虚拟机?
- 27. 什么是以编程方式创建虚拟机的良好API或方法?
- 28. 如何以编程方式获取IIS 7中的网站列表和虚拟目录?
- 29. 通过Portal UI在天蓝色虚拟机上设置静态IP
- 30. 要同步两个天蓝色虚拟机,需要排除哪些文件?
伟大...什么来api版本顺便说一句? –
@MuhammadMuradHaider页面顶部有一个链接,提供[必需的标题和参数](https://msdn.microsoft.com/en-us/library/azure/mt163630.aspx),包括api版本 - 只是为了破坏这个惊喜,它是'2015-05-01-preview';) –