Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Commit

Permalink
pep8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
briandorsey committed Dec 31, 2012
1 parent 78f60a1 commit 969553a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions main.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@


SAMPLE_NAME = 'Instance timeout helper' SAMPLE_NAME = 'Instance timeout helper'


CONFIG= { CONFIG = {
# In DRY_RUN mode, deletes are only logged. Set this to False after you've # In DRY_RUN mode, deletes are only logged. Set this to False after you've
# double-checked the status page and you're ready to enable the deletes. # double-checked the status page and you're ready to enable the deletes.
'DRY_RUN': True, 'DRY_RUN': True,


# Be careful, this application could delete all instances in this project. # Be careful, this application could delete all instances in this project.
# Your project id can be found on the overview tab of the Google APIs # Your project id can be found on the overview tab of the Google APIs
# Console: https://code.google.com/apis/console/ # Console: https://code.google.com/apis/console/
'GCE_PROJECT_ID': 'replace-with-your-compute-engine-project-id', 'GCE_PROJECT_ID': 'replace-with-your-compute-engine-project-id',
Expand Down Expand Up @@ -60,25 +60,25 @@


def annotate_instances(instances): def annotate_instances(instances):
"""loops through the instances and adds exclusion, age and timeout""" """loops through the instances and adds exclusion, age and timeout"""
for instance in instances: for inst in instances:
# set _excluded # set _excluded
excluded = False excluded = False
for tag in instance.get('tags', []): for tag in inst.get('tags', []):
if tag.lower() in CONFIG['SAFE_TAGS']: if tag.lower() in CONFIG['SAFE_TAGS']:
excluded = True excluded = True
break break
instance['_excluded'] = excluded inst['_excluded'] = excluded


# set _age_minutes and _timeout_expired # set _age_minutes and _timeout_expired
# _timeout_expired is never True for _excluded inst # _timeout_expired is never True for _excluded inst
creation = parse_iso8601tz(instance['creationTimestamp']) creation = parse_iso8601tz(inst['creationTimestamp'])
now = datetime.datetime.now() now = datetime.datetime.now()
delta = now - creation delta = now - creation
instance['_age_minutes'] = delta.seconds / 60 inst['_age_minutes'] = delta.seconds / 60
if not instance['_excluded'] and delta.seconds > (CONFIG['TIMEOUT'] * 60): if not inst['_excluded'] and delta.seconds > (CONFIG['TIMEOUT'] * 60):
instance['_timeout_expired'] = True inst['_timeout_expired'] = True
else: else:
instance['_timeout_expired'] = False inst['_timeout_expired'] = False




def list_instances(): def list_instances():
Expand Down Expand Up @@ -121,8 +121,8 @@ def delete_expired_instances():
logging.info("DRY_RUN, not deleted: %s", name) logging.info("DRY_RUN, not deleted: %s", name)
else: else:
logging.info("DELETE: %s", name) logging.info("DELETE: %s", name)
request = compute.instances().delete(project=CONFIG['GCE_PROJECT_ID'], request = compute.instances().delete(
instance=name) project=CONFIG['GCE_PROJECT_ID'], instance=name)
response = request.execute() response = request.execute()
logging.info(response) logging.info(response)


Expand Down

0 comments on commit 969553a

Please sign in to comment.