简体   繁体   English

python azure sdk - 列出存储帐户 SKU

[英]python azure sdk - To list storage account SKU

I am using Python3 SDK for azure.我正在为 azure 使用 Python3 SDK。 Here is version details of all the modules currently installed.这是当前安装的所有模块的版本详细信息。 I want to list the Storage Account Types/SKU using SDK.我想使用 SDK 列出存储帐户类型/SKU。 Not sure how to do it.不知道该怎么做。

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 的官方链接。 But I want to list this information via code.但我想通过代码列出这些信息。

From azure-mgmt-storage==16.0.0 , there is a list() method in the SkuOperations class.azure-mgmt-storage==16.0.0SkuOperations class 中有一个list()方法。 Since the method will return multiple skus for every region and storage kind available, you can use a set to remove duplicate SKU names.由于该方法将为每个可用的区域和存储类型返回多个 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)

Which outputs the following set:输出以下集合:

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

If you simply want to list these skus, then you can iterate the set:如果您只是想列出这些 skus,那么您可以迭代该集合:

for sku in skus:
    print(sku)

Which outputs the SKUs on newlines like so:它在换行符上输出 SKU,如下所示:

Premium_LRS
Standard_GRS
Standard_GZRS
Premium_ZRS
Standard_LRS
Standard_RAGRS
Standard_RAGZRS
Standard_ZRS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM