Example #1
0
 def test_create(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.create()
     self.boto_mock.return_value.create_stack.assert_called_with(self.test_config['STACK_NAME'],
                                                                 template_body=ANY,
                                                                 capabilities=self.test_config['CAPABILITIES'],
                                                                 tags=self.test_config['TAGS'])
Example #2
0
 def test_create(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.create()
     self.boto_mock.return_value.create_stack.assert_called_with(
         self.test_config['STACK_NAME'],
         template_body=ANY,
         capabilities=self.test_config['CAPABILITIES'],
         tags=self.test_config['TAGS'])
Example #3
0
 def test_update(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.update()
     test_result_json = open(os.path.join(self.test_config['TEMPLATE_PATH'], 'output.json')).read()
     self.boto_mock.return_value.update_stack.assert_called_with(self.test_config['STACK_NAME'],
                                                                 # TODO: Check if equal to test_result_json:
                                                                 template_body=ANY,
                                                                 capabilities=self.test_config['CAPABILITIES'],
                                                                 tags=self.test_config['TAGS'])
Example #4
0
 def test_update(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.update()
     test_result_json = open(
         os.path.join(self.test_config['TEMPLATE_PATH'],
                      'output.json')).read()
     self.boto_mock.return_value.update_stack.assert_called_with(
         self.test_config['STACK_NAME'],
         # TODO: Check if equal to test_result_json:
         template_body=ANY,
         capabilities=self.test_config['CAPABILITIES'],
         tags=self.test_config['TAGS'])
Example #5
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
Example #6
0
File: run.py Project: uho/cftpl
def delete_stack(config, password):
    stack = CFStack(config, password)
    if not stack.get_stack():
        print("No running stack detected.")
        return None
    print('{}\t{}\t{}'.format(stack.stack_id, stack.stack_name, stack.stack_status))
    yesno = raw_input('Should I delete {}? '.format(stack.stack_name))
    if yesno.lower() in ('y', 'j', 'ja', 'yes'):
        print('Deleting stack {}...'.format(stack.name), end='')
        stack.delete()
        print('done.')
        print_stack_events(stack)
    else:
        print('Keeping "{}" for now.'.format(stack.stack_id))
Example #7
0
def delete_stack(config, password):
    stack = CFStack(config, password)
    if not stack.get_stack():
        print("No running stack detected.")
        return None
    print('{}\t{}\t{}'.format(stack.stack_id, stack.stack_name,
                              stack.stack_status))
    yesno = raw_input('Should I delete {}? '.format(stack.stack_name))
    if yesno.lower() in ('y', 'j', 'ja', 'yes'):
        print('Deleting stack {}...'.format(stack.name), end='')
        stack.delete()
        print('done.')
        print_stack_events(stack)
    else:
        print('Keeping "{}" for now.'.format(stack.stack_id))
Example #8
0
File: run.py Project: uho/cftpl
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
Example #9
0
File: run.py Project: uho/cftpl
def list_stacks(config, password):
    stack = CFStack(config, password)
    print('\nRegion:   {}\nEndpoint: {}\n'.format(stack.connection.region.name, stack.connection.region.endpoint))
    stacks = stack.list()
    if len(stacks) == 0:
        print('No stacks found.')
    for x in stacks:
        print("NAME         | {}".format(getattr(x, 'stack_name')))
        print('-------------+-' + '-' * len(x.stack_id))
        for a, b in (('STATUS       | {}', 'stack_status'),
                     ('REASON       | {}', 'StackStatusReason'),
                     ('LAST UPDATED | {}', 'LastUpdatedTime'),
                     ('DELETED      | {}', 'deletion_time'),
                     ('ID           | {}', 'stack_id')):
            try:
                print(a.format(getattr(x, b)))
            except AttributeError:
                print(a.format("None"))
        if x.stack_status != 'DELETE_COMPLETE':
            print("STACK EVENTS:")
            for e in stack.connection.describe_stack_events(x.stack_id):
                print('\t{}: {}'.format(e.timestamp, e))
        print('\n')
Example #10
0
def list_stacks(config, password):
    stack = CFStack(config, password)
    print('\nRegion:   {}\nEndpoint: {}\n'.format(
        stack.connection.region.name, stack.connection.region.endpoint))
    stacks = stack.list()
    if len(stacks) == 0:
        print('No stacks found.')
    for x in stacks:
        print("NAME         | {}".format(getattr(x, 'stack_name')))
        print('-------------+-' + '-' * len(x.stack_id))
        for a, b in (('STATUS       | {}', 'stack_status'),
                     ('REASON       | {}', 'StackStatusReason'),
                     ('LAST UPDATED | {}', 'LastUpdatedTime'),
                     ('DELETED      | {}',
                      'deletion_time'), ('ID           | {}', 'stack_id')):
            try:
                print(a.format(getattr(x, b)))
            except AttributeError:
                print(a.format("None"))
        if x.stack_status != 'DELETE_COMPLETE':
            print("STACK EVENTS:")
            for e in stack.connection.describe_stack_events(x.stack_id):
                print('\t{}: {}'.format(e.timestamp, e))
        print('\n')
Example #11
0
 def test_make_connection(self):
     stack = CFStack(self.test_config, self.test_password)
     self.boto_mock.assert_called_once_with(
         self.test_config['ACCOUNT'],
         region=ANY,
         aws_secret_access_key=self.test_password)
Example #12
0
 def test_active_stacks(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.active
     self.boto_mock.return_value.list_stacks.assert_called_with()
     self.assertEqual(result, False)
Example #13
0
 def test_list(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.list()
     self.boto_mock.return_value.list_stacks.assert_called_with()
Example #14
0
 def test_delete(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.delete()
     self.boto_mock.return_value.delete_stack.assert_called_with(self.test_config['STACK_NAME'])
Example #15
0
 def test_delete(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.delete()
     self.boto_mock.return_value.delete_stack.assert_called_with(
         self.test_config['STACK_NAME'])
Example #16
0
 def test_init_configured(self):
     # TODO: This tests nothing!
     self.assertTrue(CFStack(self.test_config, self.test_password))
Example #17
0
 def test_list(self):
     stack = CFStack(self.test_config, self.test_password)
     result = stack.list()
     self.boto_mock.return_value.list_stacks.assert_called_with()