Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it is already updating or creating.
"""
old_status = kwargs.get("status")
wait_time = 0 if old_status is PENDING else STACK_POLL_TIME
if self.cancel.wait(wait_time):
return INTERRUPTED
if not should_submit(stack):
return NotSubmittedStatus()
provider = self.build_provider(stack)
try:
provider_stack = provider.get_stack(stack.fqn)
except StackDoesNotExist:
provider_stack = None
if provider_stack and not should_update(stack):
stack.set_outputs(
self.provider.get_output_dict(provider_stack))
return NotUpdatedStatus()
recreate = False
if provider_stack and old_status == SUBMITTED:
logger.debug(
"Stack %s provider status: %s",
stack.fqn,
provider.get_stack_status(provider_stack),
)
if provider.is_stack_rolling_back(provider_stack):
def _destroy_stack(self, stack, **kwargs):
old_status = kwargs.get("status")
wait_time = 0 if old_status is PENDING else STACK_POLL_TIME
if self.cancel.wait(wait_time):
return INTERRUPTED
provider = self.build_provider(stack)
try:
provider_stack = provider.get_stack(stack.fqn)
except StackDoesNotExist:
logger.debug("Stack %s does not exist.", stack.fqn)
# Once the stack has been destroyed, it doesn't exist. If the
# status of the step was SUBMITTED, we know we just deleted it,
# otherwise it should be skipped
if kwargs.get("status", None) == SUBMITTED:
return DestroyedStatus
else:
return StackDoesNotExistStatus()
logger.debug(
"Stack %s provider status: %s",
provider.get_stack_name(provider_stack),
provider.get_stack_status(provider_stack),
)
if provider.is_stack_destroyed(provider_stack):
return DestroyedStatus
def get_stack_info(self, stack):
""" Get the template and parameters of the stack currently in AWS
Returns [ template, parameters ]
"""
stack_name = stack['StackId']
try:
template = self.cloudformation.get_template(
StackName=stack_name)['TemplateBody']
except botocore.exceptions.ClientError as e:
if "does not exist" not in str(e):
raise
raise exceptions.StackDoesNotExist(stack_name)
parameters = self.params_as_dict(stack.get('Parameters', []))
return [json.dumps(template), parameters]
def get_stack_info(self, stack):
""" Get the template and parameters of the stack currently in AWS
Returns [ template, parameters ]
"""
stack_name = stack['StackId']
try:
template = self.cloudformation.get_template(
StackName=stack_name)['TemplateBody']
except botocore.exceptions.ClientError as e:
if "does not exist" not in str(e):
raise
raise exceptions.StackDoesNotExist(stack_name)
parameters = self.params_as_dict(stack.get('Parameters', []))
return [json.dumps(template), parameters]
def get_stack(self, stack_name, **kwargs):
try:
return self.cloudformation.describe_stacks(
StackName=stack_name)['Stacks'][0]
except botocore.exceptions.ClientError as e:
if "does not exist" not in str(e):
raise
raise exceptions.StackDoesNotExist(stack_name)
def run(self, *args, **kwargs):
logger.info('Outputs for stacks: %s', self.context.get_fqn())
if not self.context.get_stacks():
logger.warn('WARNING: No stacks detected (error in config?)')
for stack in self.context.get_stacks():
provider = self.build_provider(stack)
try:
provider_stack = provider.get_stack(stack.fqn)
except exceptions.StackDoesNotExist:
logger.info('Stack "%s" does not exist.' % (stack.fqn,))
continue
logger.info('%s:', stack.fqn)
if 'Outputs' in provider_stack:
for output in provider_stack['Outputs']:
logger.info(
'\t%s: %s',
output['OutputKey'],
output['OutputValue']
)
def get_stack(self, stack_name, **kwargs):
try:
return self.cloudformation.describe_stacks(
StackName=stack_name)['Stacks'][0]
except botocore.exceptions.ClientError as e:
if "does not exist" not in str(e):
raise
raise exceptions.StackDoesNotExist(stack_name)