【发布时间】:2020-04-20 08:01:59
【问题描述】:
有人知道如何使用 Python SDK 获取区域信息吗?我发现this technet 帖子向您展示了如何使用 powershell 按区域转储支持的机器类型,Azure 命令行工具等效似乎如下:
user@server:~$ az vm list-skus -l southeastasia --zone | wc -l
12350
user@server:~$ az vm list-skus -l southeastasia --zone | head -n 120 | grep family -A 18
"family": "standardNVFamily",
"kind": null,
"locationInfo": [
{
"location": "southeastasia",
"zoneDetails": [],
"zones": [
"3"
]
}
],
"locations": [
"southeastasia"
],
"name": "Standard_NV6",
"resourceType": "virtualMachines",
"restrictions": [],
"size": "NV6",
"tier": "Standard"
user@server:~$
但是在翻阅文档很长一段时间后,我还没有找到合适的 SDK 方法。
compute_client.virtual_machine_images.list_skus() 不返回区域信息,仅返回图像,例如
{
'additional_properties': {
'properties': {
'automaticOSUpgradeProperties': {
'automaticOSUpgradeSupported': False
}
}
},
'id': '/Subscriptions/f03687b3-57b3-43c9-9734-6fb36e0de268/Providers/Microsoft.Compute/Locations/southeastasia/Publishers/Debian/ArtifactTypes/VMImage/Offers/debian-10/Skus/10-backports',
'name': '10-backports',
'location': 'southeastasia',
'tags': None
}
使用 AWS 开发工具包非常简单:
boto3.client('ec2').describe_availability_zones()
【问题讨论】:
-
关于问题,请尝试使用代码
results=compute_client.resource_skus.list()。更多详情请参考docs.microsoft.com/en-us/python/api/azure-mgmt-compute/… -
您还有其他顾虑吗?如果您没有其他顾虑,可以请accept the answer吗?它可能会帮助更多的人。
-
嗨,Jim 感谢您的回答,但代码不太好用(NameError: name 'location' is not defined),您是说这个吗?
if(result.resource_type=='virtualMachines' and result.locations[0].lower() == result.location_info[0].location.lower() ):result.location_info[0].location 始终等于 result.locations[0] ,因此无需归档。如果有人感兴趣,我还使用len(result.location_info[0].zones) > 0获取冗余区域,并使用result.location_info[0].location.lower().endswith('euap')过滤早期更新访问计划图像。 -
我犯了一个错误。我们需要手动提供位置。对此感到抱歉。更多详情请参考我的更新。
标签: python azure azure-virtual-machine