Beispiel #1
0
def create_or_update(config, password, run=True):
    stack = CFStack(config, password)
    print('Validating template... ', end='', file=sys.stderr)
    stack.validate()  # raises if defect
    print('successfull.', file=sys.stderr)
    if run:
        if stack.active:
            print("Updating Stack {}...".format(stack.name),
                  end='',
                  file=sys.stderr)
            stack.update()
            print(' done.')
        else:
            print("Creating Stack {}...".format(stack.name),
                  end='',
                  file=sys.stderr)
            stack.create()
        print(' done.', file=sys.stderr)
        print_stack_events(stack)
        return stack
    # IF WE'RE NOT ACTIVELY CREATING OR UPDATING A STACK, WE'RE SHOWING THE CONFIG INSTEAD:
    print("This is the configuration we'd use if this was for real:\n\n",
          file=sys.stderr)
    if not config['JSON_INDENT']:
        config['JSON_INDENT'] = 4
    template = CFTemplate(config)
    print(template.create_json())
    if config['FILES']:
        print("\n\nHere are all the files you can use:", file=sys.stderr)
        for name, path in config['FILES'].iteritems():
            print('\t"{}":\t"{}"'.format(name, path), file=sys.stderr)
    return None
Beispiel #2
0
 def __init__(self, config, password=None):
     """
     A thin layer over boto.connect_cloudformation adding templates.
     config: the usual dict
     password_getter: an executable that yields the password or None to use AWS IAM.
     """
     self.conf = config
     self.password = password
     self.name = config['STACK_NAME']
     self.connection = self.__make_cloud_formation_connection()
     self.template = CFTemplate(self.conf)
Beispiel #3
0
def display_yaml(config):
    print("This is the rendered template:\n\n", file=sys.stderr)
    template = CFTemplate(config)
    print(template.create())
    return None
Beispiel #4
0
 def test_create_json(self):
     conf = CFTemplate(self.example_config)
     created = json.loads(conf.create_json())
     self.assertEqual(created, self.test_result)
Beispiel #5
0
 def test_create_yaml(self):
     self.example_config['TEMPLATE'] = 'prod.yaml'
     conf = CFTemplate(self.example_config)
     created = json.loads(conf.create_json())
     self.assertEqual(created, self.test_result)
Beispiel #6
0
 def test_create_fails(self):
     self.example_config['TEMPLATE_PATH'] = '/tmp'
     self.example_config['FILES'] = {}
     conf = CFTemplate(self.example_config)
     self.assertRaises(TemplateNotFound, conf.create)
Beispiel #7
0
 def test_init_settings(self):
     testpath = '/tmp'
     self.example_config['TEMPLATE_PATH'] = testpath
     self.example_config['FILES'] = {}
     conf = CFTemplate(self.example_config)
     self.assertEqual(conf.config['TEMPLATE_PATH'], testpath)