diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 695ae58..0000000 --- a/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -*.deb -*.egg -*.egg-info -*.html -*.pyc -*.pyo -*.swp -*.tar -*.tar.gz -*.template -.coverage -build -control -dist -setup.py diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 3abfdf9..0000000 --- a/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -Copyright 2011 DevStructure. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - -THIS SOFTWARE IS PROVIDED BY DEVSTRUCTURE ``AS IS'' AND ANY EXPRESS -OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL DEVSTRUCTURE OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation -are those of the authors and should not be interpreted as representing -official policies, either expressed or implied, of DevStructure. diff --git a/Makefile b/Makefile deleted file mode 100644 index e6f3854..0000000 --- a/Makefile +++ /dev/null @@ -1,95 +0,0 @@ -VERSION=0.0.0 -BUILD=1 - -PYTHON=$(shell which python2.7 || which python27 || which python2.6 || which python26 || which python) -PYTHON_VERSION=$(shell ${PYTHON} -c "from distutils.sysconfig import get_python_version; print(get_python_version())") - -prefix=/usr/local -bindir=${prefix}/bin -libdir=${prefix}/lib -pydir=$(shell ${PYTHON} pydir.py ${libdir}) -mandir=${prefix}/share/man - -all: - -clean: - rm -rf \ - *.deb \ - setup.py build dist *.egg *.egg-info \ - man/man*/*.html - find . -name \*.pyc -delete - -install: install-lib install-man - -install-lib: - find cloudformation -type d -printf %P\\0 | xargs -0r -I__ install -d $(DESTDIR)$(pydir)/cloudformation/__ - find cloudformation -type f -name \*.py -printf %P\\0 | xargs -0r -I__ install -m644 cloudformation/__ $(DESTDIR)$(pydir)/cloudformation/__ - PYTHONPATH=$(DESTDIR)$(pydir) $(PYTHON) -mcompileall $(DESTDIR)$(pydir)/cloudformation - -install-man: - find man -type d -printf %P\\0 | xargs -0r -I__ install -d $(DESTDIR)$(mandir)/__ - find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ install -m644 man/__ $(DESTDIR)$(mandir)/__ - find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ gzip $(DESTDIR)$(mandir)/__ - -uninstall: uninstall-lib uninstall-man - -uninstall-lib: - find cloudformation -type f -name \*.py -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(pydir)/cloudformation/__ $(DESTDIR)$(pydir)/cloudformation/__c - find cloudformation -depth -mindepth 1 -type d -printf %P\\0 | xargs -0r -I__ rmdir $(DESTDIR)$(pydir)/cloudformation/__ || true - rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(pydir)/cloudformation || true - -uninstall-man: - find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(mandir)/__.gz - find man -depth -mindepth 1 -type d -printf %P\\0 | xargs -0r -I__ rmdir $(DESTDIR)$(mandir)/__ || true - rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(mandir) || true - -build: build-deb build-pypi - -build-deb: - make install prefix=/usr DESTDIR=debian - fpm -s dir -t deb -C debian \ - -n python-cloudformation -v $(VERSION)-$(BUILD)py$(PYTHON_VERSION) -a all \ - -d python$(PYTHON_VERSION) \ - -m "Richard Crowley " \ - --url "https://github.com/devstructure/python-cloudformation" \ - --description "Tools for creating CloudFormation templates." - make uninstall prefix=/usr DESTDIR=debian - -build-pypi: - m4 -D__VERSION__=$(VERSION) setup.py.m4 >setup.py - $(PYTHON) setup.py bdist_egg - -deploy: deploy-deb deploy-pypi - -deploy-deb: - scp -i ~/production.pem python-cloudformation_$(VERSION)-$(BUILD)py$(PYTHON_VERSION)_all.deb ubuntu@packages.devstructure.com: - make deploy-deb-$(PYTHON_VERSION) - ssh -i ~/production.pem -t ubuntu@packages.devstructure.com "rm python-cloudformation_$(VERSION)-$(BUILD)py$(PYTHON_VERSION)_all.deb" - -deploy-deb-2.6: - ssh -i ~/production.pem -t ubuntu@packages.devstructure.com "sudo freight add python-cloudformation_$(VERSION)-$(BUILD)py$(PYTHON_VERSION)_all.deb apt/lenny apt/squeeze apt/lucid apt/maverick" - ssh -i ~/production.pem -t ubuntu@packages.devstructure.com "sudo freight cache apt/lenny apt/squeeze apt/lucid apt/maverick" - -deploy-deb-2.7: - ssh -i ~/production.pem -t ubuntu@packages.devstructure.com "sudo freight add python-cloudformation_$(VERSION)-$(BUILD)py$(PYTHON_VERSION)_all.deb apt/natty" - ssh -i ~/production.pem -t ubuntu@packages.devstructure.com "sudo freight cache apt/natty" - -deploy-pypi: - $(PYTHON) setup.py sdist upload - -man: - find man -name \*.ronn | xargs -n1 ronn \ - --manual="python-cloudformation" --organization=DevStructure --style=toc - -gh-pages: man - mkdir -p gh-pages - find man -name \*.html | xargs -I__ mv __ gh-pages/ - git checkout -q gh-pages - cp -R gh-pages/* ./ - rm -rf gh-pages - git add . - git commit -m "Rebuilt manual." - git push origin gh-pages - git checkout -q master - -.PHONY: all build clean install install-lib install-man uninstall uninstall-lib uninstall-man deb deploy deploy-deb deploy-deb-2.6 deploy-deb-2.7 deploy-pypi man gh-pages diff --git a/README.md b/README.md deleted file mode 100644 index 5d6dda3..0000000 --- a/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# python-cloudformation - -## Tools for creating CloudFormation templates - -`python-cloudformation` transforms Python source code representations of AWS CloudFormation templates into JSON. It's most useful for automating tedious user data manipulation in its very rudimentary "templating language." - -## Usage - -See the simple example in [`python-cloudformation`(7)](http://devstructure.github.com/python-cloudformation/python-cloudformation.7.html). - -## Installation - -Prerequisites: - -* Python >= 2.6 - -### From source on Mac OS X, Debian, Ubuntu, and Fedora - - git clone git://github.com/devstructure/python-cloudformation.git - cd python-cloudformation && make && sudo make install - -### From source on CentOS and RHEL - - rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm - yum install python26 - git clone git://github.com/devstructure/python-cloudformation.git - cd python-cloudformation && make && sudo make install PYTHON=/usr/bin/python26 - -This installs Python 2.6 from EPEL side-by-side with Python 2.4 and so won't break yum. - -### With a package manager - -DevStructure maintains Debian packages and Python eggs. See [Installing with a package manager](https://github.com/devstructure/python-cloudformation/wiki/Installing-with-a-package-manager) on the wiki. - -## Documentation - -Coming soon! - -## Manuals - -* [`python-cloudformation`(7)](http://devstructure.github.com/python-cloudformation/python-cloudformation.7.html) - -## Contribute - -`python-cloudformation` is [BSD-licensed](https://github.com/devstructure/python-cloudformation/blob/master/LICENSE). - -* Source code: -* Issue tracker: -* Documentation: -* Wiki: -* Mailing list: -* IRC: `#devstructure` on Freenode diff --git a/cloudformation/__init__.py b/cloudformation/__init__.py deleted file mode 100644 index 9378ea3..0000000 --- a/cloudformation/__init__.py +++ /dev/null @@ -1,89 +0,0 @@ -""" -Tools for creating CloudFormation templates. -""" - -from collections import defaultdict -import json - -def _dict_property(name): - """ - Return a property that gets and sets the given dictionary item. - """ - def get(self): - return self[name] - def set(self, value): - self[name] = value - return property(get, set) - -class Template(defaultdict): - """ - A CloudFormation template. - """ - - def __init__(self, *args, **kwargs): - """ - Initialize a neverending tree of Template objects. - """ - super(self.__class__, self).__init__(*args, **kwargs) - self.default_factory = lambda: self.__class__(self.__class__) - self.user_data = [] - - # Shortcuts to the typical keys in a Template template. - Description = _dict_property('Description') - Mappings = _dict_property('Mappings') - Outputs = _dict_property('Outputs') - Parameters = _dict_property('Parameters') - Resources = _dict_property('Resources') - - def add(self, key, *args, **kwargs): - """ - Add an item to this CloudFormation template. This is typically - called on non-root Template objects, for example - - t.Parameters.add(...) - - to add an item to the Parameters object. - """ - self[key] = self.__class__(*args, **kwargs) - - def add_user_data(self, f): - """ - Read user data from the given file-like object, parse it, and store - it. Lines containing the "____" interpolation marker will be - reconstituted later. - """ - for line in f: - self.user_data.append(line.rstrip().split('____')) - - def dumps(self, pretty=True): - """ - Return a string representation of this CloudFormation template. - """ - self['AWSTemplateFormatVersion'] = '2010-09-09' - return json.JSONEncoder(indent=2 if pretty else None, - sort_keys=True).encode(self) - - def ref_user_data(self, *args): - """ - Write out the appropriate function calls and references to pass user - data to an instance. Do not call this before calling add_user_data. - - This method skimps on error checking so make sure you pass the same - number of arguments as there are interpolation markers in the user - data, otherwise the result will be wrong or raise StopIteration. - """ - iterargs = iter(args) - lines = [] - for parts in self.user_data: - if 1 == len(parts): - lines.append(parts[0]) - else: - line = [] - for part in parts: - line.extend([part, None]) - line.pop() - for i in range(len(line)): - if line[i] is None: - line[i] = iterargs.next() - lines.append({'Fn::Join': ['', line]}) - return {'Fn::Base64': {'Fn::Join': ['\n', lines]}} diff --git a/index.html b/index.html new file mode 100644 index 0000000..a8f8f6e --- /dev/null +++ b/index.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/man/man7/python-cloudformation.7 b/man/man7/python-cloudformation.7 index f210649..ed33f62 100644 --- a/man/man7/python-cloudformation.7 +++ b/man/man7/python-cloudformation.7 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "PYTHON\-CLOUDFORMATION" "7" "July 2011" "DevStructure" "python-cloudformation" +.TH "PYTHON\-CLOUDFORMATION" "7" "June 2011" "DevStructure" "python-cloudformation" . .SH "NAME" \fBpython\-cloudformation\fR \- tools for creating CloudFormation templates diff --git a/man/man7/python-cloudformation.7.ronn b/man/man7/python-cloudformation.7.ronn deleted file mode 100644 index a966ba9..0000000 --- a/man/man7/python-cloudformation.7.ronn +++ /dev/null @@ -1,70 +0,0 @@ -python-cloudformation(7) -- tools for creating CloudFormation templates -======================================================================= - -## SYNOPSIS - - import cloudformation - import sys - - t = cloudformation.Template() - t.Description = 'Demo of python-cloudformation.' - t.add_user_data(sys.stdin) - - t.Outputs.add('DemoIp', - Description='Public IP address of DemoInstance', - Value={'Fn::GetAtt': ['DemoInstance', 'PublicIp']}) - - t.Parameters.add('DemoParam', - Description='DemoParam description.', - Type='String') - t.Parameters.add('ImageId', - Default='ami-e2af508b', - Description='AMI to use for all EC2 instances.', - Type='String') - t.Parameters.add('InstanceType', - Default='m1.small', - Description='Instance type to use for all EC2 instances.', - Type='String') - - t.Resources.add('DemoInstance', - Properties={'ImageId': {'Ref': 'ImageId'}, - 'InstanceType': {'Ref': 'InstanceType'}, - 'KeyName': {'Ref': 'KeyName'}, - 'SecurityGroups': [{'Ref': 'DemoSecurityGroup'}], - 'UserData': t.ref_user_data({'Ref': 'DemoParam'})}, - Type='AWS::EC2::Instance') - - t.Resources.add('DemoSecurityGroup', - Properties={ - 'GroupDescription': 'Unrestricted SSH and HTTP.', - 'SecurityGroupIngress': [{'CidrIp': '0.0.0.0/0', - 'FromPort': '22', - 'IpProtocol': 'tcp', - 'ToPort': '22'}, - {'CidrIp': '0.0.0.0/0', - 'FromPort': '80', - 'IpProtocol': 'tcp', - 'ToPort': '80'}]}, - Type='AWS::EC2::SecurityGroup') - - print(t.dumps()) - -## DESCRIPTION - -`python-cloudformation` transforms Python source code representations of AWS CloudFormation templates into JSON. It's most useful for automating tedious user data manipulation in its very rudimentary "templating language." - -After constructing a `cloudformation.Template` object there are two main classes of APIs available. The first is a `dict`/`set`-like API to `Description`, `Mappings`, `Outputs`, `Parameters`, and `Resources`. `Description` should be get and set as a string property. The rest may be treated like dictionaries or sets via the `add` method, which takes a `key` and arbitrary keyword arguments. These data structures will be faithfully reproduced in the JSON output. - -EC2 user data is handled separately. The `add_user_data` method accepts a file-like object which it reads, parses, and stores for later. The parsing step is very rudimentary: it splits the input on "`____`". Later, the `ref_user_data` method will replace the "`____`" markers with its positional parameters in the order they appear. Use `ref_user_data` as the value of the `UserData` key in the `Properties` dictionary of a `Resource` with `Type='AWS::EC2::Instance'`. - -## THEME SONG - -Led Zeppelin - "Night Flight" - -## AUTHOR - -Richard Crowley - -## SEE ALSO - -Blueprint I/O Server can create user data scripts for EC2 instance configuration. See for more information. diff --git a/pydir.py b/pydir.py deleted file mode 100644 index e4fcf47..0000000 --- a/pydir.py +++ /dev/null @@ -1,11 +0,0 @@ -from distutils.sysconfig import get_python_version, get_python_lib -import os.path -import sys -for s in ('dist', 'site'): - pydir = os.path.join(sys.argv[1], - 'python%s' % get_python_version(), - '%s-packages' % s) - if pydir in sys.path: - print(pydir) - sys.exit(0) -print(get_python_lib()) diff --git a/python-cloudformation.7.html b/python-cloudformation.7.html new file mode 100644 index 0000000..456aecf --- /dev/null +++ b/python-cloudformation.7.html @@ -0,0 +1,159 @@ + + + + + + python-cloudformation(7) - tools for creating CloudFormation templates + + + + + +
+ + + +
    +
  1. python-cloudformation(7)
  2. +
  3. python-cloudformation
  4. +
  5. python-cloudformation(7)
  6. +
+ +

NAME

+

+ python-cloudformation - tools for creating CloudFormation templates +

+ +

SYNOPSIS

+ +
import cloudformation
+import sys
+
+t = cloudformation.Template()
+t.Description = 'Demo of python-cloudformation.'
+t.add_user_data(sys.stdin)
+
+t.Outputs.add('DemoIp',
+              Description='Public IP address of DemoInstance',
+              Value={'Fn::GetAtt': ['DemoInstance', 'PublicIp']})
+
+t.Parameters.add('DemoParam',
+                 Description='DemoParam description.',
+                 Type='String')
+t.Parameters.add('ImageId',
+                 Default='ami-e2af508b',
+                 Description='AMI to use for all EC2 instances.',
+                 Type='String')
+t.Parameters.add('InstanceType',
+                 Default='m1.small',
+                 Description='Instance type to use for all EC2 instances.',
+                 Type='String')
+
+t.Resources.add('DemoInstance',
+    Properties={'ImageId': {'Ref': 'ImageId'},
+                'InstanceType': {'Ref': 'InstanceType'},
+                'KeyName': {'Ref': 'KeyName'},
+                'SecurityGroups': [{'Ref': 'DemoSecurityGroup'}],
+                'UserData': t.ref_user_data({'Ref': 'DemoParam'})},
+    Type='AWS::EC2::Instance')
+
+t.Resources.add('DemoSecurityGroup',
+    Properties={
+        'GroupDescription': 'Unrestricted SSH and HTTP.',
+        'SecurityGroupIngress': [{'CidrIp': '0.0.0.0/0',
+                                  'FromPort': '22',
+                                  'IpProtocol': 'tcp',
+                                  'ToPort': '22'},
+                                 {'CidrIp': '0.0.0.0/0',
+                                  'FromPort': '80',
+                                  'IpProtocol': 'tcp',
+                                  'ToPort': '80'}]},
+    Type='AWS::EC2::SecurityGroup')
+
+print(t.dumps())
+
+ +

DESCRIPTION

+ +

python-cloudformation transforms Python source code representations of AWS CloudFormation templates into JSON. It's most useful for automating tedious user data manipulation in its very rudimentary "templating language."

+ +

After constructing a cloudformation.Template object there are two main classes of APIs available. The first is a dict/set-like API to Description, Mappings, Outputs, Parameters, and Resources. Description should be get and set as a string property. The rest may be treated like dictionaries or sets via the add method, which takes a key and arbitrary keyword arguments. These data structures will be faithfully reproduced in the JSON output.

+ +

EC2 user data is handled separately. The add_user_data method accepts a file-like object which it reads, parses, and stores for later. The parsing step is very rudimentary: it splits the input on "____". Later, the ref_user_data method will replace the "____" markers with its positional parameters in the order they appear. Use ref_user_data as the value of the UserData key in the Properties dictionary of a Resource with Type='AWS::EC2::Instance'.

+ +

THEME SONG

+ +

Led Zeppelin - "Night Flight"

+ +

AUTHOR

+ +

Richard Crowley richard@devstructure.com

+ +

SEE ALSO

+ +

Blueprint I/O Server can create user data scripts for EC2 instance configuration. See http://devstructure.com/docs/endpoints.html#GET-user-data for more information.

+ + +
    +
  1. DevStructure
  2. +
  3. June 2011
  4. +
  5. python-cloudformation(7)
  6. +
+ +
+ + diff --git a/setup.py.m4 b/setup.py.m4 deleted file mode 100644 index 1535500..0000000 --- a/setup.py.m4 +++ /dev/null @@ -1,11 +0,0 @@ -from setuptools import setup, find_packages - -setup(name='cloudformation', - version='__VERSION__', - description='Tools for creating CloudFormation templates.', - author='Richard Crowley', - author_email='richard@devstructure.com', - url='http://devstructure.com/', - packages=find_packages(), - license='BSD', - zip_safe=False)