Search code examples
azureazure-sdk-pythonazure-rest-api

Azure VM:: Programmatically how to get vcpus and GiB memory of the virtual machine corresponding to a vm size


Programmatically how to get vcpus and GiB memory of the virtual machine corresponding to a vm size.I am using python code to get the details,so is there any API or azure python sdk available to get above details.


Solution

  • You can use the Python SDK to list all the available VM size in your region and get the same one as you use:

    region = "xxxx"
    current_vmSize = "xxxxx"
    compute_client = ComputeManagementClient(credential, subscription_Id)
    vmSizes = compute_client.virtual_machine_sizes.list(region)
    for vmSize in vmSizes:
      if vmSize.name == current_vmSize:
        print("vCPU: ", vmSize.number_of_cores)
        print("memory: ", vmSize.memory_in_mb)
    

    You can get more details about the VM size in the Python SDK. And you can replace the variable with the exact thing that you get with your code.