由於使用資源管理器部署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;