I have a virtual machine scale set and I have two VMs attached to it and I want to fetch its public IP address with the Python SDK.
I am using this script to fetch IP configurations.
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(
rg, vmscalesetname)
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']
print ipconf
This is my output:
{'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Compute/virtualMachineScaleSets/EchoServer/virtualMachines/2/networkInterfaces/test-vnet-nic01/ipConfigurations/test-vnet-nic01-defaultIpConfiguration', 'properties': {'subnet': {'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/default'}, 'privateIPAddressVersion': u'IPv4', 'publicIPAddress': {'id': u'/subscriptions/sub_id/resourceGroups/test/providers/Microsoft.Compute/virtualMachineScaleSets/EchoServer/virtualMachines/2/networkInterfaces/test-vnet-nic01/ipConfigurations/test-vnet-nic01-defaultIpConfiguration/publicIPAddresses/publicIp-test-vnet-nic01'}, 'privateIPAllocationMethod': u'Dynamic', 'primary': True, 'privateIPAddress': u'10.0.0.9'}, 'name': u'test-vnet-nic01-defaultIpConfiguration'}]
I can see privateIPAddress
, but not publicIPAddress
. How do I fetch the public IP address?
If you want to the Azure scale set virtual machines' public IP address, please refer to the following script
Create a service principal and assign
Contributor
role to the service principalCode