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

feat: add turbo replication support and samples #622

Merged
merged 27 commits into from Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions google/cloud/storage/bucket.py
Expand Up @@ -55,6 +55,8 @@
from google.cloud.storage.constants import REGIONAL_LEGACY_STORAGE_CLASS
from google.cloud.storage.constants import REGION_LOCATION_TYPE
from google.cloud.storage.constants import STANDARD_STORAGE_CLASS
from google.cloud.storage.constants import RPO_DEFAULT
from google.cloud.storage.constants import RPO_ASYNC_TURBO
from google.cloud.storage.notification import BucketNotification
from google.cloud.storage.notification import NONE_PAYLOAD_FORMAT
from google.cloud.storage.retry import DEFAULT_RETRY
Expand Down Expand Up @@ -633,6 +635,25 @@ def _set_properties(self, value):
self._label_removals.clear()
return super(Bucket, self)._set_properties(value)

@property
def rpo(self):
"""Get the RPO (Recovery Point Objective) of this bucket

unforced marked this conversation as resolved.
Show resolved Hide resolved
"ASYNC_TURBO" or "DEFAULT"
:rtype: str
"""
return self._properties.get("rpo")

@rpo.setter
def rpo(self, value):
"""
Set the RPO (Recovery Point Objective) of this bucket.

:type value: str
:param value: "ASYNC_TURBO" or "DEFAULT"
"""
self._patch_property("rpo", value)

@property
def user_project(self):
"""Project ID to be billed for API requests made via this bucket.
Expand Down
4 changes: 4 additions & 0 deletions google/cloud/storage/client.py
Expand Up @@ -832,6 +832,7 @@ def create_bucket(
location=None,
predefined_acl=None,
predefined_default_object_acl=None,
rpo=None,
timeout=_DEFAULT_TIMEOUT,
retry=DEFAULT_RETRY,
):
Expand Down Expand Up @@ -953,6 +954,9 @@ def create_bucket(
if location is not None:
properties["location"] = location

if rpo is not None:
properties["rpo"] = rpo

unforced marked this conversation as resolved.
Show resolved Hide resolved
api_response = self._post_resource(
"/b",
properties,
Expand Down
12 changes: 12 additions & 0 deletions google/cloud/storage/constants.py
Expand Up @@ -117,3 +117,15 @@

See: https://cloud.google.com/storage/docs/public-access-prevention
"""

RPO_ASYNC_TURBO = "ASYNC_TURBO"
"""Turbo Replication RPO

See: https://cloud.google.com/storage/docs/managing-turbo-replication
"""

RPO_DEFAULT = "DEFAULT"
"""Default RPO

See: https://cloud.google.com/storage/docs/managing-turbo-replication
"""
18 changes: 18 additions & 0 deletions tests/system/test_bucket.py
Expand Up @@ -886,3 +886,21 @@ def test_new_bucket_created_w_enforced_pap(
constants.PUBLIC_ACCESS_PREVENTION_INHERITED,
]
assert not bucket.iam_configuration.uniform_bucket_level_access_enabled

def test_new_bucket_with_rpo(
storage_client, buckets_to_delete, blobs_to_delete,
):
from google.cloud.storage import constants

bucket_name = _helpers.unique_name("new-w-turbo-replication")
bucket = storage_client.create_bucket(bucket_name, location="NAM4", rpo=constants.RPO_ASYNC_TURBO)
buckets_to_delete.append(bucket)

assert bucket.rpo == constants.RPO_ASYNC_TURBO

bucket.rpo = constants.RPO_DEFAULT
bucket.patch()

bucket_from_server = storage_client.get_bucket(bucket_name)

assert bucket_from_server.rpo == constants.RPO_DEFAULT