微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure:使用 Python 脚本在 virtual_network 类中检索“address_space”

如何解决Azure:使用 Python 脚本在 virtual_network 类中检索“address_space”

我正在尝试创建一个脚本,该脚本将检索 Azure 中特定 VNET 的所有详细信息。下面是我的python脚本:

from azure.identity import AzureCliCredential
from azure.mgmt.network import NetworkManagementClient

subscription_id = input("Enter the subscription ID where VNET is located: ")
rg_name = input("Enter the resource group where VNET is located: ")
vnet_name = input("Enter the VNET name: ")

credential = AzureCliCredential()
network_client = NetworkManagementClient(credential,subscription_id)

vnet = network_client.virtual_networks.get(rg_name,vnet_name)
print(vnet)

下面是输出

{'additional_properties': {},'id': 'XXXXXXXXX','name': 'XXXXXXXXX','type': 'Microsoft.Network/virtualNetworks','location': 'southeastasia','tags': {'owner': 'test','dept': 'test-dept'},'extended_location': None,'etag': 'XXXXXXXXX','address_space': <azure.mgmt.network.v2021_02_01.models._models_py3.Addressspace object at 0x000002BC6E1F3C40>,'dhcp_options': None,'flow_timeout_in_minutes': None,'subnets': [<azure.mgmt.network.v2021_02_01.models._models_py3.subnet object at 0x000002BC6E1F3C70>,<azure.mgmt.network.v2021_02_01.models._models_py3.subnet object at 0x000002BC6E1F3CA0>,<azure.mgmt.network.v2021_02_01.models._models_py3.subnet object at 0x000002BC6E1F3CD0>],'virtual_network_peerings': [],'resource_guid': 'XXXXXXXXX','provisioning_state': 'Succeeded','enable_ddos_protection': False,'enable_vm_protection': None,'ddos_protection_plan': None,'bgp_communities': None,'ip_allocations': None}

如您所见,它显示 'address_space': 而不是 IP 地址。

我尝试使用以下方法导入地址空间:

from azure.mgmt.network.v2021_02_01.models._models_py3 import Addressspace

但我似乎无法弄清楚它是如何工作的。

解决方法

我认为我们只需要玩 Apex Legends 并达到 Predator 等级,然后此代码就可以工作了。

,

代码没问题,你需要做的是像这样深入探索地址空间属性:

address_space = vnet.address_space.address_prefixes
print(address_space)

获取更多关于网络get函数返回信息的详细信息here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。