-
Notifications
You must be signed in to change notification settings - Fork 162
feat: add turbo replication support and samples #622
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
edeb027
feat: add turbo replication support
c036053
lintfix
e743002
nother-lint-fix
2de90a5
hmm weird
8fa18a4
i need to learn how to use lint better...
b276aab
.
896ce91
.
1032084
how about now?
1f2a347
take rpo out of constructor
d046b1f
add unit tests
57f5df7
add link to docs
0ab5ce8
ensure inclusion of "rpo" in bucket._changes
f8078f5
Merge branch 'main' into rpo-changes
6dddfe2
add rpo samples
b43e04f
lint it
01cf60e
Merge branch 'main' into rpo-changes
325e5eb
address cathys nits
93c2af6
fix a little test thing
81ba4fc
Merge branch 'main' into rpo-changes
cc2ed6e
Merge branch 'main' into rpo-changes
d258f0a
Merge branch 'main' into rpo-changes
d671e4b
start to fix weirdness, creating issue to address more fully
0e288d4
Merge branch 'rpo-changes' of github.com:Breathtender/python-storage …
5d28895
Merge branch 'main' into rpo-changes
e6595b0
change it back
ec6d003
Merge branch 'rpo-changes' of github.com:Breathtender/python-storage …
feced15
Merge branch 'main' into rpo-changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import uuid | ||
|
||
from google.cloud import storage | ||
import pytest | ||
|
||
import storage_create_bucket_turbo_replication | ||
import storage_get_rpo | ||
import storage_set_rpo_async_turbo | ||
import storage_set_rpo_default | ||
|
||
|
||
@pytest.fixture | ||
def dual_region_bucket(): | ||
"""Yields a dual region bucket that is deleted after the test completes.""" | ||
bucket = None | ||
while bucket is None or bucket.exists(): | ||
unforced marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bucket_name = "bucket-lock-{}".format(uuid.uuid4()) | ||
bucket = storage.Client().bucket(bucket_name) | ||
bucket.location = "NAM4" | ||
bucket.create() | ||
yield bucket | ||
bucket.delete(force=True) | ||
|
||
|
||
def test_get_rpo(dual_region_bucket, capsys): | ||
storage_get_rpo.get_rpo(dual_region_bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert f"RPO for {dual_region_bucket.name} is DEFAULT." in out | ||
|
||
|
||
def test_set_rpo_async_turbo(dual_region_bucket, capsys): | ||
storage_set_rpo_async_turbo.set_rpo_async_turbo(dual_region_bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert f"RPO is ASYNC_TURBO for {dual_region_bucket.name}." in out | ||
|
||
|
||
def test_set_rpo_default(dual_region_bucket, capsys): | ||
storage_set_rpo_default.set_rpo_default(dual_region_bucket.name) | ||
out, _ = capsys.readouterr() | ||
assert f"RPO is DEFAULT for {dual_region_bucket.name}." in out | ||
|
||
|
||
def test_create_bucket_turbo_replication(capsys): | ||
bucket_name = "test-rpo-{}".format(uuid.uuid4()) | ||
storage_create_bucket_turbo_replication.create_bucket_turbo_replication(bucket_name) | ||
out, _ = capsys.readouterr() | ||
assert f"{bucket_name} created with RPO ASYNC_TURBO in NAM4." in out |
48 changes: 48 additions & 0 deletions
48
samples/snippets/storage_create_bucket_turbo_replication.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
"""Sample that creates a new bucket with dual-region and turbo replication. | ||
This sample is used on this page: | ||
https://cloud.google.com/storage/docs/managing-turbo-replication | ||
For more information, see README.md. | ||
""" | ||
|
||
# [START storage_create_bucket_turbo_replication] | ||
|
||
from google.cloud import storage | ||
from google.cloud.storage.constants import RPO_ASYNC_TURBO | ||
|
||
|
||
def create_bucket_turbo_replication(bucket_name): | ||
"""Creates dual-region bucket with turbo replication enabled.""" | ||
# The ID of your GCS bucket | ||
# bucket_name = "my-bucket" | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(bucket_name) | ||
bucket.location = "NAM4" | ||
bucket.rpo = RPO_ASYNC_TURBO | ||
bucket.create() | ||
|
||
print(f"{bucket.name} created with RPO {bucket.rpo} in {bucket.location}.") | ||
|
||
|
||
# [END storage_create_bucket_turbo_replication] | ||
|
||
if __name__ == "__main__": | ||
create_bucket_turbo_replication(bucket_name=sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
"""Sample that gets RPO (Recovery Point Objective) of a bucket | ||
This sample is used on this page: | ||
https://cloud.google.com/storage/docs/managing-turbo-replication | ||
For more information, see README.md. | ||
""" | ||
|
||
# [START storage_get_rpo] | ||
|
||
from google.cloud import storage | ||
from google.cloud.storage.constants import RPO_DEFAULT | ||
|
||
|
||
def get_rpo(bucket_name): | ||
"""Gets the RPO of the bucket""" | ||
# The ID of your GCS bucket | ||
# bucket_name = "my-bucket" | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(bucket_name) | ||
|
||
bucket.rpo = RPO_DEFAULT | ||
rpo = bucket.rpo | ||
|
||
print(f"RPO for {bucket.name} is {rpo}.") | ||
|
||
|
||
# [END storage_get_rpo] | ||
|
||
if __name__ == "__main__": | ||
get_rpo(bucket_name=sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
"""Sample that sets RPO (Recovery Point Objective) to ASYNC_TURBO | ||
This sample is used on this page: | ||
https://cloud.google.com/storage/docs/managing-turbo-replication | ||
For more information, see README.md. | ||
""" | ||
|
||
# [START storage_set_rpo_async_turbo] | ||
|
||
from google.cloud import storage | ||
from google.cloud.storage.constants import RPO_ASYNC_TURBO | ||
|
||
|
||
def set_rpo_async_turbo(bucket_name): | ||
"""Sets the RPO to ASYNC_TURBO, enabling the turbo replication feature""" | ||
# The ID of your GCS bucket | ||
# bucket_name = "my-bucket" | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(bucket_name) | ||
|
||
bucket.rpo = RPO_ASYNC_TURBO | ||
bucket.patch() | ||
|
||
print(f"RPO is ASYNC_TURBO for {bucket.name}.") | ||
|
||
|
||
# [END storage_set_rpo_async_turbo] | ||
|
||
if __name__ == "__main__": | ||
set_rpo_async_turbo(bucket_name=sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
|
||
"""Sample that sets RPO (Recovery Point Objective) to default | ||
This sample is used on this page: | ||
https://cloud.google.com/storage/docs/managing-turbo-replication | ||
For more information, see README.md. | ||
""" | ||
|
||
# [START storage_set_rpo_default] | ||
|
||
from google.cloud import storage | ||
from google.cloud.storage.constants import RPO_DEFAULT | ||
|
||
|
||
def set_rpo_default(bucket_name): | ||
"""Sets the RPO to DEFAULT, disabling the turbo replication feature""" | ||
# The ID of your GCS bucket | ||
# bucket_name = "my-bucket" | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(bucket_name) | ||
|
||
bucket.rpo = RPO_DEFAULT | ||
bucket.patch() | ||
|
||
print(f"RPO is DEFAULT for {bucket.name}.") | ||
|
||
|
||
# [END storage_set_rpo_default] | ||
|
||
if __name__ == "__main__": | ||
set_rpo_default(bucket_name=sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.