Skip to content

Commit e094a77

Browse files
Merge branch 'main' into hyperdisk-create-pool-and-from-pool
2 parents d7076b1 + 3ca526d commit e094a77

File tree

68 files changed

+2587
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2587
-133
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# Platform Ops
3939
/monitoring/opencensus @yuriatgoogle @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
4040
/monitoring/prometheus @yuriatgoogle @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
41-
/trace/**/* @ymotongpoo @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
41+
/trace/**/* @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
4242

4343
# DEE Data & AI
4444
/speech/**/* @GoogleCloudPlatform/cloud-speech-eng @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
@@ -62,6 +62,7 @@
6262
/pubsub/**/* @GoogleCloudPlatform/api-pubsub-and-pubsublite @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6363
/pubsublite/**/* @GoogleCloudPlatform/api-pubsub-and-pubsublite @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6464
/managedkafka/**/* @GoogleCloudPlatform/api-pubsub-and-pubsublite @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
65+
/dataplex/**/* @GoogleCloudPlatform/googleapi-dataplex @GoogleCloudPlatform/python-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
6566

6667
# For practicing
6768
# ---* Use with codelabs to learn to submit samples

.github/auto-label.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ path:
3636
container-analysis: "containeranalysis"
3737
contentwarehouse: "contentwarehouse"
3838
datacatalog: "datacatalog"
39+
dataplex: "dataplex"
3940
datalabeling: "datalabeling"
4041
dataproc: "dataproc"
4142
datastore: "datastore"

.github/blunderbuss.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ assign_issues_by:
129129
- "api: serviceextensions"
130130
to:
131131
- GoogleCloudPlatform/service-extensions-samples-reviewers
132+
- labels:
133+
- "api: dataplex"
134+
to:
135+
- GoogleCloudPlatform/googleapi-dataplex
132136

133137
# Self-service individuals
134138
- labels:
@@ -250,6 +254,10 @@ assign_prs_by:
250254
to:
251255
- GoogleCloudPlatform/service-extensions-samples-reviewers
252256
- GoogleCloudPlatform/dee-infra
257+
- labels:
258+
- "api: dataplex"
259+
to:
260+
- GoogleCloudPlatform/googleapi-dataplex
253261
# Self-service individuals
254262
- labels:
255263
- "api: auth"
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
# https://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 consume_any_matching_reservation>
24+
def consume_any_project_reservation(
25+
project_id: str,
26+
zone: str,
27+
reservation_name: str,
28+
instance_name: str,
29+
machine_type: str = "n1-standard-1",
30+
min_cpu_platform: str = "Intel Ivy Bridge",
31+
) -> compute_v1.Instance:
32+
"""
33+
Creates a specific reservation in a single project and launches a VM
34+
that consumes the newly created reservation.
35+
Args:
36+
project_id (str): The ID of the Google Cloud project.
37+
zone (str): The zone to create the reservation.
38+
reservation_name (str): The name of the reservation to create.
39+
instance_name (str): The name of the instance to create.
40+
machine_type (str): The machine type for the instance.
41+
min_cpu_platform (str): The minimum CPU platform for the instance.
42+
"""
43+
instance_properties = (
44+
compute_v1.AllocationSpecificSKUAllocationReservedInstanceProperties(
45+
machine_type=machine_type,
46+
min_cpu_platform=min_cpu_platform,
47+
)
48+
)
49+
50+
reservation = compute_v1.Reservation(
51+
name=reservation_name,
52+
specific_reservation=compute_v1.AllocationSpecificSKUReservation(
53+
count=3,
54+
instance_properties=instance_properties,
55+
),
56+
)
57+
58+
# Create a reservation client
59+
client = compute_v1.ReservationsClient()
60+
operation = client.insert(
61+
project=project_id,
62+
zone=zone,
63+
reservation_resource=reservation,
64+
)
65+
wait_for_extended_operation(operation, "Reservation creation")
66+
67+
instance = compute_v1.Instance()
68+
instance.name = instance_name
69+
instance.machine_type = f"zones/{zone}/machineTypes/{machine_type}"
70+
instance.min_cpu_platform = min_cpu_platform
71+
instance.zone = zone
72+
73+
# Set the reservation affinity to target any matching reservation
74+
instance.reservation_affinity = compute_v1.ReservationAffinity(
75+
consume_reservation_type="ANY_RESERVATION", # Type of reservation to consume
76+
)
77+
# Define the disks for the instance
78+
instance.disks = [
79+
compute_v1.AttachedDisk(
80+
boot=True, # Indicates that this is a boot disk
81+
auto_delete=True, # The disk will be deleted when the instance is deleted
82+
initialize_params=compute_v1.AttachedDiskInitializeParams(
83+
source_image="projects/debian-cloud/global/images/family/debian-11",
84+
disk_size_gb=10,
85+
),
86+
)
87+
]
88+
instance.network_interfaces = [
89+
compute_v1.NetworkInterface(
90+
network="global/networks/default", # The network to use
91+
access_configs=[
92+
compute_v1.AccessConfig(
93+
name="External NAT", # Name of the access configuration
94+
type="ONE_TO_ONE_NAT", # Type of access configuration
95+
)
96+
],
97+
)
98+
]
99+
# Create a request to insert the instance
100+
request = compute_v1.InsertInstanceRequest()
101+
request.zone = zone
102+
request.project = project_id
103+
request.instance_resource = instance
104+
105+
vm_client = compute_v1.InstancesClient()
106+
operation = vm_client.insert(request)
107+
wait_for_extended_operation(operation, "instance creation")
108+
print(f"Instance {instance_name} that targets any open reservation created.")
109+
110+
return vm_client.get(project=project_id, zone=zone, instance=instance_name)
111+
112+
113+
# </INGREDIENT>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
# https://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 consume_single_project_reservation>
24+
def consume_specific_single_project_reservation(
25+
project_id: str,
26+
zone: str,
27+
reservation_name: str,
28+
instance_name: str,
29+
machine_type: str = "n1-standard-1",
30+
min_cpu_platform: str = "Intel Ivy Bridge",
31+
) -> compute_v1.Instance:
32+
"""
33+
Creates a specific reservation in a single project and launches a VM
34+
that consumes the newly created reservation.
35+
Args:
36+
project_id (str): The ID of the Google Cloud project.
37+
zone (str): The zone to create the reservation.
38+
reservation_name (str): The name of the reservation to create.
39+
instance_name (str): The name of the instance to create.
40+
machine_type (str): The machine type for the instance.
41+
min_cpu_platform (str): The minimum CPU platform for the instance.
42+
"""
43+
instance_properties = (
44+
compute_v1.AllocationSpecificSKUAllocationReservedInstanceProperties(
45+
machine_type=machine_type,
46+
min_cpu_platform=min_cpu_platform,
47+
)
48+
)
49+
50+
reservation = compute_v1.Reservation(
51+
name=reservation_name,
52+
specific_reservation=compute_v1.AllocationSpecificSKUReservation(
53+
count=3,
54+
instance_properties=instance_properties,
55+
),
56+
# Only VMs that target the reservation by name can consume from this reservation
57+
specific_reservation_required=True,
58+
)
59+
60+
# Create a reservation client
61+
client = compute_v1.ReservationsClient()
62+
operation = client.insert(
63+
project=project_id,
64+
zone=zone,
65+
reservation_resource=reservation,
66+
)
67+
wait_for_extended_operation(operation, "Reservation creation")
68+
69+
instance = compute_v1.Instance()
70+
instance.name = instance_name
71+
instance.machine_type = f"zones/{zone}/machineTypes/{machine_type}"
72+
instance.min_cpu_platform = min_cpu_platform
73+
instance.zone = zone
74+
75+
# Set the reservation affinity to target the specific reservation
76+
instance.reservation_affinity = compute_v1.ReservationAffinity(
77+
consume_reservation_type="SPECIFIC_RESERVATION", # Type of reservation to consume
78+
key="compute.googleapis.com/reservation-name", # Key for the reservation
79+
values=[reservation_name], # Reservation name to consume
80+
)
81+
# Define the disks for the instance
82+
instance.disks = [
83+
compute_v1.AttachedDisk(
84+
boot=True, # Indicates that this is a boot disk
85+
auto_delete=True, # The disk will be deleted when the instance is deleted
86+
initialize_params=compute_v1.AttachedDiskInitializeParams(
87+
source_image="projects/debian-cloud/global/images/family/debian-11",
88+
disk_size_gb=10,
89+
),
90+
)
91+
]
92+
instance.network_interfaces = [
93+
compute_v1.NetworkInterface(
94+
network="global/networks/default", # The network to use
95+
access_configs=[
96+
compute_v1.AccessConfig(
97+
name="External NAT", # Name of the access configuration
98+
type="ONE_TO_ONE_NAT", # Type of access configuration
99+
)
100+
],
101+
)
102+
]
103+
# Create a request to insert the instance
104+
request = compute_v1.InsertInstanceRequest()
105+
request.zone = zone
106+
request.project = project_id
107+
request.instance_resource = instance
108+
109+
vm_client = compute_v1.InstancesClient()
110+
operation = vm_client.insert(request)
111+
wait_for_extended_operation(operation, "instance creation")
112+
print(f"Instance {instance_name} with specific reservation created successfully.")
113+
114+
return vm_client.get(project=project_id, zone=zone, instance=instance_name)
115+
116+
117+
# </INGREDIENT>

0 commit comments

Comments
 (0)