Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

various variable naming improvements

  • Loading branch information...
commit bc823b46380803cf45645f1a69173bbd0651c254 1 parent c51cdb8
@briandorsey briandorsey authored
Showing with 17 additions and 15 deletions.
  1. +3 −3 README.md
  2. +2 −2 app.yaml
  3. +11 −9 main.py
  4. +1 −1  templates/index.html
View
6 README.md
@@ -59,7 +59,7 @@ Give your App Engine application's service account `edit` access to your GCE pro
Verify
------
-> As long as PRETEND_MODE is set to `True` (the default) in `main.py`, the application will only log deletes.
+> As long as DRY_RUN is set to `True` (the default) in `main.py`, the application will only log deletes.
Deploy the application to App Engine:
@@ -74,8 +74,8 @@ To create instances tagged "production", add the instance using the GCE Console
You can optionally run the cron task manually and check the logs to verify that the correct instances will be deleted.
-Visit `http://YOUR-APP-ID.appspot.com/cron/delete` to run deletes immediately. Then check the AppEngine logs. You should see "PRETEND DELETE" if any instances are old enough to be deleted.
+Visit `http://YOUR-APP-ID.appspot.com/cron/delete` to run deletes immediately. Then check the AppEngine logs. You should see "DRY_RUN, not deleted" if any instances are old enough to be deleted.
-Once everything looks good, edit `main.py` and change `PRETEND_MODE` to `False`.
+Once everything looks good, edit `main.py` and change `DRY_RUN` to `False`.
Happy Computing!
View
4 app.yaml
@@ -1,4 +1,4 @@
-application: REPLACE-WITH-YOUR-APP-ID
+application: replace-with-your-app-id
version: 1
runtime: python27
api_version: 1
@@ -15,7 +15,7 @@ handlers:
libraries:
- name: webapp2
- version: "2.5.2"
+ version: latest
- name: jinja2
version: latest
View
20 main.py
@@ -28,12 +28,12 @@
SAMPLE_NAME = 'Instance timeout helper'
# Be careful, this application will delete instances unless they're tagged
# with one of the SAFE_TAGS below.
-GCE_PROJECT_ID = 'briandpe-api'
+GCE_PROJECT_ID = 'replace-with-your-compute-engine-project-id'
TIMEOUT = 60 * 8 # in minutes, defaulting to 8 hours
SAFE_TAGS = "production safetag".lower().split()
# In pretend 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.
-PRETEND_MODE = True
+DRY_RUN = True
# Obtain App Engine AppAssertion credentials and authorize HTTP connection.
# https://developers.google.com/appengine/docs/python/appidentity/overview
@@ -41,6 +41,7 @@
scope='https://www.googleapis.com/auth/compute')
HTTP = credentials.authorize(httplib2.Http(memcache))
+# Build object for the 'v1beta13' version of the GCE API.
compute = build('compute', 'v1beta13', http=HTTP)
jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader('templates'))
@@ -57,11 +58,12 @@ def annotate_instances(instances):
break
instance['_excluded'] = excluded
- # set _age and _timeout_expired (never True for _excluded instances)
+ # set _age_hours and _timeout_expired
+ # _timeout_expired is never True for _excluded inst
creation = parse_iso8601tz(instance['creationTimestamp'])
now = datetime.datetime.now()
delta = now - creation
- instance['_age'] = delta.seconds / 60
+ instance['_age_hours'] = delta.seconds / 60
if delta.seconds > TIMEOUT * 60 and not instance['_excluded']:
instance['_timeout_expired'] = True
else:
@@ -83,7 +85,7 @@ def get(self):
instances = list_instances()
config = {}
- config['PRETEND_MODE'] = PRETEND_MODE
+ config['DRY_RUN'] = DRY_RUN
config['SAFE_TAGS'] = ', '.join(SAFE_TAGS)
config['TIMEOUT'] = TIMEOUT
config['GCE_PROJECT_ID'] = GCE_PROJECT_ID
@@ -98,7 +100,7 @@ def get(self):
def delete_expired_instances():
- """logs all expired instances, calls delete API when not PRETEND_MODE"""
+ """logs all expired instances, calls delete API when not DRY_RUN"""
instances = list_instances()
# filter instances, keep only expired instances
@@ -109,8 +111,8 @@ def delete_expired_instances():
for instance in instances:
name = instance['name']
- if PRETEND_MODE:
- logging.info("PRETEND DELETE: %s", name)
+ if DRY_RUN:
+ logging.info("DRY_RUN, not deleted: %s", name)
else:
logging.info("DELETE: %s", name)
request = compute.instances().delete(project=GCE_PROJECT_ID,
@@ -126,8 +128,8 @@ def get(self):
app = webapp2.WSGIApplication([
- ('/', MainHandler),
('/cron/delete', DeleteHandler),
+ ('/', MainHandler),
], debug=True)
View
2  templates/index.html
@@ -38,7 +38,7 @@
{% for i in instances %}
<tr {{'class="expired"' if i._timeout_expired}}>
<td>{{i.name}}</td>
- <td>{{i._age}}</td>
+ <td>{{i._age_hours}}</td>
<td>{{i.creationTimestamp}}</td>
<td>{{i.machineType.split('/')[-1]}}</td>
<td>{{i._excluded}}</td>
Please sign in to comment.
Something went wrong with that request. Please try again.