Blog
Let's try this again. A whole bunch of years ago, I tried doing some blogging, and it didn't go so hot. Now, Core Software Group is doing a lot of exciting work with Plone, Django, Pyramid, and other Python based tools, and we are documenting various tips and tricks that we run into as we build custom solutions for our customers.
May 02, 2013
Automated Amazon EBS Volume Snapshots with Boto
The following write-up describes how to setup, configure and use an easy tool for taking regular snapshots of Amazon Elastic Block Storage (EBS) volumes.
Recently, we were asked by a client to setup regular EBS volume snapshots for their production EC2 instances. After a little research, Mike came across a fairly simple tool called aws-snapshot-tool: https://github.com/evannuil/aws-snapshot-tool. This tool runs as a cron job and automatically creates daily, weekly, and monthly snapshots, and automatically rotates out the oldest snapshots for each time period.
The tool, written in Python, takes advantage of an excellent module called boto (https://github.com/boto/boto, http://docs.pythonboto.org/en/latest/). Boto is a Python package that provides an interface to Amazon Web Services (AWS) allowing you to easily maintain and manage various aspects of your AWS environment with very little coding.
Install Notes
The aws-snapshot-tool github page has simple instructions to get started, but here are a couple points of interest:
install and setup boto
- pip install boto
- Setup a .boto config file to store your AWS access key (See: https://code.google.com/p/boto/wiki/BotoConfig)
Setup your Identity and Access Management (IAM) access
When you access AWS through their API, you are utilizing the web service functions to which your account has been given access. The aws-snapshot-tool includes a sample IAM configuration, that shows which actions need to be setup:
"Action": [
"ec2:CreateSnapshot",
"ec2:CreateTags",
"ec2:DeleteSnapshot",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeSnapshots",
"ec2:DescribeTags",
"ec2:DescribeVolumeAttribute",
"ec2:DescribeVolumeStatus",
"ec2:DescribeVolumes"
],
Configuration (including rotation)
Configuration is very easy. The script uses a config.py file that looks like:
config = {
'ec2_region_name': 'us-east-1',
'ec2_region_endpoint': 'ec2.us-east-1.amazonaws.com',
'tag_name': 'tag:MakeSnapshot',
'tag_value': 'True',
'keep_day': 5,
'keep_week': 5,
'keep_month': 11,
'log_file': '/tmp/makesnapshots.log',
}
There are three important pieces being defined here:
- The region where your EBS volumes are defined
- The tag name put on each volume in order to enable snapshots
- The definition for how long to keep snapshots: 5 days, 5 weeks, and 13 months
Tag Your Volumes
Well, it couldn't be any easier. Simply add a Tag of 'MakeSnapshot', with a value of 'True', (as defined in the above config file) to any volume you want picked up by this script. The script loops through all volumes in the entire defined ec2_region_name field, looks for that tag, and handles the snapshot and rotation of snapshots automatically.

Cron Setup & Output
We chose to run our script on another EC2 instance, but this could run anywhere. We setup the following cron jobs to run:
$ crontab -l
# mon-fri 30 3 * * 1-5 /home/zope/aws-snapshot-tool/makesnapshots.py day
# every sat 30 3 * * 6 /home/zope/aws-snapshot-tool/makesnapshots.py week
# first sun 30 3 1-7 * 0 /home/zope/aws-snapshot-tool/makesnapshots.py month
Each snapshot is created with a description that begins like 'day_snapshot...', 'week_snapshot...', or 'month_snapshot...', like in the following screenshots:


Gotchas?
At the moment, I can only think of 3:
- The config.py script points to a region. If we decide to start using other regions for our servers, we will need to accomodate that.
- The cost of storage. Is cheap. However, once this has run for a year, we will have 23 snapshots per volume saved in our account.
- These are real time snapshots. It is each server administrator's responsibility to insure the volume being backed up is in the proper state.
Apr 10, 2013
A Landscape of Python Web Development
Last week we had our kickoff meeting of the new Python Web Development meetup in Fort Collins, Colorado. We had 8 folks at the meeting and had great discussions about a variety of Python products and ideas for future meetings.
In preparation for our kickoff meeting of the new Python Web Development meetup, I started putting together what I called "A Landscape of Python Web Development". It started with a few of the obvious tools and products that we use at Core Software Group, like Zope/Plone, Django, and boto and suds.
From there, it started becoming obvious that I needed to break down the ever-growing list into mutliple categories.
My list of products played out like this:
The Categories
- Frameworks
- CMS
- Deployment/Hosting
- Page Templates/Forms
- Databases
- Testing
- Tools/Other
- Static Site Generators
Frameworks
This list of frameworks includes some old timers, and some newer, 'lightweight' frameworks. The last one listed, itty, was mentioned in one of Raymond Hettinger's pycon videos, and seemed an interesting, super small framework to check out.
- Zope
- Pyramid
- Django
- Flask
- Bottle
- CherryPy
- web2py
- itty
CMS
I'm sure I missed some, but these seemed to be the key players that we have come across, and the interwebs seemed to point to.
- Plone
- Kotti
- Django CMS
- Mezzanine
Deployment/Hosting
The first three are cloud platforms, and the last three are samples of python tools related to deployment.
- Heroku
- Google App Engine
- Elastic Beanstalk
- boto for EC2
- fabric
- buildout
Page Templates/Forms
This list was a late addition, but is now pretty obvious. You can't do web development without page templates and forms.
- Zope Page Templates (ZPT)
- Django Templates
- jinja2
- chameleon
- deform
- z3c.form
- WTForms
Databases
While the following are not directly related to web development, they certainly come into play when building applications that require a backend database.
- sqlalchemy
- psycopg2
- pymongo
- MySQL-python
Testing
Ok, I have to admit that I'm incredibly weak when it comes to writing tests. But I needed a list of some of the tools out there.
- unittest
- doctest
- coverage
- selenium
- funkload
Tools/Other
Wow. This list could go on and on and on. I grabbed a few tools that we use, plus a few others I came across over the last month. Hopefully, we can provide some presentations about some of these in future meetups.
- suds
- requests
- twisted
- mincss
- xml.dom, lxml, etree
- virtualenv
- simplejson
- PIL/Pillow
Static Site Generators
This list of static site generators almost has nothing to do with the above items, but I couldn't resist putting the list together. I'm fascinated by the concept of someone willing to write blog entries as text files, which in turn get deployed as static HTML to some server on the web. What I really want to know is: "How many folks are actually using these kind of tools for production sites?"
- Klein - https://github.com/twisted/klein
- Pelican - http://blog.notmyidea.org/pelican-a-simple-static-blog-generator-in-python.html
- Hyde - http://ringce.com/hyde
- Cactus - https://github.com/koenbok/Cactus
- Nikola - https://github.com/ralsina/nikola
Hovercraft/impress.js
Finally, while building my presentation, I came across a Python package called Hovercraft!, written by Lennart Regebro, for generating impress.js presentations from a reStructuredText file. Awesome. And so easy to use. You can download my kickoff.rst file and the generated output for my presentation.
Our discussion at the Python Web Development meetup was interesting, and it turns out that most of categories really start to look like the definition of a "development stack" which I suppose could be used to define a set of tools that someone might use to get started doing Python based web development.
I hope you find some value in this list. If I missed some completely obvious products, please add a comment and let me know.
Apr 09, 2013
How to enable User Folders in Plone
User Folders are an option in Plone. You can turn them on In the Security settings area of Site Setup (Plone Control Panel). Here's how I enabled User Folders in Plone from within my product.
I needed to enable the User Folders feature of Plone from within my product. My first thought was to use a Generic Setup profile, but the solution was setuphandlers.py.
I inspected the Enable User Folders button on the Security settings page of Site Setup, and saw the attribute was named enable_user_folders. I tried to find a generic setup profile I could edit.
The closest I got was adding enable_user_folders to properties.xml. This turned the attribute on in the ZMI, but not in Site Setup and User Folders were not enabled.
Then I found a reference to
security.enable_user_folders
in a setuphandlers.py file from the Rhaptos git repo.
So, I added these lines to setupVarious in my setuphandlers.py.from plone.app.controlpanel.security import ISecuritySchema site = context.getSite() security = ISecuritySchema(site) security.enable_user_folders = True
Now, when I install my product, User Folders are enabled automatically.
Note that you need to make sure setupVarious is turned on in configure.zcml.
<genericsetup:importStep
name="your.package"
title="your.package special import handlers"
description=""
handler="your.package.setuphandlers.setupVarious"
/>
Hope this helps someone.
Apr 08, 2013
How to open SSH links in iTerm 2
When I switched to iTerm 2, it wouldn't open ssh links for me. Instead, it opened new tabs. I finally solved the problem with a simple configuration change.
I know some of you have this problem. I've seen a few references to it on the net, but no solutions. iTerm 2 won't open ssh links.
I have a pyramid application that uses boto to query ec2 instances and then posts information about the instances--including an ssh link, to a web page on my laptop.
The ssh links open fine in iTerm. I couldn't get them to open in iTerm 2 though. Instead, they just opened new tabs.
I really like using iTerm 2, so to 'solve' the problem, I added the actual ssh shell command for each of the instances as text on the page.
To open an ssh connection to an instance, I simply copy the ssh command, click the link, paste the ssh command into the new terminal tab, and hit return.
Hey, it works.
Every once in a while, when it really bothers me, I try to figure out a real solution.
Today was one of those days.
The solution turned out to be pretty simple.
In the iTerm 2 Preferences, under the Profiles tab, General section, change the Command to Login shell.
Now, when I click on one of the links, it opens correctly in iTerm 2.
I hope it works for you too.
*Note that you must first have iTerm 2 set up to accept ssh connections. Preferences->Profiles->General->URL Schemes
Sep 14, 2012
Plone Hello World Tutorial
A simple introduction to Plone development.
About a month ago, there was a bit of a ruckus on twitter about the state of Plone and documentation and what not.
There was a specific request for a Hello World type tutorial introducing Plone development. After talking with Mikko and others on IRC, I put some ideas together and released a first attempt a few days later.
Over the last few weeks, I've put time into adding more sections, reorganizing the layout, and general cleanup. Tonight, I pushed those changes to the developer manual at http://collective-docs.readthedocs.org/en/latest/getstarted/helloworld/index.html
At this point it's starting to take shape. There are holes in it, and things I'd like to clean up, but it's a good start.
I'd like to get some feedback. What do folks think? What is missing? Are there any errors? Really, anything helpful is appreciated.
You can comment here, or reach me @cullerton on twitter.
Thanks,
Mike

