Getting all the properties of a vnet using python | List function only gives name

本秂侑毒 提交于 2019-12-11 15:52:21

问题


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...')

回答1:


it should be re.location instead of re.region.

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.



来源:https://stackoverflow.com/questions/56035949/getting-all-the-properties-of-a-vnet-using-python-list-function-only-gives-nam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!