awstools / awstools / display.py

# -*- coding: utf-8 -*-
# Copyright (C) 2012 Ludia Inc.
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
# Author: Pior Bastida <pbastida@socialludia.com>

import boto


def format_stack_summary(stack):
    tmpl  = "Name: {s.stack_name}\n"
    tmpl += "Id: {s.stack_id}\n"
    tmpl += "Status: {s.stack_status}\n"
    tmpl += "Creation : {s.creation_time}\n"

    if hasattr(stack, 'description'):
        tmpl += "Template: {s.description}"
    elif hasattr(stack, 'template_description'):
        tmpl += "Template: {s.template_description}"
    else:
        raise ValueError("Invalid Stack object")
    return tmpl.format(s=stack)


def format_stack_summary_short(stack):
    tmpl = "{s.stack_name:<26} {s.stack_status:<18} {s.creation_time}"

    if hasattr(stack, 'description'):
        tmpl += " - {s.description}"
    elif hasattr(stack, 'template_description'):
        tmpl += " - {s.template_description}"
    else:
        raise ValueError("Invalid Stack object")
    return tmpl.format(s=stack)


def format_stack_events(stack, limit=None):
    cfn = boto.connect_cloudformation()
    events = list(cfn.describe_stack_events(stack.stack_name))
    if limit:
        events = events[0:limit]

    def formatline(e):
        f = "{time}  {etype:<40}  {logicalid:<24}  {status:<20}  {reason}"
        return f.format(time=e.timestamp.isoformat().replace('T', ' '),
                        status=e.resource_status,
                        etype=e.resource_type,
                        logicalid=e.logical_resource_id,
                        reason=e.resource_status_reason)

    return "\n".join([formatline(e) for e in events])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.