Skip to content

feat(storagecontrol): Added samples for Anywhere Cache#14021

Draft
nidhiii-27 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
nidhiii-27:feat-storagecontrol-anywhere-cache-samples-7716475408764255585
Draft

feat(storagecontrol): Added samples for Anywhere Cache#14021
nidhiii-27 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
nidhiii-27:feat-storagecontrol-anywhere-cache-samples-7716475408764255585

Conversation

@nidhiii-27
Copy link
Copy Markdown
Contributor

Implemented 7 new code samples for Google Cloud Storage Anywhere Cache:

  • create_anywhere_cache.py
  • get_anywhere_cache.py
  • list_anywhere_cache.py
  • update_anywhere_cache.py
  • pause_anywhere_cache.py
  • resume_anywhere_cache.py
  • disable_anywhere_cache.py

Updated snippets_test.py with integration tests for these samples. Added required copyright headers and LRO blocking comments. Ensured other files in storagecontrol/ remain unchanged.

Implemented 7 new code samples for Google Cloud Storage Anywhere Cache:
- create_anywhere_cache.py
- get_anywhere_cache.py
- list_anywhere_cache.py
- update_anywhere_cache.py
- pause_anywhere_cache.py
- resume_anywhere_cache.py
- disable_anywhere_cache.py

Updated snippets_test.py with integration tests for these samples.
Added required copyright headers and LRO blocking comments.
Ensured other files in storagecontrol/ remain unchanged.

Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 9, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a suite of Python scripts for managing Google Cloud Storage Anywhere Cache resources, including operations for creation, retrieval, listing, updating, pausing, resuming, and disabling. It also includes integration tests for these new features. The reviewer provided several actionable suggestions to improve the code, such as using client-provided path helper methods for resource name construction to ensure consistency and maintainability. Additionally, the feedback identifies potential IndexError bugs in command-line argument handling and recommends moving documentation snippet tags to include necessary imports.

Comment on lines +37 to +38
project_path = client.common_project_path("_")
bucket_path = f"{project_path}/buckets/{bucket_name}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is recommended to use the client's built-in path helper methods instead of manually constructing resource names with f-strings. This ensures the resource name follows the correct pattern and is more maintainable.

Suggested change
project_path = client.common_project_path("_")
bucket_path = f"{project_path}/buckets/{bucket_name}"
bucket_path = client.bucket_path("_", bucket_name)

Comment on lines +62 to +64
create_anywhere_cache(
bucket_name=sys.argv[1], zone=sys.argv[2], admission_policy=sys.argv[3]
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation will raise an IndexError if the optional admission_policy argument is not provided on the command line. Using *sys.argv[1:] allows the function to use its default value when the third argument is missing.

    create_anywhere_cache(*sys.argv[1:])

Comment on lines +32 to +33
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the client's path helper methods is preferred over manual string concatenation for resource names. This improves readability and reduces the risk of errors in the resource path structure.

Suggested change
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
name = client.anywhere_cache_path("_", bucket_name, zone)

Comment on lines +32 to +33
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the anywhere_cache_path helper method provided by the client to construct the resource name. This is a best practice for Google Cloud client library samples.

Suggested change
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
name = client.anywhere_cache_path("_", bucket_name, zone)

Comment on lines +29 to +30
project_path = client.common_project_path("_")
bucket_path = f"{project_path}/buckets/{bucket_name}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The client provides a bucket_path helper method which is cleaner and more robust than manual f-string construction for the parent resource path.

Suggested change
project_path = client.common_project_path("_")
bucket_path = f"{project_path}/buckets/{bucket_name}"
bucket_path = client.bucket_path("_", bucket_name)

Comment on lines +32 to +33
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the anywhere_cache_path helper method is recommended for constructing the resource name, ensuring consistency across samples and adherence to client library best practices.

Suggested change
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
name = client.anywhere_cache_path("_", bucket_name, zone)

Comment on lines +32 to +33
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is better to use the anywhere_cache_path helper method to build the resource name instead of manual string formatting.

Suggested change
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
name = client.anywhere_cache_path("_", bucket_name, zone)

Comment on lines +17 to +20
from google.cloud import storage_control_v2
from google.protobuf import field_mask_pb2

# [START storage_control_update_anywhere_cache]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The snippet start tag should be placed before the imports required by the sample. This ensures that when the snippet is displayed in documentation, users can see all the necessary imports to run the code.

Suggested change
from google.cloud import storage_control_v2
from google.protobuf import field_mask_pb2
# [START storage_control_update_anywhere_cache]
# [START storage_control_update_anywhere_cache]
from google.cloud import storage_control_v2
from google.protobuf import field_mask_pb2

Comment on lines +39 to +40
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the anywhere_cache_path helper method from the client to construct the resource name for the update request.

Suggested change
project_path = client.common_project_path("_")
name = f"{project_path}/buckets/{bucket_name}/anywhereCaches/{zone}"
name = client.anywhere_cache_path("_", bucket_name, zone)

Comment on lines +67 to +69
update_anywhere_cache(
bucket_name=sys.argv[1], zone=sys.argv[2], admission_policy=sys.argv[3]
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The script will crash with an IndexError if only two arguments are provided. Using *sys.argv[1:] allows the function to correctly use its default value for the optional admission_policy parameter.

    update_anywhere_cache(*sys.argv[1:])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant