Skip to content
This repository was archived by the owner on Dec 31, 2023. It is now read-only.

Commit 6cfa01e

Browse files
feat: Switch to string enums for compute (#685) (#158)
* feat: Switch to string enums for compute (#685) Also introduce gapic_yaml for java clients to override default LRO configuration (which has too way too long timeouts). Also cleanup regenerate other files (grpc_service_config and service yaml) Source-Link: googleapis/googleapis@8ce4ea6 Source-Link: https://github.com/googleapis/googleapis-gen/commit/55e242c7cf5e600fabb8d767bd06f4fdfad6a015 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTVlMjQyYzdjZjVlNjAwZmFiYjhkNzY3YmQwNmY0ZmRmYWQ2YTAxNSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * run blacken on all directories with a noxfile * chore: Update integration tests to reflect API changes * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: Update integration test to reflect API changes * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 34092b5 commit 6cfa01e

File tree

72 files changed

+1227
-1196
lines changed

Some content is hidden

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

72 files changed

+1227
-1196
lines changed

google/cloud/compute_v1/types/compute.py

Lines changed: 783 additions & 739 deletions
Large diffs are not rendered by default.

owlbot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from pathlib import Path
1516
import synthtool as s
1617
import synthtool.gcp as gcp
1718
from synthtool.languages import python
@@ -57,7 +58,8 @@
5758
python.py_samples(skip_readmes=True)
5859

5960
# ----------------------------------------------------------------------------
60-
# Run blacken session
61+
# Run blacken session for all directories with a noxfile
6162
# ----------------------------------------------------------------------------
6263

63-
s.shell.run(["nox", "-s", "blacken"], hide_output=False)
64+
for noxfile in Path(".").glob("**/noxfile.py"):
65+
s.shell.run(["nox", "-s", "blacken"], cwd=noxfile.parent, hide_output=False)

samples/snippets/noxfile_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
TEST_CONFIG_OVERRIDE = {
1616
# Tests in test_sample_default_values.py require separate projects to not interfere with each other.
17-
'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
17+
"gcloud_project_env": "BUILD_SPECIFIC_GCLOUD_PROJECT",
1818
}

samples/snippets/quickstart.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def list_instances(project_id: str, zone: str) -> typing.Iterable[compute_v1.Ins
5656
print(f" - {instance.name} ({instance.machine_type})")
5757

5858
return instance_list
59+
60+
5961
# [END compute_instances_list]
6062

6163

@@ -74,7 +76,9 @@ def list_all_instances(
7476
"""
7577
instance_client = compute_v1.InstancesClient()
7678
# Use the `max_results` parameter to limit the number of results that the API returns per response page.
77-
request = compute_v1.AggregatedListInstancesRequest(project=project_id, max_results=5)
79+
request = compute_v1.AggregatedListInstancesRequest(
80+
project=project_id, max_results=5
81+
)
7882
agg_list = instance_client.aggregated_list(request=request)
7983
all_instances = {}
8084
print("Instances found:")
@@ -88,6 +92,8 @@ def list_all_instances(
8892
for instance in response.instances:
8993
print(f" - {instance.name} ({instance.machine_type})")
9094
return all_instances
95+
96+
9197
# [END compute_instances_list_all]
9298

9399

@@ -133,7 +139,7 @@ def create_instance(
133139
disk.initialize_params = initialize_params
134140
disk.auto_delete = True
135141
disk.boot = True
136-
disk.type_ = compute_v1.AttachedDisk.Type.PERSISTENT
142+
disk.type_ = "PERSISTENT"
137143

138144
# Use the network interface provided in the network_name argument.
139145
network_interface = compute_v1.NetworkInterface()
@@ -166,6 +172,8 @@ def create_instance(
166172
print("Warning during creation:", operation.warnings, file=sys.stderr)
167173
print(f"Instance {instance_name} created.")
168174
return instance
175+
176+
169177
# [END compute_instances_create]
170178

171179

@@ -196,6 +204,8 @@ def delete_instance(project_id: str, zone: str, machine_name: str) -> None:
196204
print("Warning during deletion:", operation.warnings, file=sys.stderr)
197205
print(f"Instance {machine_name} deleted.")
198206
return
207+
208+
199209
# [END compute_instances_delete]
200210

201211

@@ -227,6 +237,8 @@ def wait_for_operation(
227237
else:
228238
client = compute_v1.GlobalOperationsClient()
229239
return client.wait(**kwargs)
240+
241+
230242
# [END compute_instances_operation_check]
231243

232244

samples/snippets/sample_default_values.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
# [START compute_usage_report_get]
2323
# [START compute_usage_report_disable]
2424
from google.cloud import compute_v1
25+
2526
# [END compute_usage_report_disable]
2627
# [END compute_usage_report_get]
2728
# [END compute_usage_report_set]
2829

2930

3031
# [START compute_usage_report_set]
31-
def set_usage_export_bucket(project_id: str, bucket_name: str,
32-
report_name_prefix: str = "") -> None:
32+
def set_usage_export_bucket(
33+
project_id: str, bucket_name: str, report_name_prefix: str = ""
34+
) -> None:
3335
"""
3436
Set Compute Engine usage export bucket for the Cloud project.
3537
This sample presents how to interpret the default value for the
@@ -43,27 +45,28 @@ def set_usage_export_bucket(project_id: str, bucket_name: str,
4345
to showcase default values behaviour.
4446
"""
4547
usage_export_location = compute_v1.UsageExportLocation(
46-
bucket_name=bucket_name,
47-
report_name_prefix=report_name_prefix
48+
bucket_name=bucket_name, report_name_prefix=report_name_prefix
4849
)
4950

5051
if not report_name_prefix:
5152
# Sending an empty value for report_name_prefix results in the
5253
# next usage report being generated with the default prefix value
5354
# "usage_gce". (ref: https://cloud.google.com/compute/docs/reference/rest/v1/projects/setUsageExportBucket)
54-
print("Setting report_name_prefix to empty value causes the report "
55-
"to have the default prefix of `usage_gce`.")
55+
print(
56+
"Setting report_name_prefix to empty value causes the report "
57+
"to have the default prefix of `usage_gce`."
58+
)
5659

5760
projects_client = compute_v1.ProjectsClient()
5861
operation = projects_client.set_usage_export_bucket(
59-
project=project_id, usage_export_location_resource=usage_export_location)
62+
project=project_id, usage_export_location_resource=usage_export_location
63+
)
6064

6165
op_client = compute_v1.GlobalOperationsClient()
6266

6367
while operation.status != compute_v1.Operation.Status.DONE:
64-
operation = op_client.wait(
65-
operation=operation.name, project=project_id
66-
)
68+
operation = op_client.wait(operation=operation.name, project=project_id)
69+
6770

6871
# [END compute_usage_report_set]
6972

@@ -94,10 +97,14 @@ def get_usage_export_bucket(project_id: str) -> compute_v1.UsageExportLocation:
9497
# Although the server sent the empty string value, the next usage report
9598
# generated with these settings still has the default prefix value
9699
# "usage_gce". (see https://cloud.google.com/compute/docs/reference/rest/v1/projects/get)
97-
print('Report name prefix not set, replacing with default value of '
98-
'`usage_gce`.')
99-
uel.report_name_prefix = 'usage_gce'
100+
print(
101+
"Report name prefix not set, replacing with default value of "
102+
"`usage_gce`."
103+
)
104+
uel.report_name_prefix = "usage_gce"
100105
return uel
106+
107+
101108
# [END compute_usage_report_get]
102109
# [END compute_instances_verify_default_value]
103110

@@ -115,12 +122,13 @@ def disable_usage_export(project_id: str) -> None:
115122
# Setting `usage_export_location_resource` to an
116123
# empty object will disable the usage report generation.
117124
operation = projects_client.set_usage_export_bucket(
118-
project=project_id, usage_export_location_resource={})
125+
project=project_id, usage_export_location_resource={}
126+
)
119127

120128
op_client = compute_v1.GlobalOperationsClient()
121129

122130
while operation.status != compute_v1.Operation.Status.DONE:
123-
operation = op_client.wait(
124-
operation=operation.name, project=project_id
125-
)
131+
operation = op_client.wait(operation=operation.name, project=project_id)
132+
133+
126134
# [END compute_usage_report_disable]

samples/snippets/sample_firewall.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# [START compute_firewall_patch]
2121
# [START compute_firewall_delete]
2222
import google.cloud.compute_v1 as compute_v1
23+
2324
# [END compute_firewall_delete]
2425
# [END compute_firewall_patch]
2526
# [END compute_firewall_create]
@@ -45,6 +46,8 @@ def list_firewall_rules(project_id: str) -> Iterable:
4546
print(f" - {firewall.name}: {firewall.description}")
4647

4748
return firewalls_list
49+
50+
4851
# [END compute_firewall_list]
4952

5053

@@ -70,7 +73,7 @@ def create_firewall_rule(
7073
"""
7174
firewall_rule = compute_v1.Firewall()
7275
firewall_rule.name = firewall_rule_name
73-
firewall_rule.direction = compute_v1.Firewall.Direction.INGRESS
76+
firewall_rule.direction = "INGRESS"
7477

7578
allowed_ports = compute_v1.Allowed()
7679
allowed_ports.I_p_protocol = "tcp"
@@ -81,7 +84,7 @@ def create_firewall_rule(
8184
firewall_rule.network = network
8285
firewall_rule.description = "Allowing TCP traffic on port 80 and 443 from Internet."
8386

84-
firewall_rule.target_tags = ['web']
87+
firewall_rule.target_tags = ["web"]
8588

8689
# Note that the default value of priority for the firewall API is 1000.
8790
# If you check the value of `firewall_rule.priority` at this point it
@@ -98,6 +101,8 @@ def create_firewall_rule(
98101
op_client.wait(project=project_id, operation=op.name)
99102

100103
return
104+
105+
101106
# [END compute_firewall_create]
102107

103108

@@ -124,6 +129,8 @@ def patch_firewall_priority(project_id: str, firewall_rule_name: str, priority:
124129
operation_client = compute_v1.GlobalOperationsClient()
125130
operation_client.wait(project=project_id, operation=operation.name)
126131
return
132+
133+
127134
# [END compute_firewall_patch]
128135

129136

@@ -142,6 +149,8 @@ def delete_firewall_rule(project_id: str, firewall_rule_name: str):
142149
operation_client = compute_v1.GlobalOperationsClient()
143150
operation_client.wait(project=project_id, operation=operation.name)
144151
return
152+
153+
145154
# [END compute_firewall_delete]
146155

147156

samples/snippets/sample_instance_from_template.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# [START compute_instances_create_from_template]
1616
# [START compute_instances_create_from_template_with_overrides]
1717
from google.cloud import compute_v1
18+
1819
# [END compute_instances_create_from_template_with_overrides]
1920

2021

@@ -116,7 +117,7 @@ def create_instance_from_template_with_overrides(
116117
new_disk.initialize_params.source_image = new_disk_source_image
117118
new_disk.auto_delete = True
118119
new_disk.boot = False
119-
new_disk.type_ = compute_v1.AttachedDisk.Type.PERSISTENT
120+
new_disk.type_ = "PERSISTENT"
120121

121122
instance.disks.append(new_disk)
122123

samples/snippets/sample_pagination.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# [START compute_images_list_page]
1818
# [START compute_images_list]
1919
import google.cloud.compute_v1 as compute_v1
20+
2021
# [END compute_images_list]
2122
# [END compute_images_list_page]
2223

@@ -34,14 +35,17 @@ def print_images_list(project: str) -> None:
3435
"""
3536
images_client = compute_v1.ImagesClient()
3637
# Listing only non-deprecated images to reduce the size of the reply.
37-
images_list_request = compute_v1.ListImagesRequest(project=project, max_results=100,
38-
filter="deprecated.state != DEPRECATED")
38+
images_list_request = compute_v1.ListImagesRequest(
39+
project=project, max_results=100, filter="deprecated.state != DEPRECATED"
40+
)
3941

4042
# Although the `max_results` parameter is specified in the request, the iterable returned
4143
# by the `list()` method hides the pagination mechanic. The library makes multiple
4244
# requests to the API for you, so you can simply iterate over all the images.
4345
for img in images_client.list(request=images_list_request):
4446
print(f" - {img.name}")
47+
48+
4549
# [END compute_images_list]
4650

4751

@@ -60,21 +64,26 @@ def print_images_list_by_page(project: str, page_size: int = 10) -> None:
6064
"""
6165
images_client = compute_v1.ImagesClient()
6266
# Listing only non-deprecated images to reduce the size of the reply.
63-
images_list_request = compute_v1.ListImagesRequest(project=project, max_results=page_size,
64-
filter="deprecated.state != DEPRECATED")
67+
images_list_request = compute_v1.ListImagesRequest(
68+
project=project, max_results=page_size, filter="deprecated.state != DEPRECATED"
69+
)
6570

6671
# Use the `pages` attribute of returned iterable to have more granular control of
6772
# iteration over paginated results from the API. Each time you want to access the
6873
# next page, the library retrieves that page from the API.
69-
for page_num, page in enumerate(images_client.list(request=images_list_request).pages, start=1):
74+
for page_num, page in enumerate(
75+
images_client.list(request=images_list_request).pages, start=1
76+
):
7077
print(f"Page {page_num}: ")
7178
for img in page.items:
7279
print(f" - {img.name}")
80+
81+
7382
# [END compute_images_list_page]
7483

7584

76-
if __name__ == '__main__':
85+
if __name__ == "__main__":
7786
print("=================== Flat list of images ===================")
78-
print_images_list('windows-sql-cloud')
87+
print_images_list("windows-sql-cloud")
7988
print("================= Paginated list of images ================")
80-
print_images_list_by_page('windows-sql-cloud', 5)
89+
print_images_list_by_page("windows-sql-cloud", 5)

0 commit comments

Comments
 (0)