0

This is similar to Is there any python API which can get the IP address (internal or external) of Virtual machine in Azure, but instead I'd like to get the infiniband IP address of an azure VM.

So far, I can get the NIC of the VM in the VMSS, but that only lets me query for the private IP address of eth0. How can I get the IP addresses of the other interfaces?

Ideally, I'd like to do this in Python


from azure.mgmt.network import NetworkManagementClient
self.network_client = NetworkManagementClient(credentials, AZURE_SUBSCRIPTION_ID)

# get the private IP of a network interface
nic_name = 'redacted'
network_client.network_interfaces.get(GROUP_NAME, nic_name)
private_ip = nic.ip_configurations[0].private_ip_address

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
Alex Kaszynski
  • 1,817
  • 2
  • 17
  • 17

1 Answers1

0

If the requirement is to fetch all the IPs of the VMs/Network interfaces in the VMSS instance, you can use the official Azure SDK for Python as follows:

# Imports
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.network import NetworkManagementClient

# Set subscription ID
SUBSCRIPTION_ID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'


def get_credentials():
    credentials = ServicePrincipalCredentials(
        client_id='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
        secret='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
        tenant='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
    )

    return credentials


# Get credentials
credentials = get_credentials()


# Initialize management client
network_client = NetworkManagementClient(
    credentials,
    SUBSCRIPTION_ID
)


def get_vmss_vm_ips():

    # List all network interfaces of the VMSS instance
    vmss_nics = network_client.network_interfaces.list_virtual_machine_scale_set_network_interfaces(
        "<VMSS Resource group name>", "<VMSS instance name>")

    niclist = [nic.serialize() for nic in vmss_nics]

    print "IP addresses in the given VM Scale Set:"

    for nic in niclist:
        ipconf = nic['properties']['ipConfigurations']

        for ip in ipconf:
            print ip['properties']['privateIPAddress']


# Get all IPs of VMs in VMSS
get_vmss_vm_ips()

Note that the network_client.network_interfaces.get() method gets information about the specified network interface only whereas the list_virtual_machine_scale_set_network_interfaces() method fetches all network interfaces in a virtual machine scale set.

References:

Hope this helps! Please let me know if otherwise and we can explore further.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30