-
Notifications
You must be signed in to change notification settings - Fork 0
Feat(StorageControl): Add samples for anywhereCache #31
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
base: main
Are you sure you want to change the base?
Changes from 15 commits
4578cbf
aa7fbe7
f6b7e86
1505099
b196c26
3ccb3b8
e59bd09
f48c666
7cd535a
b61324d
8138f9f
cba6a60
4fa2563
e9aedb5
6943d60
656f770
798abb2
5ce4a63
2be8c1b
ffbf603
9f87877
e0dfa6d
633e9f4
92586cb
18804b8
8b8cc51
71e501c
91d6629
9ff183e
bbbbdc5
8ca1a45
82b75d6
04ea966
f5576d3
1bfc026
8ac6ff9
3269771
d966e95
c2ed6f2
2c13084
e1a3e99
2e30b2a
dcaefc4
d75a7f4
6d1670d
96c1532
e2d4416
84c9db2
09815f1
5c326aa
2e7505a
75c5ea3
c91603b
283abf4
53d4ba0
e0384db
47a7f8b
6971fd0
17df145
d03a097
493f896
d9eeec0
024aeb4
48b29ca
669bf99
557a156
35f086c
27389bd
7848fe6
966af76
b679466
01f4e61
81a9a0b
fe48be0
1d18a01
859ae73
80e4f19
73361bb
d8d1601
21bf8b9
78bad51
5956cea
9acd791
c5c91ce
fcd49c1
7853580
0f2ed67
0036d52
02f2cbe
78b7a33
e8c98ea
bd92fec
56fd12b
78fd8b8
99c8586
4d5258f
0bcc5b7
79d3ded
469ce73
31d400f
4827355
f9dc2eb
b6d6296
a0585e6
36a38bb
20c15d9
64f4bbd
3c5a040
ce7e966
66219cc
1d9cc0d
4e8d3e4
77bd77c
be39ffb
a10a43e
419d676
39b5718
7e8b77e
5ca5770
58c17cd
d156aed
9f32e83
39c1e6c
27c7ae0
a529563
cfc588e
030b3b3
0d94638
f572649
447b06a
a66442a
87f8062
1058817
9f607a9
44bb0b4
a263f6c
40f296a
29972f6
cfff82f
012e660
7b90704
e2723d9
0099e9b
a191f78
eca51b6
22ed038
11e07ff
c00e9d6
5e46908
c85c8b3
7fc002f
4bb034c
f1f6d0a
734b7de
867b528
cce085f
ed8fb11
8798c55
60b26f8
c6af2dd
fc540d2
ffd6d67
dcf3344
2682b6e
0012df8
4b355e9
941e645
87b6a79
b398da0
f420245
a900296
b457a12
3fe9fce
429358a
cdda158
9bbe5cc
4653449
005d66c
e45aa84
43d694b
f6b9e82
5c83142
9064fae
18041ee
e634dcf
638b7a2
b1dedf3
dde4a45
495714f
6fdd243
4293e17
7bb560f
f608133
b9ddfa2
a4da85f
41c44ed
a82eef3
fec04b3
5cbdc9d
4e0b1fc
581e284
4830186
164ee00
5eb9066
8c1f4a7
dd2a595
fba45b4
36ec077
5420634
eb0b0e4
912312d
274d427
4081d5c
049e9b7
bdd3d7e
345fd0e
0f80212
d2290cb
36c2334
5441e0d
9437852
44e93e0
1b337ca
268ed2f
ac3634f
e7e8d4a
e083d1e
7902d02
497d2c2
69255dd
682f39e
c12f635
fd9dacc
9cb5828
242674d
bf2b4f6
75f2613
fcd2e2f
0ab16b7
4e428eb
c52b1bb
7cf3dbf
55a4c06
f3c206e
7501c62
3a80950
10ba20d
84745ee
f75dedf
f880819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_create_anywhere_cache] | ||
| def create_anywhere_cache bucket_name:, zone: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # Zone where you want to create cache | ||
| # zone = "your-zone-name" | ||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{zone}" | ||
|
|
||
| anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( | ||
| name: name, | ||
| zone: zone | ||
| ) | ||
|
|
||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::CreateAnywhereCacheRequest.new( | ||
| parent: parent, | ||
| anywhere_cache: anywhere_cache | ||
| ) | ||
| # The request creates a new cache in the specified zone. | ||
| # The cache is created in the specified bucket. | ||
| # Call the create_anywhere_cache method. | ||
| result = storage_control_client.create_anywhere_cache request | ||
|
|
||
| if result.instance_of? Gapic::Operation | ||
| puts "AnywhereCache created - #{result.name}" | ||
| else | ||
| puts "operation failed" | ||
| end | ||
| end | ||
| # [END storage_control_create_anywhere_cache] | ||
| create_anywhere_cache bucket_name: ARGV.shift, zone: ARGV.shift if $PROGRAM_NAME == __FILE__ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_disable_anywhere_cache] | ||
| def disable_anywhere_cache bucket_name:, anywhere_cache_id: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # A value that, along with the bucket's name, uniquely identifies the cache | ||
| # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache | ||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" | ||
|
|
||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::DisableAnywhereCacheRequest.new( | ||
| name: name | ||
| ) | ||
| # The request disables the cache, but does not delete it. | ||
| # The cache can be re-enabled later. | ||
| # Call the disable_anywhere_cache method. | ||
| result = storage_control_client.disable_anywhere_cache request | ||
| puts "AnywhereCache #{result.name} #{result.state}" | ||
| end | ||
| # [END storage_control_disable_anywhere_cache] | ||
| disable_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_get_anywhere_cache] | ||
| def get_anywhere_cache bucket_name:, anywhere_cache_id: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # A value that, along with the bucket's name, uniquely identifies the cache | ||
| # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache | ||
|
||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" | ||
|
|
||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::GetAnywhereCacheRequest.new( | ||
| name: name | ||
| ) | ||
| # The request retrieves the cache in the specified bucket. | ||
| # The cache is identified by the specified ID. | ||
| # The cache is in the specified bucket. | ||
| # Call the get_anywhere_cache method. | ||
| result = storage_control_client.get_anywhere_cache request | ||
| puts "AnywhereCache #{result.name}" | ||
| end | ||
| # [END storage_control_get_anywhere_cache] | ||
| get_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_list_anywhere_caches] | ||
| def list_anywhere_caches bucket_name: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
|
|
||
| request = Google::Cloud::Storage::Control::V2::ListAnywhereCachesRequest.new( | ||
| parent: parent | ||
| ) | ||
| # The request lists all caches in the specified bucket. | ||
| # The caches are identified by the specified bucket name. | ||
| # Call the list_anywhere_caches method. | ||
| result = storage_control_client.list_anywhere_caches request | ||
|
|
||
| result.response.anywhere_caches.each do |item| | ||
| puts item.name | ||
| end | ||
| end | ||
| # [END storage_control_list_anywhere_caches] | ||
| list_anywhere_caches bucket_name: ARGV.shift if $PROGRAM_NAME == __FILE__ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_pause_anywhere_cache] | ||
| def pause_anywhere_cache bucket_name:, anywhere_cache_id: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # A value that, along with the bucket's name, uniquely identifies the cache | ||
| # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache | ||
|
||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" | ||
|
|
||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::PauseAnywhereCacheRequest.new( | ||
| name: name | ||
| ) | ||
| # The request pauses the cache, but does not delete it. | ||
| # The cache can be resumed later. | ||
| # The cache is paused in the specified bucket. | ||
| # Call the pause_anywhere_cache method. | ||
| result = storage_control_client.pause_anywhere_cache request | ||
| puts "AnywhereCache #{result.name} #{result.state}" | ||
| end | ||
| # [END storage_control_pause_anywhere_cache] | ||
| pause_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_resume_anywhere_cache] | ||
| def resume_anywhere_cache bucket_name:, anywhere_cache_id: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # A value that, along with the bucket's name, uniquely identifies the cache | ||
| # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache | ||
|
||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" | ||
|
|
||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::ResumeAnywhereCacheRequest.new( | ||
| name: name | ||
| ) | ||
| # The request resumes the cache, which was previously paused. | ||
| # The cache is resumed in the specified bucket. | ||
| # The cache is identified by the specified ID. | ||
| # Call the resume_anywhere_cache method. | ||
| result = storage_control_client.resume_anywhere_cache request | ||
| puts "AnywhereCache #{result.name} #{result.state}" | ||
| end | ||
| # [END storage_control_resume_anywhere_cache] | ||
| resume_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright 2025 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. | ||
|
|
||
| # [START storage_control_update_anywhere_cache] | ||
| def update_anywhere_cache bucket_name:, anywhere_cache_id: | ||
| # The ID of your GCS bucket | ||
| # bucket_name = "your-unique-bucket-name" | ||
|
|
||
| # A value that, along with the bucket's name, uniquely identifies the cache | ||
| # anywhere_cache_id = value that, along with the bucket's name, uniquely identifies the cache | ||
|
||
| require "google/cloud/storage/control/v2" | ||
|
|
||
| # Create a client object. The client can be reused for multiple calls. | ||
| storage_control_client = Google::Cloud::Storage::Control::V2::StorageControl::Client.new | ||
| parent = "projects/_/buckets/#{bucket_name}" | ||
| name = "#{parent}/anywhereCaches/#{anywhere_cache_id}" | ||
|
|
||
| anywhere_cache = Google::Cloud::Storage::Control::V2::AnywhereCache.new( | ||
| name: name, | ||
| ttl: 7200 | ||
| ) | ||
| mask = Google::Protobuf::FieldMask.new paths: ["ttl"] | ||
| # Create a request. Replace the placeholder values with actual data. | ||
| request = Google::Cloud::Storage::Control::V2::UpdateAnywhereCacheRequest.new( | ||
| anywhere_cache: anywhere_cache, | ||
| update_mask: mask | ||
| ) | ||
| # The request updates the cache in the specified bucket. | ||
| # The cache is identified by the specified ID. | ||
| # Call the update_anywhere_cache method. | ||
| result = storage_control_client.update_anywhere_cache request | ||
|
|
||
| if result.instance_of? Gapic::Operation | ||
| puts "AnywhereCache updated - #{result.name}" | ||
| else | ||
| puts "operation failed" | ||
| end | ||
| end | ||
| # [END storage_control_update_anywhere_cache] | ||
| update_anywhere_cache bucket_name: ARGV.shift, anywhere_cache_id: ARGV.shift if $PROGRAM_NAME == __FILE__ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be a dummy value not description! Like bucket_name