I'm trying to get a list of private IP addresses for all VMs in a Scale Set (none of the VMs deliberately has any public IP addresses). I've found how to get this from az cli
as follows:
az vmss nic list -g ResourceGroup --vmss-name ScaleSetName --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv
However I'm unable to get the same output using Python SDK. I am using the following basic code:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
credentials = ServicePrincipalCredentials(client_id = CLIENT, secret = KEY, tenant = TENANT)
compute_client = ComputeManagementClient(credentials, SUBSCRIPTION)
vmss = compute_client.virtual_machine_scale_sets.get(RG, SC)
print(vmss.virtual_machine_profile.network_profile.network_interface_configurations[0].ip_configurations[0])
Is this the right place in the SDK object model to look for them? From what I understand, the network properties should be at the Scale Set level, and that's the only place in the API where I see anything network-related. However, I only see 'private IP version' in the subsequent properties, and since there are no public IPs, that portion of the properties is blank.
Unfortunately, I'm afraid you cannot get the private IP of virtual machine scale set instances. The network interfaces of virtual machine scale sets are not the resources in Azure and you cannot get them. Currently, Azure python SDK does not support get the VMSS private IPs through the python SDK.
You can try to use the REST API to achieve the purpose and get the REST API via the CLI command debug like this:
az vmss nic list -g ResourceGroup --vmss-name ScaleSetName --query [].{ip:ipConfigurations[0].privateIpAddress} -o tsv --debug
It will show the progress and the REST API: