Odyssey
Functions | Variables
cli.cloudformation Namespace Reference

Functions

def __get_boto_client__ (region)
 
def __get_stack_name__ (cluster, region, name, uuid)
 
def __get_changeset_name__ (stack_name, git_sha)
 
def __read_template_body_as_json__ ()
 
def __aws_tags_translation__ (tags)
 
def __aws_params_translation__ (params)
 
def __update_template_tasks_environments__ (template, env)
 
def __validate_template__ (client, template_body)
 
def describe_stack (stack, **kwargs)
 
def describe_changeset (stack, git_sha, **kwargs)
 
def watch_stack_progress (stack, **kwargs)
 
def watch_changeset_progress (stack, git_sha, **kwargs)
 
def list_stack_events (stack, **kwargs)
 
def create_cloudformation_stack (stack, params, tags=None, **kwargs)
 
def create_cloudformation_changeset (stack, params, git_sha, tags=None, **kwargs)
 
def execute_changeset (stack, git_sha, **kwargs)
 
def deploy_changeset (stack, git_sha, params, **kwargs)
 
def delete_stack (stack, **kwargs)
 

Variables

string STACK_TEMPLATE_DIR = '/cloudformation'
 
 STACK_TEMPLATE = os.path.join(STACK_TEMPLATE_DIR, 'odyssey.cf.json')
 
 LOG = logging.getLogger(__name__)
 

Detailed Description

Hosting Cloudformation Library

Function Documentation

◆ create_cloudformation_changeset()

def cli.cloudformation.create_cloudformation_changeset (   stack,
  params,
  git_sha,
  tags = None,
**  kwargs 
)
Create AWS Cloudformation Changeset

Definition at line 167 of file cloudformation.py.

167 def create_cloudformation_changeset(stack,
168  params,
169  git_sha,
170  tags=None,
171  **kwargs):
172  '''Create AWS Cloudformation Changeset'''
173  if tags is None:
174  tags = {}
175  client = __get_boto_client__(stack.region)
176  stack_name = __get_stack_name__(stack.cluster,
177  stack.region,
178  stack.name,
179  stack.uuid)
180  changeset_name = __get_changeset_name__(stack_name, git_sha)
181  stack_template = __update_template_tasks_environments__(
182  __read_template_body_as_json__(),
183  stack.env
184  )
185  template_body = json.dumps(stack_template, indent=2)
186 
187  if kwargs.get('verbose', False):
188  print(__validate_template__(client, template_body), file=sys.stderr)
189 
190  try:
191  response = client.create_change_set(
192  StackName=stack_name,
193  ChangeSetName=changeset_name,
194  TemplateBody=template_body,
195  Parameters=__aws_params_translation__(params),
196  Capabilities=['CAPABILITY_NAMED_IAM'],
197  Tags=__aws_tags_translation__(tags))
198  except Exception as ex:
199  print(ex, file=sys.stderr)
200  return False
201 
202  if kwargs.get('verbose', False):
203  print(response, file=sys.stderr)
204 
205  if response['ResponseMetadata']['HTTPStatusCode'] != 200:
206  return False
207  else:
208  return True
209 
210 

◆ create_cloudformation_stack()

def cli.cloudformation.create_cloudformation_stack (   stack,
  params,
  tags = None,
**  kwargs 
)
Create AWS Cloudformation Stack

Definition at line 136 of file cloudformation.py.

136 def create_cloudformation_stack(stack,
137  params,
138  tags=None,
139  **kwargs):
140  '''Create AWS Cloudformation Stack'''
141  if tags is None:
142  tags = {}
143  stack_name = __get_stack_name__(stack.cluster,
144  stack.region,
145  stack.name,
146  stack.uuid)
147  stack_template = __update_template_tasks_environments__(
148  __read_template_body_as_json__(),
149  stack.env
150  )
151  template_body = json.dumps(stack_template, indent=4)
152 
153  client = __get_boto_client__(stack.region)
154 
155  if kwargs.get('verbose', False):
156  print(__validate_template__(client, template_body), file=sys.stderr)
157 
158  response = client.create_stack(
159  StackName=stack_name,
160  Parameters=__aws_params_translation__(params),
161  TemplateBody=template_body,
162  Capabilities=['CAPABILITY_NAMED_IAM'],
163  Tags=__aws_tags_translation__(tags))
164  return response.get('StackId')
165 
166 

◆ delete_stack()

def cli.cloudformation.delete_stack (   stack,
**  kwargs 
)
Delete stack

Definition at line 252 of file cloudformation.py.

252 def delete_stack(stack, **kwargs):
253  '''Delete stack'''
254  assert stack
255  stack_name = __get_stack_name__(stack.cluster,
256  stack.region,
257  stack.name,
258  stack.uuid)
259  client = boto3.client('cloudformation', region_name=stack.region)
260  client.delete_stack(StackName=stack_name)
261  if kwargs.get('wait_until_complete', False):
262  watch_stack_progress(stack, **kwargs)