Search code examples
azure-sdk-python

How to get detailed VM Size information


I would like to use the Python Azure SDK to find the VM Sizes that support Enhanced Networking as well as AVX-512. The method I've seen so far to query information about VM Sizes is ComputeManagementClient.virtual_machine_sizes.list(region). But, the information returned doesn't include whether Enhanced Networking is supported for each VM type, or whether AVX-512 is supported.

This is an example of what one entry of virtual_machine_sizes.list provides:

{'name': 'Standard_M208ms_v2', 'numberOfCores': 208, 'osDiskSizeInMB': 1047552, 'resourceDiskSizeInMB': 4194304, 'memoryInMB': 5836800, 'maxDataDiskCount': 64}

I found on https://learn.microsoft.com/en-us/rest/api/compute/resourceskus/list that perhaps the resource skus list will provide the info I'm looking for. But, I don't see a way to use that resource skus list function in the Python SDK.

I am using version 4.0.0 of Python's azure library. Installed it via:

pip3 install -Iv azure==4.0.0

Thank you in advance for any help you can provide!


Solution

  • If you want to list azure vm resource sku with python, please refer to the following steps:

    1. Create a service principal and assign Contributor role to the sp
    az login
    #create sp and assign Contributor role at subscription level
    az ad sp create-for-rbac -n "your service principal name"
    

    enter image description here

    1. code
    from azure.mgmt.compute import ComputeManagementClient
    from azure.common.credentials import ServicePrincipalCredentials
    
    client_id = "sp appId"
    secret = "sp password"
    tenant = "sp tenant"
    credentials = ServicePrincipalCredentials(
            client_id = client_id,
            secret = secret,
            tenant = tenant
    )
    
    Subscription_Id = ''
    compute_client =ComputeManagementClient(credentials,Subscription_Id)
    resource_group_name='Networking-WebApp-AppGW-V1-E2ESSL'
    virtual_machine_scale_set_name='VMSS'
    results = compute_client.resource_skus.list(raw=True)
    resourceSkusList = [result.as_dict() for result in results]
    r=json.dumps(resourceSkusList)
    print(r)
    
    

    enter image description here

    For more details, please refer to here.