2014-02-12 30 views
1

我在编写一个应用程序,列出Azure上所有虚拟机及其状态(正在运行/未运行)的状态。我能得到的所有使用下面的代码运行的云服务和他们的名字列表...如何在Windows Azure中获取虚拟机列表

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。

+0

如果你的意思是IaaS的虚拟机,对了,还有的API为此 - 在虚拟机操作组下。 –

回答

1

通过虚拟机,我假设你的意思是角色实例?

您可以通过部署获得它们。

var instances = _computeManagementClient.Deployments.GetBySlot(serviceName, DeploymentSlot.Production).RoleInstances; 

这将返回的Microsoft.WindowsAzure.Management.Compute.Models.RoleInstance的集合,从中可以获取状态信息等

为RoleInstance文档:

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.management.compute.models.roleinstance.aspx

+0

GetBySlot没有一个参数,所以我不得不编辑它看起来像'GetBySlot(Item.Properties.Label,DeploymentSlot.Production)',然后它完美运行。非常感谢。 –

+0

对不起,我的错。我更新了我的答案。如果答案是正确的,你能标记吗?我需要代表; o) –