Exemplo n.º 1
0
 def validateStack(self, stack, region, logoutput=None):
     session, config = configtasks.getConfig(region, stack)
     cftemplate = template.voltron(stack, **config)
     template.writecompiled(data=cftemplate, name=stack, region=region)
     cf = cloudformation.stack(session)
     validationstatus = cf.validateTemplate(cftemplate)
     return validationstatus
Exemplo n.º 2
0
    def deleteCreateStack(self, stack, region, githash=None, environment=None, logoutput=None):
        '''Deletes a stack then creates it again'''
        self.optOut(stack)
        session, config = configtasks.getConfig(region, stack, githash, environment)
        cftemplate = template.voltron(stack, **config)
        template.writecompiled(cftemplate, stack, region)
        cf = cloudformation.stack(session)

        try:
            cf.validateTemplate(cftemplate)
        except:
            print "Template validation failed!"
            print json.dumps(cftemplate, sort_keys=True, indent=4, separators=(',', ': '))
            sys.exit(1)

        try:
            cf.deleteStack(config["stackname"])
            cf.statusPoller(stackname=config["stackname"])
        except ClientError as err:
            print err
            sys.exit(1)

        try:
            cf.createStack(cftemplate, config["stackname"])
            cf.statusPoller(stackname=config["stackname"])
        except ClientError as err:
            log.warn(err)
            sys.exit(1)
Exemplo n.º 3
0
 def createChangeSet(self, stack, region, githash, environment):
     session, config = configtasks.getConfig(region, stack, githash, environment)
     cftemplate = template.voltron(stack, **config)
     template.writecompiled(data=cftemplate, name=stack, region=region)
     cf = cloudformation.stack(session)
     cfstackname = self.generateStackName(stack, githash, environment)
     changes = cf.createChangeSet(cftemplate, cfstackname)
     return changes
Exemplo n.º 4
0
 def generateTemplate(ctx, stack, region, githash=None, environment=None, logoutput=None, outFile=None, customConfig=''):
     '''Generates a template given stack name and region USAGE generateTemplate STACK REGION'''
     config = configs.loadConfig(stack, region, githash, environment, customConfig)
     cftemplate = template.voltron(stack, **config)
     if len(json.dumps(cftemplate)) >= 51200:
         print output.whalesay(text='Your generated Cloudformation Template is over the max allowable size.\nYou will need to reduce the size, split the template or upload into S3.')
     if len(json.dumps(cftemplate)) >= 460800:
         print output.piesay(text='Your generated Cloudformation Template is over the max allowable size.')
         sys.exit(1)
     name = outFile if outFile else stack
     template.writecompiled(cftemplate, name, region)
Exemplo n.º 5
0
 def generateTemplateS3(ctx, stack, region, githash=None, environment=None, logoutput=None, outFile=None, customConfig=None):
     '''Generates a template that needs to be uploaded to S3. Must run on
     the build agents as it will decrypt the secrets using KMS. Otherwise usage
     is the same as generateTemplate'''
     session, config = configtasks.getConfig(region, stack, githash, environment, customConfig)
     cftemplate = template.voltron(stack, **config)
     if len(json.dumps(cftemplate)) >= 51200:
         print output.whalesay(text='Your generated Cloudformation Template is over the max allowable size.\nYou will need to reduce the size, split the template or upload into S3.')
     if len(json.dumps(cftemplate)) >= 460800:
         print output.piesay(text='Your generated Cloudformation Template is over the max allowable size.')
         sys.exit(1)
     name = outFile if outFile else stack
     template.writecompiled(cftemplate, name, region)
Exemplo n.º 6
0
    def upsertIamStackSet(self, stack, region, githash=None, environment=None, logoutput=None):
        self.optOut(stack)
        session, config = configtasks.getConfig(region, stack, githash, environment)
        cftemplate = template.voltron(stack, **config)
        cfstackname = self.generateStackName(config["stackname"], githash, environment)
        template.writecompiled(data=cftemplate, name=stack, region=region, logoutput=logoutput)
        cf = cloudformation.stack(session)
        try:
            cf.validateTemplate(cftemplate=cftemplate)
        except ClientError as err:
            log.warn(err)
            # print "Template validation failed!"
            # pprint.pprint(json.dumps(cftemplate))
            sys.exit(1)
        status = cf.describeStackSet(stackname=cfstackname)
        if status:
            try:
                response = cf.updateStackSet(cftemplate=cftemplate, stackname=cfstackname, iamcapable=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'])
                if logoutput:
                    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
                state, status = cf.statusPoller(stackname=cfstackname)

                if logoutput:
                    print json.dumps(cf.getStackResources(stackname=cfstackname), default=str, sort_keys=True, indent=4, separators=(',', ': '))

                if state != 0:
                    sys.exit(1)
            except ClientError as err:
                log.warn(err)
                if 'No updates are to be performed' in str(err):
                    sys.exit(0)
                sys.exit(1)
        else:
            try:
                response = cf.createStackSet(cftemplate=cftemplate, stackname=cfstackname, iamcapable=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM'])
                if logoutput:
                    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
                state, status = cf.statusPoller(stackname=cfstackname)

                if logoutput:
                    print json.dumps(cf.getStackResources(stackname=cfstackname), default=str, sort_keys=True, indent=4, separators=(',', ': '))

                if state != 0:
                    sys.exit(1)
            except ClientError as err:
                log.warn(err)
                if 'already exists' in str(err):
                    sys.exit(0)
                sys.exit(1)
Exemplo n.º 7
0
    def upsertS3Stack(self, stack, s3location, region, githash=None, environment=None, logoutput=None, customConfig=None):
        self.optOut(stack)
        session, config = configtasks.getConfig(region, stack, githash, environment, customConfig)
        cftemplate = template.voltron(stack, **config)
        cfstackname = self.generateStackName(config["stackname"], githash, environment)
        template.writecompiled(data=cftemplate, name=stack, region=region, logoutput=logoutput)
        cf = cloudformation.stack(session)
        status = cf.describeStack(stackname=cfstackname)
        if status:
            try:
                response = cf.updateStack(cftemplate=s3location, stackname=cfstackname)
                if logoutput:
                    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
                state, status = cf.statusPoller(stackname=cfstackname)

                if logoutput:
                    print json.dumps(cf.getStackResources(stackname=cfstackname), default=str, sort_keys=True, indent=4, separators=(',', ': '))

                if state != 0:
                    sys.exit(1)
            except ClientError as err:
                log.warn(err)
                if 'No updates are to be performed' in str(err):
                    sys.exit(0)
                sys.exit(1)
        else:
            try:
                response = cf.createStack(cftemplate=s3location, stackname=cfstackname)
                if logoutput:
                    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
                state, status = cf.statusPoller(stackname=cfstackname)

                if logoutput:
                    print json.dumps(cf.getStackResources(stackname=cfstackname), default=str, sort_keys=True, indent=4, separators=(',', ': '))

                if state != 0:
                    sys.exit(1)
            except ClientError as err:
                log.warn(err)
                if 'already exists' in str(err):
                    sys.exit(0)
                sys.exit(1)