Skip to content

Commit a56bb16

Browse files
author
Thoughtseize1
committed
Merge branch 'refs/heads/main' into instance-attach-regional-disk
# Conflicts: # compute/client_library/snippets/tests/test_disks.py
2 parents 9e88faa + 1a866be commit a56bb16

25 files changed

Lines changed: 718 additions & 24 deletions

File tree

.github/blunderbuss.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ assign_prs_by:
172172
- labels:
173173
- "api: cloudsql"
174174
to:
175-
- GoogleCloudPlatform/infra-db-sdk
175+
- GoogleCloudPlatform/cloud-sql-connectors
176176
- labels:
177177
- "api: bigtable"
178178
- "api: datastore"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# pin pytest to 4.6.11 for Python2.
22
pytest==4.6.11; python_version < '3.0'
3+
pytest==8.3.4; python_version >= '3.0'
4+
six==1.17.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Flask==1.1.4; python_version < '3.0'
22
Flask==3.0.0; python_version > '3.0'
33
Werkzeug==1.0.1; python_version < '3.0'
4-
Werkzeug==3.0.3; python_version > '3.0'
4+
Werkzeug==3.0.6; python_version > '3.0'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This is an ingredient file. It is not meant to be run directly. Check the samples/snippets
16+
# folder for complete code samples that are ready to be used.
17+
# Disabling flake8 for the ingredients file, as it would fail F821 - undefined name check.
18+
# flake8: noqa
19+
20+
from google.cloud import compute_v1
21+
22+
23+
# <INGREDIENT create_replicated_disk>
24+
def create_regional_replicated_disk(
25+
project_id,
26+
region,
27+
disk_name,
28+
size_gb,
29+
disk_type: str = "pd-ssd",
30+
) -> compute_v1.Disk:
31+
"""Creates a synchronously replicated disk in a region across two zones.
32+
Args:
33+
project_id (str): The ID of the Google Cloud project.
34+
region (str): The region where the disk will be created.
35+
disk_name (str): The name of the disk.
36+
size_gb (int): The size of the disk in gigabytes.
37+
disk_type (str): The type of the disk. Default is 'pd-ssd'.
38+
Returns:
39+
compute_v1.Disk: The created disk object.
40+
"""
41+
disk = compute_v1.Disk()
42+
disk.name = disk_name
43+
44+
# You can specify the zones where the disk will be replicated.
45+
disk.replica_zones = [
46+
f"zones/{region}-a",
47+
f"zones/{region}-b",
48+
]
49+
disk.size_gb = size_gb
50+
disk.type = f"regions/{region}/diskTypes/{disk_type}"
51+
52+
client = compute_v1.RegionDisksClient()
53+
operation = client.insert(project=project_id, region=region, disk_resource=disk)
54+
55+
wait_for_extended_operation(operation, "Replicated disk creation")
56+
57+
return client.get(project=project_id, region=region, disk=disk_name)
58+
59+
60+
# </INGREDIENT>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This is an ingredient file. It is not meant to be run directly. Check the samples/snippets
16+
# folder for complete code samples that are ready to be used.
17+
# Disabling flake8 for the ingredients file, as it would fail F821 - undefined name check.
18+
# flake8: noqa
19+
20+
from google.cloud import compute_v1
21+
22+
23+
# <INGREDIENT consistency_group_clone_disks>
24+
def clone_disks_to_consistency_group(project_id, group_region, group_name):
25+
"""
26+
Clones disks to a consistency group in the specified region.
27+
Args:
28+
project_id (str): The ID of the Google Cloud project.
29+
group_region (str): The region where the consistency group is located.
30+
group_name (str): The name of the consistency group.
31+
Returns:
32+
bool: True if the disks were successfully cloned to the consistency group.
33+
"""
34+
consistency_group_policy = (
35+
f"projects/{project_id}/regions/{group_region}/resourcePolicies/{group_name}"
36+
)
37+
38+
resource = compute_v1.BulkInsertDiskResource(
39+
source_consistency_group_policy=consistency_group_policy
40+
)
41+
client = compute_v1.RegionDisksClient()
42+
request = compute_v1.BulkInsertRegionDiskRequest(
43+
project=project_id,
44+
region=group_region,
45+
bulk_insert_disk_resource_resource=resource,
46+
)
47+
operation = client.bulk_insert(request=request)
48+
wait_for_extended_operation(operation, verbose_name="bulk insert disk")
49+
return True
50+
51+
52+
# </INGREDIENT>

compute/client_library/ingredients/disks/сonsistency_groups/remove_disk_consistency_group.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
# flake8: noqa
15-
1614

17-
# This file is automatically generated. Please do not modify it directly.
18-
# Find the relevant recipe file in the samples/recipes or samples/ingredients
19-
# directory and apply your changes there.
15+
# This is an ingredient file. It is not meant to be run directly. Check the samples/snippets
16+
# folder for complete code samples that are ready to be used.
17+
# Disabling flake8 for the ingredients file, as it would fail F821 - undefined name check.
18+
# flake8: noqa
2019

2120

2221
from google.cloud import compute_v1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# flake8: noqa
15+
16+
from google.cloud import compute_v1
17+
18+
19+
# <INGREDIENT stop_replication_in_consistency_group>
20+
def stop_replication_consistency_group(project_id, location, consistency_group_name):
21+
"""
22+
Stops the asynchronous replication for a consistency group.
23+
Args:
24+
project_id (str): The ID of the Google Cloud project.
25+
location (str): The region where the consistency group is located.
26+
consistency_group_id (str): The ID of the consistency group.
27+
Returns:
28+
bool: True if the replication was successfully stopped.
29+
"""
30+
consistency_group = compute_v1.DisksStopGroupAsyncReplicationResource(
31+
resource_policy=f"regions/{location}/resourcePolicies/{consistency_group_name}"
32+
)
33+
region_client = compute_v1.RegionDisksClient()
34+
operation = region_client.stop_group_async_replication(
35+
project=project_id,
36+
region=location,
37+
disks_stop_group_async_replication_resource_resource=consistency_group,
38+
)
39+
wait_for_extended_operation(operation, "Stopping replication for consistency group")
40+
41+
return True
42+
43+
44+
# </INGREDIENT>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# flake8: noqa
15+
16+
# <REGION compute_disk_regional_replicated>
17+
# <IMPORTS/>
18+
19+
# <INGREDIENT wait_for_extended_operation />
20+
21+
# <INGREDIENT create_replicated_disk />
22+
23+
# </REGION compute_disk_regional_replicated>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# flake8: noqa
15+
16+
# <REGION compute_consistency_group_clone>
17+
# <IMPORTS/>
18+
19+
# <INGREDIENT wait_for_extended_operation />
20+
21+
# <INGREDIENT consistency_group_clone_disks />
22+
23+
# </REGION compute_consistency_group_clone>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# flake8: noqa
15+
16+
17+
# <REGION compute_consistency_group_stop_replication>
18+
# <IMPORTS/>
19+
20+
# <INGREDIENT wait_for_extended_operation />
21+
22+
# <INGREDIENT stop_replication_in_consistency_group />
23+
24+
# </REGION compute_consistency_group_stop_replication>

0 commit comments

Comments
 (0)