有没有一种方法可以在蔚蓝的python sdk api中获取虚拟机的vcpu数量?

时间:2019-08-06 06:55:56

标签: python azure

如何获取python azure sdk ComputeManagementClient对象中具有的VCPU数量? 代码示例:

    from azure.mgmt.compute import ComputeManagementClient 
    compute_client = ComputeManagementClient(self.credentials, SUBSCRIPTION_ID)
    vm = compute_client.virtual_machines.get(resource_group, name, expand='instanceView')
    vm.hardware_profile.vm_size # here i have the vm type in a string

如何从该对象获取VCPU的数量?

1 个答案:

答案 0 :(得分:1)

简短的回答是。获取虚拟机大小后,即可从确切大小中获取VCPU号。此处的示例代码:

vm = compute_client.virtual_machines.get(resource_group, name, expand='instanceView')
sizeList = compute_client.virtual_machine_sizes.list(vm.location)
print(sizeList)
for size in sizeList:
    if size.name == vm.hardware_profile.vm_size:
        print(size.number_of_cores)

有关更多详细信息,请参见VirtualMachineSizesOperations class。希望对您有所帮助。