Skip to content

Commit a4cab64

Browse files
committed
Merge pull request #73 from mhahn/info-command
Add action for getting information on stacks
2 parents 7a44c26 + f72225d commit a4cab64

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

stacker/actions/info.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
from .base import BaseAction
4+
from .. import exceptions
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class Action(BaseAction):
10+
"""Get information on CloudFormation stacks.
11+
12+
Displays the outputs for the set of CloudFormation stacks.
13+
14+
"""
15+
16+
def run(self, *args, **kwargs):
17+
logger.info('Outputs for stacks: %s', self.context.get_fqn())
18+
for stack in self.context.get_stacks():
19+
try:
20+
provider_stack = self.provider.get_stack(stack.fqn)
21+
except exceptions.StackDoesNotExist:
22+
logger.info('Stack "%s" does not exist.' % (stack.fqn,))
23+
continue
24+
25+
logger.info('%s:', stack.fqn)
26+
for output in provider_stack.outputs:
27+
logger.info('\t%s: %s', output.key, output.value)

stacker/commands/stacker/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from .build import Build
44
from .destroy import Destroy
5+
from .info import Info
56
from .base import BaseCommand
67
from ...context import Context
78
from ...providers import aws
@@ -10,7 +11,7 @@
1011
class Stacker(BaseCommand):
1112

1213
name = 'stacker'
13-
subcommands = (Build, Destroy)
14+
subcommands = (Build, Destroy, Info)
1415

1516
def configure(self, options, **kwargs):
1617
super(Stacker, self).configure(options, **kwargs)

stacker/commands/stacker/info.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Gets information on the CloudFormation stacks based on the given config."""
2+
3+
from .base import BaseCommand
4+
from ...actions import info
5+
6+
7+
class Info(BaseCommand):
8+
9+
name = 'info'
10+
description = __doc__
11+
12+
def add_arguments(self, parser):
13+
super(Info, self).add_arguments(parser)
14+
parser.add_argument("--stacks", action="append",
15+
metavar="STACKNAME", type=str,
16+
help="Only work on the stacks given. Can be "
17+
"specified more than once. If not specified "
18+
"then stacker will work on all stacks in the "
19+
"config file.")
20+
21+
def run(self, options, **kwargs):
22+
super(Info, self).run(options, **kwargs)
23+
action = info.Action(options.context, provider=options.provider)
24+
action.execute()
25+
26+
def get_context_kwargs(self, options, **kwargs):
27+
return {'stack_names': options.stacks}

0 commit comments

Comments
 (0)