Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable undelete container #13377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ def list_containers(
:param bool include_metadata:
Specifies that container metadata to be returned in the response.
The default value is `False`.
:keyword bool include_deleted:
Specifies that deleted containers to be returned in the response. This is for container restore enabled
account. The default value is `False`.
.. versionadded:: 12.4.0
:keyword int results_per_page:
The maximum number of container names to retrieve per API
call. If the request does not specify the server will return up to 5,000 items.
Expand All @@ -401,6 +405,9 @@ def list_containers(
:caption: Listing the containers in the blob service.
"""
include = ['metadata'] if include_metadata else []
include_deleted = kwargs.pop('include_deleted', None)
if include_deleted:
include.append("deleted")

timeout = kwargs.pop('timeout', None)
results_per_page = kwargs.pop('results_per_page', None)
Expand Down Expand Up @@ -557,7 +564,7 @@ def delete_container(
**kwargs)

@distributed_trace
def _undelete_container(self, deleted_container_name, deleted_container_version, new_name=None, **kwargs):
def undelete_container(self, deleted_container_name, deleted_container_version, new_name=None, **kwargs):
# type: (str, str, str, **Any) -> ContainerClient
"""Restores soft-deleted container.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ def list_containers(
:param bool include_metadata:
Specifies that container metadata to be returned in the response.
The default value is `False`.
:keyword bool include_deleted:
Specifies that deleted containers to be returned in the response. This is for container restore enabled
account. The default value is `False`.
.. versionadded:: 12.4.0
:keyword int results_per_page:
The maximum number of container names to retrieve per API
call. If the request does not specify the server will return up to 5,000 items.
Expand All @@ -355,6 +359,9 @@ def list_containers(
:caption: Listing the containers in the blob service.
"""
include = ['metadata'] if include_metadata else []
include_deleted = kwargs.pop('include_deleted', None)
if include_deleted:
include.append("deleted")
timeout = kwargs.pop('timeout', None)
results_per_page = kwargs.pop('results_per_page', None)
command = functools.partial(
Expand Down Expand Up @@ -510,7 +517,7 @@ async def delete_container(
**kwargs)

@distributed_trace_async
async def _undelete_container(self, deleted_container_name, deleted_container_version, new_name=None, **kwargs):
async def undelete_container(self, deleted_container_name, deleted_container_version, new_name=None, **kwargs):
# type: (str, str, str, **Any) -> ContainerClient
"""Restores soft-deleted container.

Expand Down
6 changes: 3 additions & 3 deletions sdk/storage/azure-storage-blob/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def test_undelete_container(self, resource_group, location, storage_account, sto
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = bsc._undelete_container(container.name, container.version,
restored_ctn_client = bsc.undelete_container(container.name, container.version,
new_name="restored" + str(restored_version))
restored_version += 1

Expand Down Expand Up @@ -774,7 +774,7 @@ def test_restore_to_existing_container(self, resource_group, location, storage_a
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
with self.assertRaises(HttpResponseError):
bsc._undelete_container(container.name, container.version,
bsc.undelete_container(container.name, container.version,
new_name=existing_container_client.container_name)

@pytest.mark.live_test_only # sas token is dynamically generated
Expand Down Expand Up @@ -804,7 +804,7 @@ def test_restore_with_sas(self, resource_group, location, storage_account, stora
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = bsc._undelete_container(container.name, container.version,
restored_ctn_client = bsc.undelete_container(container.name, container.version,
new_name="restored" + str(restored_version))
restored_version += 1

Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/tests/test_container_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ async def test_undelete_container(self, resource_group, location, storage_accoun
for container in container_list:
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
restored_ctn_client = await bsc._undelete_container(container.name, container.version,
restored_ctn_client = await bsc.undelete_container(container.name, container.version,
new_name="restoredctn" + str(restored_version))
restored_version += 1

Expand Down Expand Up @@ -841,7 +841,7 @@ async def test_restore_to_existing_container(self, resource_group, location, sto
# find the deleted container and restore it
if container.deleted and container.name == container_client.container_name:
with self.assertRaises(HttpResponseError):
await bsc._undelete_container(container.name, container.version,
await bsc.undelete_container(container.name, container.version,
new_name=existing_container_client.container_name)

@GlobalStorageAccountPreparer()
Expand Down