Skip to content

Commit

Permalink
Merge pull request #60 from remind101/fix_line_length
Browse files Browse the repository at this point in the history
Move back to 80 character width lines
  • Loading branch information
phobologic committed Aug 6, 2015
2 parents 4b3f60c + c48c0f0 commit 0835a41
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 70 deletions.
3 changes: 2 additions & 1 deletion stacker/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def cfn_bucket(self):
except boto.exception.S3ResponseError, e:
if e.error_code == 'NoSuchBucket':
logger.debug("Creating bucket %s.", self.bucket_name)
self._cfn_bucket = self.s3_conn.create_bucket(self.bucket_name)
self._cfn_bucket = self.s3_conn.create_bucket(
self.bucket_name)
elif e.error_code == 'AccessDenied':
logger.exception("Access denied for bucket %s.",
self.bucket_name)
Expand Down
27 changes: 18 additions & 9 deletions stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class Action(BaseAction):
The plan can then either be printed out as an outline or executed. If
executed, each stack will get launched in order which entails:
- Pushing the generated CloudFormation template to S3 if it has chnaged
- Submitting either a build or update of the given stack to the `Provider`.
- Pushing the generated CloudFormation template to S3 if it has changed
- Submitting either a build or update of the given stack to the
`Provider`.
- Stores the stack outputs for reference by other stacks.
"""
Expand Down Expand Up @@ -54,7 +55,8 @@ def _resolve_parameters(self, outputs, parameters, blueprint):
# Get from the Output of another stack in the stack_map
stack_name, output = value.split('::')
stack_fqn = self.context.get_fqn(stack_name)
# XXX check out this logic to see if this is what we really want to do
# XXX check out this logic to see if this is what we really
# want to do
try:
stack_outputs = outputs[stack_fqn]
except KeyError:
Expand Down Expand Up @@ -102,15 +104,20 @@ def _launch_stack(self, results, stack, **kwargs):
logger.info("Launching stack %s now.", stack.fqn)
template_url = self.s3_stack_push(stack.blueprint)
tags = self._build_stack_tags(stack, template_url)
parameters = self._resolve_parameters(results, stack.parameters, stack.blueprint)
parameters = self._resolve_parameters(results, stack.parameters,
stack.blueprint)
required_params = [k for k, v in stack.blueprint.required_parameters]
parameters = self._handle_missing_parameters(parameters, required_params, provider_stack)
parameters = self._handle_missing_parameters(parameters,
required_params,
provider_stack)

try:
if not provider_stack:
self.provider.create_stack(stack.fqn, template_url, parameters, tags)
self.provider.create_stack(stack.fqn, template_url, parameters,
tags)
else:
self.provider.update_stack(stack.fqn, template_url, parameters, tags)
self.provider.update_stack(stack.fqn, template_url, parameters,
tags)
except StackDidNotChange:
return SKIPPED

Expand All @@ -131,7 +138,8 @@ def _get_outputs(self, stack):
stack_outputs[output.key] = output.value
return stack_outputs

def _handle_missing_parameters(self, params, required_params, existing_stack=None):
def _handle_missing_parameters(self, params, required_params,
existing_stack=None):
"""Handles any missing parameters.
If an existing_stack is provided, look up missing parameters there.
Expand Down Expand Up @@ -191,7 +199,8 @@ def pre_run(self, outline=False, *args, **kwargs):
"""Any steps that need to be taken prior to running the action."""
pre_build = self.context.config.get('pre_build')
if not outline and pre_build:
util.handle_hooks('pre_build', pre_build, self.provider.region, self.context)
util.handle_hooks('pre_build', pre_build, self.provider.region,
self.context)

def run(self, outline=False, *args, **kwargs):
"""Kicks off the build/update of the stacks in the stack_definitions.
Expand Down
40 changes: 21 additions & 19 deletions stacker/commands/stacker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,33 @@ def add_arguments(self, parser):
action=KeyValueAction, default={},
help="Adds parameters from the command line "
"that can be used inside any of the stacks "
"being built. Can be specified more than once.")
parser.add_argument('-r', '--region', default='us-east-1',
"being built. Can be specified more than "
"once.")
parser.add_argument("-r", "--region", default="us-east-1",
help="The AWS region to launch in. Default: "
"%(default)s")
parser.add_argument('-e', '--environment', type=yaml_file_type,
parser.add_argument("-e", "--environment", type=yaml_file_type,
default={},
help="Path to a yaml environment file. The values in "
"the environment file can be used in the stack "
"config as if it were a string.Template type: "
"https://docs.python.org/2/library/string.html"
"#template-strings")
parser.add_argument('-v', '--verbose', action='count', default=0,
help='Increase output verbosity. May be specified up '
'to twice.')
help="Path to a yaml environment file. The values "
"in the environment file can be used in the "
"stack config as if it were a "
"string.Template type: "
"https://docs.python.org/2/library/"
"string.html#template-strings")
parser.add_argument("-v", "--verbose", action="count", default=0,
help="Increase output verbosity. May be specified "
"up to twice.")
parser.add_argument("--stacks", action="append",
metavar="STACKNAME", type=str,
help="Only work on the stacks given. Can be "
"specified more than once. If not specified "
"then stacker will work on all stacks in the "
"config file.")
parser.add_argument('namespace',
help='The namespace for the stack collection. This '
'will be used as the prefix to the '
'cloudformation stacks as well as the s3 bucket '
'where templates are stored.')
parser.add_argument('config', type=argparse.FileType(),
help="The config file where stack configuration is "
"located. Must be in yaml format.")
parser.add_argument("namespace",
help="The namespace for the stack collection. "
"This will be used as the prefix to the "
"cloudformation stacks as well as the s3 "
"bucket where templates are stored.")
parser.add_argument("config", type=argparse.FileType(),
help="The config file where stack configuration "
"is located. Must be in yaml format.")
17 changes: 9 additions & 8 deletions stacker/commands/stacker/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Build(StackerCommand):

def add_arguments(self, parser):
super(Build, self).add_arguments(parser)
parser.add_argument('-m', '--max-zones', type=int,
help="Gives you the ability to limit the # of zones "
"that resources will be launched in. If not "
"given, then resources will be launched in all "
"available availability zones.")
parser.add_argument('-o', '--outline', action='store_true',
help='Print an outline of what steps will be taken '
'to build the stacks')
parser.add_argument("-m", "--max-zones", type=int,
help="Gives you the ability to limit the # of "
"zones that resources will be launched in. "
"If not given, then resources will be "
"launched in all available availability "
"zones.")
parser.add_argument("-o", "--outline", action="store_true",
help="Print an outline of what steps will be "
"taken to build the stacks")

def run(self, options, **kwargs):
super(Build, self).run(options, **kwargs)
Expand Down
6 changes: 4 additions & 2 deletions stacker/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Context(object):
"""

_optional_keys = ('environment', 'stack_names', 'parameters', 'mappings', 'config')
_optional_keys = ('environment', 'stack_names', 'parameters', 'mappings',
'config')

def __init__(self, namespace, **kwargs):
self.namespace = namespace
Expand All @@ -25,7 +26,8 @@ def load_config(self, conf_string):
def _get_stack_definitions(self):
if not self.stack_names:
return self.config['stacks']
return [s for s in self.config['stacks'] if s['name'] in self.stack_names]
return [s for s in self.config['stacks'] if s['name'] in
self.stack_names]

def get_stacks(self):
"""Get the stacks for the current action.
Expand Down
3 changes: 2 additions & 1 deletion stacker/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def __init__(self, parameters, *args, **kwargs):
message = 'Missing required parameters: %s' % (
', '.join(parameters),
)
super(MissingParameterException, self).__init__(message, *args, **kwargs)
super(MissingParameterException, self).__init__(message, *args,
**kwargs)


class ParameterDoesNotExist(Exception):
Expand Down
21 changes: 14 additions & 7 deletions stacker/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def run(self, results):

def set_status(self, status):
if status is not self.status:
logger.debug("Setting %s state to %s.", self.stack.name, status.name)
logger.debug("Setting %s state to %s.", self.stack.name,
status.name)
self.status = status

def complete(self):
Expand Down Expand Up @@ -105,13 +106,15 @@ def __init__(self, description, sleep_time=5, wait_func=None, *args,
self.sleep_time = sleep_time
if wait_func is not None:
if not callable(wait_func):
raise ImproperlyConfigured(self.__class__, '"wait_func" must be a callable')
raise ImproperlyConfigured(self.__class__,
'"wait_func" must be a callable')
self._wait_func = wait_func
else:
self._wait_func = time.sleep
super(Plan, self).__init__(*args, **kwargs)

def add(self, stack, run_func, completion_func=None, skip_func=None, requires=None):
def add(self, stack, run_func, completion_func=None, skip_func=None,
requires=None):
"""Add a new step to the plan."""
self[stack.fqn] = Step(
stack=stack,
Expand Down Expand Up @@ -184,7 +187,8 @@ def execute(self, results=None):

status = step.run(results)
if not isinstance(status, Status):
raise ValueError('Step run_func must return a valid Status')
raise ValueError('Step run_func must return a valid '
'Status')

if status is COMPLETE:
results[step_name] = step.complete()
Expand All @@ -202,7 +206,8 @@ def execute(self, results=None):
def outline(self, level=logging.INFO, execute_helper=False):
"""Print an outline of the actions the plan is going to take.
The outline will represent the rough ordering of the steps that will be taken.
The outline will represent the rough ordering of the steps that will be
taken.
Args:
level (Optional[int]): a valid log level that should be used to log
Expand All @@ -223,12 +228,14 @@ def outline(self, level=logging.INFO, execute_helper=False):
step_name,
step._run_func.__name__,
)
# Set the status to COMPLETE directly so we don't call the completion func
# Set the status to COMPLETE directly so we don't call the
# completion func
step.status = COMPLETE
steps += 1

if execute_helper:
logger.log(level, 'To execute this plan, run with "-f, --force" flag.')
logger.log(level, 'To execute this plan, run with "-f, --force" '
'flag.')

def _check_point(self):
logger.info('Plan Status:')
Expand Down
3 changes: 2 additions & 1 deletion stacker/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def __init__(self, region, **kwargs):
@property
def cloudformation(self):
if not hasattr(self, '_cloudformation'):
self._cloudformation = cloudformation.connect_to_region(self.region)
self._cloudformation = cloudformation.connect_to_region(
self.region)
return self._cloudformation

def get_stack(self, stack_name, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions stacker/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class BaseProvider(object):

def __init__(self, *args, **kwargs):
if not self.name:
raise exceptions.ImproperlyConfigured('Provider must have a "name"')
raise exceptions.ImproperlyConfigured('Provider must have a '
'"name"')

def _not_implemented_erorr(self, method):
raise NotImplementedError('Provider "%s" does not support "%s"' % (self.name, method))
raise NotImplementedError('Provider "%s" does not support "%s"' % (
self.name, method))

def get_stack(self, stack_name, *args, **kwargs):
self._not_implemented_erorr('get_stack')
Expand Down
4 changes: 3 additions & 1 deletion stacker/providers/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@


class StackDidNotChange(Exception):
"""Exception raised when there are no changes to be made by the provider."""
"""Exception raised when there are no changes to be made by the
provider.
"""
3 changes: 2 additions & 1 deletion stacker/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__(self, definition, context, parameters=None, mappings=None):
self.definition = definition
self.parameters = _gather_parameters(definition, parameters or {})
self.mappings = mappings
# XXX this is temporary until we remove passing context down to the blueprint
# XXX this is temporary until we remove passing context down to the
# blueprint
self.context = copy.deepcopy(context)
if isinstance(self.context.parameters, dict):
self.context.parameters.update(self.parameters)
Expand Down

0 comments on commit 0835a41

Please sign in to comment.