Skip to content

Commit 4398318

Browse files
markmirchgrant
authored andcommitted
Updating functions/billing/main.py - Code sample references (GoogleCloudPlatform#2388)
* Updating main.py Minor tweaks so the code samples will work. * Update main.py Correcting the error checking to use not in.
1 parent b0fd453 commit 4398318

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

functions/billing/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
# [START functions_billing_stop]
1717
import base64
1818
import json
19-
# [END functions_billing_stop]
2019
import os
20+
# [END functions_billing_stop]
2121
# [END functions_billing_limit]
2222

2323
# [START functions_billing_limit]
2424
# [START functions_billing_stop]
2525
from googleapiclient import discovery
2626
from oauth2client.client import GoogleCredentials
27-
2827
# [END functions_billing_stop]
2928
# [END functions_billing_limit]
3029

@@ -63,7 +62,7 @@ def notify_slack(data, context):
6362
# [END functions_billing_slack]
6463

6564

66-
# [START functions_billing_limit]
65+
# [START functions_billing_stop]
6766
def stop_billing(data, context):
6867
pubsub_data = base64.b64decode(data['data']).decode('utf-8')
6968
pubsub_json = json.loads(pubsub_data)
@@ -143,6 +142,9 @@ def __list_running_instances(project_id, zone, instances):
143142
"""
144143
res = instances.list(project=project_id, zone=zone).execute()
145144

145+
if 'items' not in res:
146+
return []
147+
146148
items = res['items']
147149
running_names = [i['name'] for i in items if i['status'] == 'RUNNING']
148150
return running_names

0 commit comments

Comments
 (0)