Factor out the generator to make it callable from other python scripts

In the process af attempting to write some scripts for automatically provisioning amazon instances, a colleague of mine resorted to using subprocess to call the cli.

This factors out the generation such that it can be usefully called from other modules.