Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AWSPlugin(object):
- """ AWS Plugin class """
- def __init__(**kwargs):
- """ setting kwargs to class object variables"""
- pass
- def get_stack_info(self, stack_name):
- """ returns the cloudformation stack details """
- client_response = None
- try:
- cfn_client = self.get_client(AWS_SERVICES.CLOUDFORMATION)
- response = cfn_client.describe_stacks(StackName=stack_name)
- client_response = response['Stacks'].pop()
- except ClientError as ce:
- self.log.error("Failed to retrieve cloudformation stack object : %s", ce)
- except Exception as e:
- self.log.exception("Exception occurred while retrieving cloudformation stack object : %s", e)
- return client_response
- def create_cfn_stack(self, stack_name, cfn_template_file, parameters):
- """ creates a cloudformation stack """
- client_response = None
- try:
- with open(cfn_template_file, 'r') as jfp:
- template_body = jfp.read()
- cfn_client = self.get_client(AWS_SERVICES.CLOUDFORMATION)
- cfn_response = cfn_client.create_stack(
- StackName=stack_name,
- TemplateBody=template_body,
- Parameters=parameters,
- DisableRollback=False,
- Tags=[
- {
- 'Key': 'Name',
- 'Value': stack_name
- },
- ]
- )
- client_response = cfn_response['StackId']
- except ClientError as ce:
- self.log.error("Failed to create cloudformation stack : %s", ce)
- except Exception as e:
- self.log.exception("Exception occurred while creating cloudformation stack : %s", e)
- return client_response
- def create_cfn_stack(self, stack_name, cfn_template_file, parameters):
- """ creates a cloudformation stack """
- client_response = None
- try:
- existing_stack = self.get_stack_info(stack_name)
- if existing_stack is not None:
- raise Exception("Stack %s is already exists and in %s state" %(stack_name, existing_stack['Status']))
- except ClientError as ce:
- print "Stack is not present and its good to create with name %s" % (stack_name)
- with open(cfn_template_file, 'r') as jfp:
- template_body = jfp.read()
- cfn_client = self.get_client(AWS_SERVICES.CLOUDFORMATION)
- cfn_response = cfn_client.create_stack(
- StackName=stack_name,
- TemplateBody=template_body,
- Parameters=parameters,
- DisableRollback=False,
- Tags=[
- {
- 'Key': 'Name',
- 'Value': stack_name
- },
- ]
- )
- client_response = response['StackId']
- except Exception as e:
- self.log.exception("Exception occurred while creating cloudformation stack : %s", e)
- return client_response
- def create_cfn_stack(self, stack_name, cfn_template_file, parameters):
- """ creates a cloudformation stack """
- client_response = None
- try:
- try:
- existing_stack = self.get_stack_info(stack_name)
- if existing_stack is not None:
- raise Exception("Stack %s is already exists and in %s state" %(stack_name, existing_stack['Status']))
- except ClientError as ce:
- print "Stack is not present and its good to create with name %s" % (stack_name)
- with open(cfn_template_file, 'r') as jfp:
- template_body = jfp.read()
- cfn_client = self.get_client(AWS_SERVICES.CLOUDFORMATION)
- cfn_response = cfn_client.create_stack(
- StackName=stack_name,
- TemplateBody=template_body,
- Parameters=parameters,
- DisableRollback=False,
- Tags=[
- {
- 'Key': 'Name',
- 'Value': stack_name
- },
- ]
- )
- client_response = cfn_response['StackId']
- except ClientError as ce:
- self.log.error("Failed to create cloudformation stack : %s", ce)
- except Exception as e:
- self.log.exception("Exception occurred while creating cloudformation stack : %s", e)
- return client_response
- def create_cfn_stack(self, stack_name, cfn_template_file, parameters):
- """ creates a cloudformation stack """
- client_response = None
- try:
- existing_stack = self.get_stack_info(stack_name)
- if existing_stack is not None:
- raise Exception("Stack %s is already exists and in %s state" %(stack_name, existing_stack['Status']))
- except ClientError as ce:
- print "Stack is not present and its good to create with name %s" % (stack_name)
- try:
- with open(cfn_template_file, 'r') as jfp:
- template_body = jfp.read()
- cfn_client = self.get_client(AWS_SERVICES.CLOUDFORMATION)
- cfn_response = cfn_client.create_stack(
- StackName=stack_name,
- TemplateBody=template_body,
- Parameters=parameters,
- DisableRollback=False,
- Tags=[
- {
- 'Key': 'Name',
- 'Value': stack_name
- },
- ]
- )
- client_response = cfn_response['StackId']
- except ClientError as ce:
- self.log.error("Failed to create cloudformation stack : %s", ce)
- except Exception as e:
- self.log.exception("Exception occurred while creating cloudformation stack : %s", e)
- return client_response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement