Skip to content

Commit

Permalink
Merge pull request #18 from remind101/taxonomy_cleanup
Browse files Browse the repository at this point in the history
Taxonomy cleanup
  • Loading branch information
phobologic committed Mar 31, 2015
2 parents 1a7309c + c3c8a6b commit 43ddb30
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 230 deletions.
8 changes: 4 additions & 4 deletions conf/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ vpc_parameters: &vpc_parameters

stacks:
- name: vpc
class_path: stacker.stacks.vpc.VPC
class_path: stacker.blueprints.vpc.VPC
parameters:
InstanceType: m3.medium
SshKeyName: default
ImageName: NAT
- name: bastion
class_path: stacker.stacks.bastion.Bastion
class_path: stacker.blueprints.bastion.Bastion
parameters:
# Extends the parameters dict with the contents of the vpc_parameters
# anchor. Basically we're including all VPC Outputs in the parameters
Expand All @@ -36,7 +36,7 @@ stacks:
SshKeyName: default
ImageName: bastion
- name: myDB
class_path: stacker.stacks.postgres.PostgresRDS
class_path: stacker.blueprints.postgres.PostgresRDS
parameters:
<< : *vpc_parameters
InstanceType: db.m3.medium
Expand All @@ -45,7 +45,7 @@ stacks:
MasterUserPassword: ExamplePassword!
DBName: db1
- name: myWeb
class_path: stacker.stacks.asg.AutoscalingGroup
class_path: stacker.blueprints.asg.AutoscalingGroup
parameters:
<< : *vpc_parameters
InstanceType: m3.medium
Expand Down
29 changes: 11 additions & 18 deletions scripts/stacker
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

import argparse
import logging
import code
from collections import Mapping
import copy

import yaml
from stacker.builder import StackBuilder
from stacker.builder import Builder

logger = logging.getLogger()

Expand All @@ -20,10 +19,10 @@ INFO_FORMAT = ('[%(asctime)s] %(message)s')
ISO_8601 = '%Y-%m-%dT%H:%M:%S'


def get_stack_config(config, stack_list):
""" If given a stack list, extract the stack config for each in config.
def get_stack_definitions(config, stack_list):
""" Extract stack definitions from the config.
If no stack list given, return stack config as is.
If no stack_list given, return stack config as is.
"""
if not stack_list:
return config['stacks']
Expand Down Expand Up @@ -85,9 +84,6 @@ def parse_args():
"specified more than once. If not specified "
"then stacker will work on all stacks in the "
"config file.")
parser.add_argument("--prompt", action="store_true",
help="Drop to python prompt rather than kicking off "
"build of the stack.")
parser.add_argument('config',
help="The config file where stack configuration is "
"located. Must be in yaml format.")
Expand Down Expand Up @@ -116,13 +112,10 @@ if __name__ == '__main__':
with open(args.config) as fd:
config = yaml.load(fd)

builder = StackBuilder(args.region, mappings=config['mappings'],
config=config, parameters=parameters)
if args.prompt:
print "Dropping into interactive console..."
code.InteractiveConsole(locals()).interact()
else:
stacks = get_stack_config(config, args.stacks)
stack_names = [s['name'] for s in stacks]
logger.info("Working on stacks: %s", ', '.join(stack_names))
builder.build(stacks)
builder = Builder(args.region, mappings=config['mappings'],
parameters=parameters)

stack_definitions = get_stack_definitions(config, args.stacks)
stack_names = [s['name'] for s in stack_definitions]
logger.info("Working on stacks: %s", ', '.join(stack_names))
builder.build(stack_definitions)
File renamed without changes.
4 changes: 2 additions & 2 deletions stacker/stacks/asg.py → stacker/blueprints/asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from troposphere import ec2, autoscaling
from troposphere.autoscaling import Tag as ASTag

from stacker.stack import StackTemplateBase
from .base import Blueprint

CLUSTER_SG_NAME = "%sSG"


class AutoscalingGroup(StackTemplateBase):
class AutoscalingGroup(Blueprint):
PARAMETERS = {
'VpcId': {'type': 'AWS::EC2::VPC::Id', 'description': 'Vpc Id'},
'DefaultSG': {'type': 'AWS::EC2::SecurityGroup::Id',
Expand Down
20 changes: 11 additions & 9 deletions stacker/stack.py → stacker/blueprints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
from troposphere import Template, Parameter


class StackTemplateBase(object):
class Blueprint(object):
"""Base implementation for dealing with a troposphere template.
:type name: string
:param name: A name for the stack template. If not provided, one
:param name: A name for the blueprint. If not provided, one
will be created from the class name automatically.
:type context: BlueprintContext object
:param config: Used for configuring the Blueprint.
:type mappings: dict
:param mappings: Cloudformation Mappings to be used in the template.
:type config: dict
:param config: A dictionary which is used to pass in configuration info
to the stack.
"""
def __init__(self, name, config, mappings=None):
def __init__(self, name, context, mappings=None):
self.name = name
self.mappings = mappings
self.config = config
# TODO: This is only, currently, used for parameters. should probably
# just pass parameters alone.
self.context = context
self.outputs = {}
self.reset_template()

Expand All @@ -32,9 +34,9 @@ def parameters(self):
params = []
for param in self.template.parameters:
try:
params.append((param, self.config.parameters[param]))
params.append((param, self.context.parameters[param]))
except KeyError:
logger.debug("Parameter '%s' not found in config, skipping.",
logger.debug("Parameter '%s' not found in context, skipping.",
param)
continue
return params
Expand Down
4 changes: 2 additions & 2 deletions stacker/stacks/bastion.py → stacker/blueprints/bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from troposphere import Ref, ec2, autoscaling, FindInMap
from troposphere.autoscaling import Tag as ASTag

from ..stack import StackTemplateBase
from .base import Blueprint

CLUSTER_SG_NAME = "BastionSecurityGroup"


class Bastion(StackTemplateBase):
class Bastion(Blueprint):
PARAMETERS = {
"VpcId": {"type": "AWS::EC2::VPC::Id", "description": "Vpc Id"},
"DefaultSG": {"type": "AWS::EC2::SecurityGroup::Id",
Expand Down
4 changes: 2 additions & 2 deletions stacker/stacks/postgres.py → stacker/blueprints/postgres.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from troposphere import Ref, ec2, Output, GetAtt, Join
from troposphere.rds import DBInstance, DBSubnetGroup

from ..stack import StackTemplateBase
from .base import Blueprint

RDS_INSTANCE_NAME = "PostgresRDS%s"
RDS_SUBNET_GROUP = "%sSubnetGroup"
RDS_SG_NAME = "RdsSG%s"


class PostgresRDS(StackTemplateBase):
class PostgresRDS(Blueprint):
PARAMETERS = {
'VpcId': {'type': 'AWS::EC2::VPC::Id', 'description': 'Vpc Id'},
'PrivateSubnets': {'type': 'List<AWS::EC2::Subnet::Id>',
Expand Down
8 changes: 4 additions & 4 deletions stacker/stacks/vpc.py → stacker/blueprints/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from troposphere import ec2
import netaddr

from ..stack import StackTemplateBase
from .base import Blueprint

NAT_INSTANCE_NAME = "NatInstance%s"


class VPC(StackTemplateBase):
class VPC(Blueprint):
PARAMETERS = {
"InstanceType": {
"type": "String",
Expand Down Expand Up @@ -188,8 +188,8 @@ def create_nat_instance(self, zone, subnet):

def create_template(self):
self.cidr_block = netaddr.IPNetwork(
self.config.parameters['CidrBlock'])
self.zones = self.config.parameters['Zones']
self.context.parameters['CidrBlock'])
self.zones = self.context.parameters['Zones']
self.template.add_output(
Output("AvailabilityZones",
Value=Join(",", self.zones)))
Expand Down

0 comments on commit 43ddb30

Please sign in to comment.