I would like to retrieve the public IP address associated with a given network interface. I need to do something like
client = NetworkManagementClient(...)
interface = client.network_interfaces.get('rg', 'nic-name')
ip_config_id = interface[0].public_ip_address.id
ip_config = some_magic(ip_config_id) # What goes here?
return ip_config.ip_address
This question suggests that in order to implement the some_magic
routine, I should parse the ID (by splitting on slashes) and call client.public_ip_addresses.get()
. This question indicates that I can call resource_client.resources.get_by_uid
, but that doesn't return a PublicIPAddress
object (I know I can call as_dict
on it and get the data that way).
Is there a way to get an object of the appropriate type (in this case PublicIPAddress
) from an object's ID in Azure (without manually parsing the ID)?
Update:
Due to this issue: public_ip_address method within NetworkManagementClient will not return values, we cannot fetch the ip address from
PublicIPAddress
.So currently, you can use any other workaround, For example:
You can change this line of code
ip_config_id = interface[0].public_ip_address.id
to something likemy_public_ip_address = interface.ip_configurations[0].public_ip_address
, then the return type isPublicIPAddress
.For example: