"Dereference" Azure Python SDK return 值中的一个子资源
"Dereference" a sub-resource in the Azure Python SDK return value
我想检索与给定网络接口关联的 public IP 地址。我需要做一些像
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
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 表示我可以调用 resource_client.resources.get_by_uid
,但 return 不是 PublicIPAddress
对象(我知道我可以调用 as_dict
它并以这种方式获取数据)。
有没有办法从 Azure 中的对象 ID 中获取适当类型的对象(在本例中为 PublicIPAddress
)(无需手动解析 ID)?
更新:
由于这个问题:public_ip_address method within NetworkManagementClient will not return values,我们无法从 PublicIPAddress
获取 IP 地址。
所以目前,您可以使用任何其他解决方法,例如:
myip = client.public_ip_addresses.get(" resource_group_name","public_ip_address_name")
print(myip.ip_address)
你可以把这行代码ip_config_id = interface[0].public_ip_address.id
改成my_public_ip_address = interface.ip_configurations[0].public_ip_address
,那么return类型就是PublicIPAddress
.
例如:
我想检索与给定网络接口关联的 public IP 地址。我需要做一些像
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
some_magic
routine, I should parse the ID (by splitting on slashes) and call client.public_ip_addresses.get()
. This question 表示我可以调用 resource_client.resources.get_by_uid
,但 return 不是 PublicIPAddress
对象(我知道我可以调用 as_dict
它并以这种方式获取数据)。
有没有办法从 Azure 中的对象 ID 中获取适当类型的对象(在本例中为 PublicIPAddress
)(无需手动解析 ID)?
更新:
由于这个问题:public_ip_address method within NetworkManagementClient will not return values,我们无法从 PublicIPAddress
获取 IP 地址。
所以目前,您可以使用任何其他解决方法,例如:
myip = client.public_ip_addresses.get(" resource_group_name","public_ip_address_name")
print(myip.ip_address)
你可以把这行代码ip_config_id = interface[0].public_ip_address.id
改成my_public_ip_address = interface.ip_configurations[0].public_ip_address
,那么return类型就是PublicIPAddress
.
例如: