1
votes

We are trying to list all available sizes for particular location using the API "GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/vmSizes?api-version=2017-12-01". It returns nearly 22400 sizes. Is it really contains this many sizes under some region? Is there any elegant way to get VM sizes based on type.

For Example:
    1. Get VM sizes based on General purpose, Memory optimized, Storage optimized etc.
    2. Get VM Sizes  based on RAM size, CPU count etc.
1
Do you mean by using the Azure Python SDK? I don't understand why this question is tag with python-2.7?juvchan
Yes. I need any way to get this by using Direct AzureRM API or Python SDK as well.sangeeth kumar
Example 1: This is not possible. General purpose, Memory optimized, Storage optimized This is just easy for you to find suitable VM. VM does not have this parameter.Shui shengbao
Example 2: This is also impossible.Shui shengbao

1 Answers

1
votes

I used the sample posted by Laurent (link below) and it returned all available VM sizes' names, cores, disks, memory, etc. in the region (use parm location=region). If you put some code around it you should be able to do example 2.

Get Virtual Machine sizes list in json format using azure-sdk-for-python

def list_available_vm_sizes(compute_client, region = 'EastUS2', minimum_cores = 1, minimum_memory_MB = 768):
    vm_sizes_list = compute_client.virtual_machine_sizes.list(location=region)
    for vm_size in vm_sizes_list:
        if vm_size.number_of_cores >= int(minimum_cores) and vm_size.memory_in_mb >= int(minimum_memory_MB): 
            print('Name:{0}, Cores:{1}, OSDiskMB:{2}, RSDiskMB:{3}, MemoryMB:{4}, MaxDataDisk:{5}'.format(
                vm_size.name,
                vm_size.number_of_cores,
                vm_size.os_disk_size_in_mb,
                vm_size.resource_disk_size_in_mb,
                vm_size.memory_in_mb,
                vm_size.max_data_disk_count
            ))

list_available_vm_sizes(compute_client, region = 'EastUS', minimum_cores = 2, minimum_memory_MB = 8192)