Azure VM:: 以编程方式获取虚拟机大小对应的 vcpus 和 GiB 内存

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

如何以编程方式获取与 vm 对应的虚拟机的 vcpus 和 GiB 内存 size.I 我正在使用 python 代码来获取详细信息,所以有没有 API 或 azure python sdk 可用于获取以上详细信息。

您可以使用 Python SDK 列出您所在区域的所有可用 VM 大小,并获得与您使用的相同的大小:

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)

您可以在 Python SDK 中获取有关 VM size 的更多详细信息。您可以用您的代码获得的确切内容替换该变量。