代码之家  ›  专栏  ›  技术社区  ›  RAC

在azure python SDK中,powershell AzStorageAccount是否有等效的类或模块?

  •  0
  • RAC  · 技术社区  · 3 年前

    我目前正在使用azure python SDK将Powershell脚本转换为python脚本。是否有等效的类或模块 AzStorageAccount 使用azure-python-sdk获取blob-url列表?我查了一下图书馆azure.mngt.storage没有给我提供我需要的信息。

    1 回复  |  直到 3 年前
        1
  •  1
  •   Jeremy Caney Abloin    3 年前

    我能够通过使用 azure.mgmt.storage 这个 storageManagementClient 有一个方法( storage_accounts.list() )将列出所有存储帐户。在检查返回的数据后,我发现它还将为每个帐户提供blob URL。

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.storage import StorageManagementClient
    
    storage_client = StorageManagementClient(credential=DefaultAzureCredential(), subscription_id=subscription_id)
    storage_accounts = storage_client.storage_accounts.list()
       
    # Get a list of all storage accounts in the subscription
    for account in storage_accounts:
        blob_url = account.primary_endpoints.blob
    
        2
  •  0
  •   Gaurav Mantri    3 年前

    您要用于处理存储在Azure Blob存储中的数据的程序包是 azure-storage-blob ( https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python )。 azure.mngt.storage 是用于管理存储帐户本身的SDK,不提供数据管理功能。

    代码如下:

    from azure.identity import DefaultAzureCredential
    from azure.storage.blob import BlobServiceClient
    
    account_url = "https://<storageaccountname>.blob.core.windows.net"
    default_credential = DefaultAzureCredential()
    
    blob_service_client = BlobServiceClient(account_url, credential=default_credential)
    container_client = blob_service_client.get_container_client(container_name)
    blob_list = container_client.list_blobs()
    for blob in blob_list:
        print("\t" + blob.name)
    

    您可以在此处找到更多代码示例: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/storage/azure-storage-blob/samples 。