是否有任何Python API可以获取Azure中虚拟机的IP地址(内部或外部) [英] Is there any python API which can get the IP address (internal or external) of Virtual machine in Azure
本文介绍了是否有任何Python API可以获取Azure中虚拟机的IP地址(内部或外部)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用python SDK控制Azure中的VM.是否有任何API可以根据虚拟机的名称获取虚拟机的IP地址(内部或外部)?
I want to control the VMs in Azure with python SDK. Is there any API that can get a VM's IP address (internal or external) according to VM's name?
推荐答案
基于我的理解,我认为您希望获得公众的认可.使用适用于Python的Azure SDK的Azure VM的私有IP地址.
Based on my understanding, I think you want to get the public & private ip addresses of a Azure VM using Azure SDK for Python.
要获取这些ip地址(内部和外部),请参见下面的代码.
For getting these ip addresses (internal & external), please see the code below.
from azure.mgmt.network import NetworkManagementClient, NetworkManagementClientConfiguration
subscription_id = '33333333-3333-3333-3333-333333333333'
credentials = ...
network_client = NetworkManagementClient(
NetworkManagementClientConfiguration(
credentials,
subscription_id
)
)
GROUP_NAME = 'XXX'
VM_NAME = 'xxx'
PUBLIC_IP_NAME = VM_NAME
public_ip_address = network_client.public_ip_addresses.get(GROUP_NAME, PUBLIC_IP_NAME)
print(public_ip_address.ip_address)
print(public_ip_address.ip_configuration.private_ip_address)
作为参考,您可以参考下面的文档以了解上面的代码的详细信息.
As reference, you can refer to the documents below to know the details of the code above.
- 使用Python作为变量的资源管理身份验证
凭据
. - 创建管理客户端表示变量
network_client
. - 有关
azure.mgmt.network
软件包的更多详细信息,请参见
- Resource Management Authentication using Python for the variable
credentials
. - Create the management client for the variable
network_client
. - More details for the
azure.mgmt.network
package, please see http://azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.network.html.
这篇关于是否有任何Python API可以获取Azure中虚拟机的IP地址(内部或外部)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文