From 66ef27527d7765c2d6b3898a11425c58ec69911c Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 20 Nov 2012 16:24:23 +1300 Subject: [PATCH] Tool to download all Amazon example templates Templates are saved in templates/cloudformation-examples which is ignored by git. Its probably time we're exposed to a bit more template diversity. Change-Id: I667c4f08fced353201ab9234a51526bcbeb0761b --- .gitignore | 2 ++ tools/fetch-cloudformation-examples | 48 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 tools/fetch-cloudformation-examples diff --git a/.gitignore b/.gitignore index 0ed16fc576..62a562e80c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ heat-test.db .venv AUTHORS ChangeLog +templates/cloudformation-examples + diff --git a/tools/fetch-cloudformation-examples b/tools/fetch-cloudformation-examples new file mode 100755 index 0000000000..4650dd2aca --- /dev/null +++ b/tools/fetch-cloudformation-examples @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import httplib +import os +import sys +import shutil +import xml.etree.ElementTree as xml + +basepath = os.path.abspath(os.path.join(sys.argv[0], + os.path.pardir, + os.path.pardir, + 'templates', + 'cloudformation-examples')) + +bucket = 'cloudformation-templates-us-east-1' + +def main(): + conn = httplib.HTTPConnection('s3.amazonaws.com') + conn.request('GET', '/%s/' % bucket) + resp = conn.getresponse() + + tree = xml.parse(resp) + rootElement = tree.getroot() + + if os.path.exists(basepath): + print 'Deleting %s' % basepath + shutil.rmtree(basepath) + + os.makedirs(basepath) + print 'Creating %s' % basepath + + for entry in rootElement.iter('{http://s3.amazonaws.com/doc/2006-03-01/}Key'): + key = entry.text + if key.endswith('.html'): + continue + filename = os.path.join(basepath, key) + + print 'Writing to %s' % filename + conn.request('GET', '/%s/%s' % (bucket, key)) + resp = conn.getresponse() + contents = resp.read() + + f = open(filename, 'w') + f.write(contents) + f.close() + +if __name__ == '__main__': + main()