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?
Based on my understanding, I think you want to get the public & private ip addresses of a Azure VM using Azure SDK for Python.
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.
azure.mgmt.networkpackage, please see http://azure-sdk-for-python.readthedocs.io/en/latest/ref/azure.mgmt.network.html.