python azure sdk - 列出存储帐户 SKU

python azure sdk - To list storage account SKU

我正在使用 Python3 Azure SDK。 这是当前安装的所有模块的版本详细信息。 我想使用 SDK 列出存储帐户 Types/SKU。不知道该怎么做。

azure-common (1.1.26)
azure-core (1.10.0)
azure-identity (1.5.0)
azure-keyvault-secrets (4.2.0)
azure-mgmt-compute (18.2.0)
azure-mgmt-core (1.2.2)
azure-mgmt-resource (15.0.0)
azure-mgmt-storage (16.0.0)
azure-storage-blob (12.7.1)
msrestazure (0.6.4)

Here is official link from Azure.但我想通过代码列出这些信息。

azure-mgmt-storage==16.0.0开始,在SkuOperationsclass中有一个list()方法。由于该方法将 return 每个可用区域和存储类型的多个 SKU,您可以使用集合删除重复的 SKU 名称。

from azure.mgmt.storage import StorageManagementClient
from azure.identity import DefaultAzureCredential

storage_client = StorageManagementClient(
    credential=DefaultAzureCredential(),
    subscription_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
)

skus = {sku.name for sku in storage_client.skus.list()}

print(skus)

输出以下集合:

{'Standard_GZRS', 'Standard_GRS', 'Standard_ZRS', 'Standard_RAGZRS', 'Premium_LRS', 'Premium_ZRS', 'Standard_LRS', 'Standard_RAGRS'}

如果你只是想列出这些skus,那么你可以迭代集合:

for sku in skus:
    print(sku)

在换行符上输出 SKU,如下所示:

Premium_LRS
Standard_GRS
Standard_GZRS
Premium_ZRS
Standard_LRS
Standard_RAGRS
Standard_RAGZRS
Standard_ZRS