How to Retrieve Public IPs of Uniform VMSS Instances Using Azure Python SDK

Udayakumar Iyappan 45 Reputation points
2025-03-27T06:11:20.9533333+00:00

I have an Azure Virtual Machine Scale Set (VMSS) deployed using Uniform Orchestration Mode. Currently, I am able to fetch the public IP addresses of the instances only via Azure CLI using the following command:


az vmss list-instance-public-ips --resource-group <RESOURCE_GROUP> --name <VMSS_NAME> --output json

However, I need to retrieve these public IPs using the Azure Python SDK instead of executing CLI commands. I have explored the azure-mgmt-compute and azure-mgmt-network libraries but haven't found a straightforward way to achieve this for Uniform VMSS instances.

My Questions:

Is there a Python SDK method that can fetch the public IPs of Uniform VMSS instances directly?

If not, is there an alternative approach using Azure SDKs to achieve this?

Any guidance or sample code would be greatly appreciated!

Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
443 questions
{count} votes

Accepted answer
  1. kobulloc-MSFT 26,721 Reputation points Microsoft Employee Moderator
    2025-03-31T16:45:07.35+00:00

    Thank you again, @Udayakumar Iyappan !

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! I've upvoted your answer but since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Answer provided by @Udayakumar Iyappan:

    Thanks for the Info @kobulloc-MSFT . I am able to retrieve the public ips of uniform vmss using the below python code.

    
    from azure.identity import DefaultAzureCredential
    from azure.mgmt.network import NetworkManagementClient
    def get_vmss_public_ips(subscription_id,resource_group_name,vmss_name):
        credential = DefaultAzureCredential()
        network_client = NetworkManagementClient(credential, subscription_id,api_version="2023-09-01")
        public_ip_address = network_client.public_ip_addresses.list_virtual_machine_scale_set_public_ip_addresses(
            resource_group_name, vmss_name
        )
        public_ips=[]
        for ip in public_ip_address:
            public_ips.append(ip.ip_address)
        logger.info("Public IPs: %s" % public_ips)
        return public_ips
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Udayakumar Iyappan 45 Reputation points
    2025-03-31T10:59:14.12+00:00

    Thanks for the Info @kobulloc-MSFT . I am able to retrieve the public ips of uniform vmss using the below python code.

    
    from azure.identity import DefaultAzureCredential
    from azure.mgmt.network import NetworkManagementClient
    def get_vmss_public_ips(subscription_id,resource_group_name,vmss_name):
        credential = DefaultAzureCredential()
        network_client = NetworkManagementClient(credential, subscription_id,api_version="2023-09-01")
        public_ip_address = network_client.public_ip_addresses.list_virtual_machine_scale_set_public_ip_addresses(
            resource_group_name, vmss_name
        )
        public_ips=[]
        for ip in public_ip_address:
            public_ips.append(ip.ip_address)
        logger.info("Public IPs: %s" % public_ips)
        return public_ips
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.