使用python获取vnet的所有属性|列表功能仅给出名称 [英] Getting all the properties of a vnet using python | List function only gives name

查看:64
本文介绍了使用python获取vnet的所有属性|列表功能仅给出名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此,我想先获得一个vnet的region属性,但是使用list函数,它只提供了name属性.我们是否必须使用另一个函数来获取全部详细信息?目前,我无法进行re.region.它仅适用于re.name

Thanks in advance, I wanted to get the region property of a vnet but using list function it only gives name property. Do we have to use another function to get the full details? currently i cannot do re.region. it only works with re.name

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.compute import ComputeManagementClient
from azure.mgmt.network import NetworkManagementClient
from azure.mgmt.compute.models import DiskCreateOption
from azure.mgmt.network.v2017_03_01.models import NetworkSecurityGroup
from azure.mgmt.network.v2017_03_01.models import SecurityRule
import azure.mgmt.network.models

SUBSCRIPTION_ID = 'xxxx'
GROUP_NAME = 'AQRG'
LOCATION = ''
VM_NAME = 'myVM'
VNET_NAME = ''
SUBNET = ''

def List_VNET(network_client):
    result_create = network_client.virtual_networks.list(
            GROUP_NAME,
        )
    global VNET_NAME
    for re in result_create:
        VNET_NAME = re.name
        Region = re.region // This is not valid
    return VNET_NAME



def get_credentials():
    credentials = ServicePrincipalCredentials(
        client_id = 'xxx',
        secret = 'xxx',
        tenant = 'xxxx'
    )
return credentials


if __name__ == "__main__":
    credentials = get_credentials()

resource_group_client = ResourceManagementClient(
    credentials, 
    SUBSCRIPTION_ID
)
network_client = NetworkManagementClient(
    credentials, 
    SUBSCRIPTION_ID
)
compute_client = ComputeManagementClient(
    credentials, 
    SUBSCRIPTION_ID
)


creation_result_listvnet = List_VNET(network_client)
print("------------------------------------------------------")
print(creation_result_listvnet)
input('Press enter to continue...')

推荐答案

它应该是 re.location ,而不是 re.region .

,我刚刚发现您可以使用 print(re)获取虚拟网络的所有属性.然后,您可以在输出中使用任何属性.

and I just found that you can fetch all the properties of virtual network with print(re). Then you can use any properties in the output.

仅供参考:

FYI: The doc of VirtualNetwork class, which lists the properties.

这篇关于使用python获取vnet的所有属性|列表功能仅给出名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆