我正在尝试编写一个应用程序,列出 Azure 上所有 VM 的状态及其状态(正在运行/未运行)。我可以使用以下代码获取所有云服务及其运行名称的列表...
var x = from h in _computeManagementClient.HostedServices.List() select h;
foreach (var item in x)
{
//item.Properties.Label is the name of the service
}
是否有类似的方法可以用来列出虚拟机及其状态?如果可能的话,我宁愿不使用 REST API。
最佳答案
通过虚拟机,我假设您指的是角色实例?
您可以通过部署来获取它们。
var instances = _computeManagementClient.Deployments.GetBySlot(serviceName, DeploymentSlot.Production).RoleInstances;
这将返回 Microsoft.WindowsAzure.Management.Compute.Models.RoleInstance
的集合,您可以从中获取状态信息等。
RoleInstance 的文档:
关于c# - 如何以编程方式获取 Windows Azure 中的虚拟机列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21738152/