简体   繁体   English

从'VirtualNetworkPeering对象中提取返回的值

[英]Extract Returned values from 'VirtualNetworkPeering object

How Can I extract the atrribute values returned from list of peered virtual networks. 如何提取从对等虚拟网络列表中返回的atrribute值。 I executed this command and I need to extract the Network ID 我执行了此命令,我需要提取网络ID

list_all = network_client.virtual_network_peerings.list(
    GROUP_NAME,
    VNET_NAME
)

for peer in list_all: 对于list_all中的对等方:

print(peer) 打印(对等)

and I get this value for from the print above: 我从上面的打印中得到了这个值:

{'additional_properties': {'type': 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings'}, 
'id': '/subscriptions/c70b9b-efd6-497d-98d8-e1e1d497425/resourceGroups/azure-sample-group-virtual-machines/providers/Microsoft.Network/virtualNetworks/azure-sample-vnet/virtualNetworkPeerings/sample-vnetpeer', 
'allow_virtual_network_access': True, 
'allow_forwarded_traffic': True, 
'allow_gateway_transit': False, 
'use_remote_gateways': False, 
'remote_virtual_network': <azure.mgmt.network.v2018_08_01.models.sub_resource_py3.SubResource object at 0x048D6950>, 
'remote_address_space': <azure.mgmt.network.v2018_08_01.models.address_space_py3.AddressSpace object at 0x048D68D0>,
 'peering_state': 'Initiated', 
'provisioning_state': 'Succeeded',
 'name': 'sample-vnetpeer',
 'etag': 'W/"653f7f94-3c4e-4275-bfdf-0bbbd9beb6e4"'}

How can I get this value "remote_virtual_network"? 如何获得该值“ remote_virtual_network”?

'remote_virtual_network': , 'remote_address_space': 'remote_virtual_network':,'remote_address_space':

I will try this out and get back: 我将尝试一下并返回:

This command is analogous to "get-azurermvirtualnetworkpeering -ResourceGroupName -VirtualNetworkName -Name" on Azure PowerShell. 此命令类似于Azure PowerShell上的“ get-azurermvirtualnetworkpeering -ResourceGroupName -VirtualNetworkName -Name”。

remote_virtual_network you don't have one. remote_virtual_network您没有一个。 You will only get this if you have Remote Gateway enabled and the Peer will learn the IP address of the Remote (On-premise site) that you are trying to connect. 仅当启用了远程网关并且对等方将了解您尝试连接的远程(本地站点)的IP地址时,才能获得此地址。

To get this value, deploy a gateway in the Vnet and connect it to Say "Vnet-S2S-test" with a gateway deployed there as well. 要获得此值,请在Vnet中部署网关,并将其连接到也说“ Vnet-S2S-test”,同时还要在其中部署网关。

Once, the Site-to-site between the Vnets are up. 一次,Vnet之间的站点到站点启动。 You can execute the command and you should see those fields populated with the local network gateway details. 您可以执行该命令,并且应该看到填充了本地网络网关详细信息的那些字段。

My feeling is that your question is actually more a Python question than an Azure question. 我的感觉是,您的问题实际上更多是Python问题,而不是Azure问题。 Assuming in your application this field is set with values, then remote_virtual_network is a SubResource meaning it only has one attribute: id 假设在您的应用程序中,此字段设置了值,则remote_virtual_networkSubResource这意味着它仅具有一个属性: id

for peer in list_all:
    remote_virtual_network_id = peer.remote_virtual_network.id

This guy is an actual virtual network, so if you want details about it you need to get it with network_client.virtual_networks.get : https://docs.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2018_08_01.operations.virtualnetworksoperations?view=azure-python#get 这个人是一个实际的虚拟网络,因此,如果您需要有关它的详细信息,则需要使用network_client.virtual_networks.get进行获取: https : //docs.microsoft.com/zh-cn/python/api/azure-mgmt-network /azure.mgmt.network.v2018_08_01.operations.virtualnetworksoperations?view=azure-python#get

The tricky part is you get an ID, but VNet get asks for a RG name and VNet name, you can use the ARM ID parser for that: 棘手的部分是您获得一个ID,但是VNet要求提供一个RG名称和VNet名称,您可以为此使用ARM ID解析器:

https://docs.microsoft.com/en-us/python/api/msrestazure/msrestazure.tools?view=azure-python#parse-resource-id https://docs.microsoft.com/zh-cn/python/api/msrestazure/msrestazure.tools?view=azure-python#parse-resource-id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从paged.SecretItemPaged类型对象获取机密值 - How to get secret values from paged.SecretItemPaged type object 正确的 arguments 创建 DiagnosticSettingsOperations object - Correct arguments to create DiagnosticSettingsOperations object Azure Python SDK:“ServicePrincipalCredentials”对象没有“get_token”属性 - Azure Python SDK: 'ServicePrincipalCredentials' object has no attribute 'get_token' 如何通过Python Azure SDK知道Azure Blob对象的大小 - How to know the size of an Azure blob object via Python Azure SDK 使用python从外部恢复azure数据库 - Restore a azure database from outside using python 从 Python 获取 Office 365 邮箱和组 - Get Office 365 Mailboxes and Groups from Python 使用 Python Azure ServiceBus SDK 发送带有对象正文的批量消息的问题 - Issue using Python Azure ServiceBus SDK to send batch of messages with object body 从 ML 管道调用脚本时无法导入“BlockBlobService” - Cannot import 'BlockBlobService' when calling a script from ML pipeline 使用 Python 从 Azure KeyVault 下载.pfx 证书 - Download.pfx certificate from Azure KeyVault with Python 如何使用Azure Python设备SDK从设备更新设备孪生? - How to update device twin from device with Azure Python device SDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM