Skip to content

Commit

Permalink
Passing the CloudFormation connection to CFStack
Browse files Browse the repository at this point in the history
Easier to do this than to have CFStack manage it's own connection
and handle profiles/STS assumed roles there too
  • Loading branch information
Raniz committed Oct 29, 2015
1 parent 034c910 commit e93ee31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions cumulus/CFStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"""
import logging
import simplejson
from boto import cloudformation


class CFStack(object):
"""
CFstack object represents a CloudFormation stack including its parameters,
region, template and what other stacks it depends on.
template and what other stacks it depends on.
"""
def __init__(self, mega_stack_name, name, params, template_name, region,
def __init__(self, mega_stack_name, name, params, template_name, cfconn,
sns_topic_arn, tags=None, depends_on=None):
self.logger = logging.getLogger(__name__)
if mega_stack_name == name:
Expand All @@ -33,8 +32,8 @@ def __init__(self, mega_stack_name, name, params, template_name, region,
self.depends_on.append(dep)
else:
self.depends_on.append("%s-%s" % (mega_stack_name, dep))
self.region = region
self.sns_topic_arn = sns_topic_arn
self.cfconn = cfconn

# Safer than setting default value for tags = {}
if tags is None:
Expand Down Expand Up @@ -148,12 +147,10 @@ def get_cf_stack(self, stack, resources=False):
if stack not in self.cf_stacks:
# We don't have this stack in the cache already
# so we need to pull it from CF
cfconn = cloudformation.connect_to_region(self.region)
self.cf_stacks[stack] = cfconn.describe_stacks(stack)[0]
self.cf_stacks[stack] = self.cfconn.describe_stacks(stack)[0]
return self.cf_stacks[stack]
else:
if stack not in self.cf_stacks_resources:
cfconn = cloudformation.connect_to_region(self.region)
the_stack = self.get_cf_stack(stack=stack, resources=False)
self.cf_stacks_resources[stack] = the_stack.list_resources()
return self.cf_stacks_resources[stack]
Expand Down
2 changes: 1 addition & 1 deletion cumulus/MegaStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def connect(service):
name=stack_name,
params=the_stack.get('params'),
template_name=the_stack['cf_template'],
region=self.region,
cfconn=self.cfconn,
sns_topic_arn=local_sns_arn,
depends_on=the_stack.get('depends'),
tags=merged_tags
Expand Down

0 comments on commit e93ee31

Please sign in to comment.