Skip to content

Commit

Permalink
Updating functions/billing/main.py - Code sample references (#2388)
Browse files Browse the repository at this point in the history
* Updating main.py

Minor tweaks so the code samples will work.

* Update main.py

Correcting the error checking to use not in.
  • Loading branch information
markmirch authored and grant committed Sep 11, 2019
1 parent b0fd453 commit 4398318
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions functions/billing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
# [START functions_billing_stop]
import base64
import json
# [END functions_billing_stop]
import os
# [END functions_billing_stop]
# [END functions_billing_limit]

# [START functions_billing_limit]
# [START functions_billing_stop]
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

# [END functions_billing_stop]
# [END functions_billing_limit]

Expand Down Expand Up @@ -63,7 +62,7 @@ def notify_slack(data, context):
# [END functions_billing_slack]


# [START functions_billing_limit]
# [START functions_billing_stop]
def stop_billing(data, context):
pubsub_data = base64.b64decode(data['data']).decode('utf-8')
pubsub_json = json.loads(pubsub_data)
Expand Down Expand Up @@ -143,6 +142,9 @@ def __list_running_instances(project_id, zone, instances):
"""
res = instances.list(project=project_id, zone=zone).execute()

if 'items' not in res:
return []

items = res['items']
running_names = [i['name'] for i in items if i['status'] == 'RUNNING']
return running_names
Expand Down

0 comments on commit 4398318

Please sign in to comment.