由于使用资源管理器部署VM,因此在不同提供者(计算和网络)下的状态,IP地址和大小信息。当前可能无法在通话中获取虚拟机信息和网络信息。
随着Microsoft Azure Management Client Library (Fluent),我们可以得到VM信息(电源状态,机器大小,IP地址)。实际上,它调用REST API 两次。关于Azure认证请参考how to create an authentication file。
AzureCredentials credentials = AzureCredentials.FromFile("Full path of your AzureAuthFile");
var azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.BASIC)
.Authenticate(credentials)
.WithDefaultSubscription();
foreach (var virtualMachine in azure.VirtualMachines.ListByGroup("Your Resource Group Name").Where(virtualMachine => virtualMachine.ComputerName.Equals("vmName")))
{
var state = virtualMachine.PowerState;
var size = virtualMachine.Size;
var ip = virtualMachine.GetPrimaryPublicIpAddress().IpAddress; //call Rest API again
}
如果它部署在CloudService下,那么我们可以使用Windows Azure management library。很容易获得虚拟机(角色) 有关电源状态,IP地址和机器大小的信息。
var certificate = new CertificateCloudCredentials(subscriptionId, x509Certificate);
var computeManagementClient = new ComputeManagementClient(certificate);
var deployments = await computeManagementClient.Deployments.GetByNameAsync (hostedServiceName,"Your Deployment Name");
var state = deployments.RoleInstances.First().PowerState;
var ipAddress = deployments.RoleInstances.First().IPAddress;
var size = deployments.RoleInstances.First().InstanceSize;