简体   繁体   English

通过databricks列出azure的存储帐户内的所有容器

[英]List down all container within a storage account of azure through databricks

I, want to dynamically get all storage account and containers within from an azure subscription by databricks.我想通过数据块从 azure 订阅中动态获取所有存储帐户和容器。
So, that I can go through each file within a container and get the files and their sizes which I have done earlier.因此,我可以通过容器中的每个文件 go 并获取我之前完成的文件及其大小。
Now I want to dynamically set my storage account and container to process with from a subscription.现在我想动态设置我的存储帐户和容器以通过订阅进行处理。

Per my experience and based on my understanding for all operations in storage account with databricks, authentication is happening in azure storage account level.根据我的经验,并根据我对使用数据块的存储帐户中的所有操作的理解,身份验证发生在 azure 存储帐户级别。 In that case, If you are trying to access storage account through service principal or storage account access key both are in storage account level, you can list out the containers within storage account.But we don't have option to list out the storage account within subscription.在这种情况下,如果您尝试通过服务主体或存储帐户访问密钥访问存储帐户都处于存储帐户级别,您可以列出存储帐户中的容器。但是我们没有列出存储帐户的选项订阅内。 As workaround, you can use powershell , to get the storage accounts within subscription and pass those value for your logic.作为解决方法,您可以使用powershell来获取订阅中的存储帐户并将这些值传递给您的逻辑。

You can use below code, to get the list of containers within storage account.您可以使用以下代码来获取存储帐户中的容器列表。

from azure.storage.blob.blockblobservice import BlockBlobService
blob_service = BlockBlobService(account_name='storageaccount', account_key='accesskey')
containers = blob_service.list_containers()
for c in containers:
    print(c.name)

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

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