【发布时间】:2022-11-05 01:32:07
【问题描述】:
我为此使用python sdk,并希望执行将blob从一个容器移动到另一个容器,但在打破租约后也会产生租约问题。
from azure.storage.blob import BlobLeaseClient, BlobServiceClient
from app.models.remediation import RemediationRequest, RemediationType
from app.shared.azure_storage_client import AzureStorageClient
def remediate(self, remediation_request: RemediationRequest, account: dict,
file_object_metadata: dict,destination_bucket_name: str):
file_type = file_object_metadata["file_type"]
storage_client = AzureStorageClient(account_name=key, account_key=Value)
if file_object_metadata['lease']['status'] == 'locked':
connection_string = storage_client._get_connection_string()
blob_service_client =
BlobServiceClient.from_connection_string(connection_string)
container_client =
blob_service_client.get_container_client(source_bucket)
blob_client = container_client.get_blob_client(blob_name)
break_lease_result = BlobLeaseClient(blob_client).break_lease()
storage_client.move_blob(blob_name, source_bucket,
destination_bucket_name, destination_blob_name,file_type)
'''
blob should move with specify lease id else break the lease and move.
【问题讨论】:
标签: python azure azure-blob-storage azure-storage-files blobstorage