BVB Source Codes

blueprint Show cfn.py Source code

Return Download blueprint: download cfn.py Source code - Download blueprint Source code - Type:.py
  1. """
  2. AWS CloudFormation template generator.
  3. """
  4.  
  5. import codecs
  6. import copy
  7. import gzip as gziplib
  8. import json
  9. import logging
  10. import os.path
  11. import tarfile
  12.  
  13. from blueprint import util
  14.  
  15.  
  16. def cfn(b, relaxed=False):
  17.     b2 = copy.deepcopy(b)
  18.     def file(pathname, f):
  19.         if 'template' in f:
  20.             logging.warning('file template {0} won\'t appear in generated '
  21.                             'CloudFormation templates'.format(pathname))
  22.             del b2.files[pathname]
  23.     if relaxed:
  24.         def package(manager, package, version):
  25.             b2.packages[manager][package] = []
  26.         b.walk(file=file, package=package)
  27.     else:
  28.         b.walk(file=file)
  29.     return Template(b2)
  30.  
  31.  
  32. class Template(dict):
  33.     """
  34.    An AWS CloudFormation template that contains a blueprint.
  35.    """
  36.  
  37.     def __init__(self, b):
  38.         self.b = b
  39.         if b.name is None:
  40.             self.name = 'blueprint-generated-cfn-template'
  41.         else:
  42.             self.name = b.name
  43.         super(Template, self).__init__(json.load(open(
  44.             os.path.join(os.path.dirname(__file__), 'cfn.json'))))
  45.         b.normalize()
  46.         self['Resources']['EC2Instance']['Metadata']\
  47.             ['AWS::CloudFormation::Init']['config'] = b
  48.  
  49.     def dumps(self):
  50.         """
  51.        Serialize this AWS CloudFormation template to JSON in a string.
  52.        """
  53.         return util.json_dumps(self)
  54.  
  55.     def dumpf(self, gzip=False):
  56.         """
  57.        Serialize this AWS CloudFormation template to JSON in a file.
  58.        """
  59.         if 0 != len(self.b.sources):
  60.             logging.warning('this blueprint contains source tarballs - '
  61.                             'to use them with AWS CloudFormation, you must '
  62.                             'store them online and edit the template to '
  63.                             'reference their URLs')
  64.         if gzip:
  65.             filename = '{0}.json.gz'.format(self.name)
  66.             f = gziplib.open(filename, 'w')
  67.         else:
  68.             filename = '{0}.json'.format(self.name)
  69.             f = codecs.open(filename, 'w', encoding='utf-8')
  70.         f.write(self.dumps())
  71.         f.close()
  72.         return filename
  73.  
downloadcfn.py Source code - Download blueprint Source code
Related Source Codes/Software:
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
mrjob - Run MapReduce jobs on Hadoop or Amazon Web Service... 2017-05-11
wax - Wax is now being maintained by alibaba ... 2017-05-11
ledisdb - a high performance NoSQL powered by Go ... 2017-05-11
d3-cloud - Create word clouds in JavaScript. ... 2017-05-11
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
www.html5rocks.com - ....a top-notch resource for web developer 2017-05-12
hologram - A markdown based documentation system for style gu... 2017-05-12
isso - a Disqus alternative https:... 2017-05-12
python3-cookbook - "The Python Cookbook" 3 rd Edition Translatio 2017-05-12
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top