2222# [START compute_usage_report_get]
2323# [START compute_usage_report_disable]
2424from 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]
0 commit comments