使用资源管理器部署和Rest API获取Azure VM [英] Get Azure VM using resource manager deployment and rest api

查看:52
本文介绍了使用资源管理器部署和Rest API获取Azure VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Resource Manager部署模型部署了虚拟机.

I've deployed a vm using Resource Manager deployment model.

按此处所述使用rest api 我可以获取有关VM的信息.
我正在寻找电源状态,IP地址和机器大小.但是,要获取所有这些信息,我需要3个不同的电话 https://management.azure.com/subscriptions/ {SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualmachines/{ServerName}

Using rest api as described here I'm able to get infomation about the VM.
I'm looking to get the power state, ip address, and machine size. However to get all that information I need 3 different calls https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualmachines/{ServerName}

https://management.azure.com/subscriptions/ {SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualmachines/{ServerName}/InstanceView

https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Compute/virtualmachines/{ServerName}/InstanceView

https://management.azure.com/subscriptions/ {SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/networkInterfaces/{ServerName} _NIC

https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroup}/providers/Microsoft.Network/networkInterfaces/{ServerName}_NIC

有没有一种方法可以在一次通话中获得所有这些信息?

Is there a way to get all this information in 1 call?

推荐答案

由于使用资源管理器部署了VM,然后在不同的提供程序(计算和网络)下声明了IP地址和大小信息.当前可能没有办法在呼叫中获取VM信息和网络信息.

Since VM deployed with Resource Manager then state, ip address and size info under the different providers (Compute and Network). It maybe has no way to get the VM info and network info in a call currently.

使用 Microsoft Azure管理客户端库(Fluent),我们可以获得虚拟机信息(电源状态,机器大小,IP地址).实际上,它将REST API称为两次.关于Azure身份验证,请参考如何创建身份验证文件.

With Microsoft Azure Management Client Library (Fluent), we can get the VM info (power state, machine size ,ip address). Actually, it call the REST API twice. About Azure authentication please refer to 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管理库.容易获得VM(角色)有关电源状态,IP地址和计算机大小的信息.

If it deployed under the CloudService then we can use Windows Azure management library. It is easy to get VM(Role) Info about power state, ip address, and machine size.

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;

这篇关于使用资源管理器部署和Rest API获取Azure VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆