Skip to content

Commit

Permalink
improving list_launches command (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnfaherty committed Apr 29, 2019
1 parent dc2af26 commit 0bca4c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions servicecatalog_puppet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from jinja2 import Environment, FileSystemLoader, Template
from betterboto import client as betterboto_client
import pkg_resources
from terminaltables import AsciiTable
from colorclass import Color

VERSION = pkg_resources.require("aws-service-catalog-puppet")[0].version

Expand Down Expand Up @@ -765,9 +767,13 @@ def list_launches(f):
ALL_REGIONS = get_regions()
manifest = yaml.safe_load(f.read())
account_ids = [a.get('account_id') for a in manifest.get('accounts')]
table_data = [
['Account', 'Region', 'Portfolio', 'Launch','Product', 'Version', 'Status']
]
for account_id in account_ids:
for region_name in ALL_REGIONS:
role = "arn:aws:iam::{}:role/{}".format(account_id, 'servicecatalog-puppet/PuppetRole')
logger.info("Looking at region: {} in account: {}".format(region_name, account_id))
with betterboto_client.CrossAccountClientContextManager(
'servicecatalog', role, 'sc-{}-{}'.format(account_id, region_name), region_name=region_name
) as spoke_service_catalog:
Expand All @@ -781,6 +787,21 @@ def list_launches(f):
response = spoke_service_catalog.search_provisioned_products(
Filters={'SearchQuery': ["productId:{}".format(product_id)]})
for provisioned_product in response.get('ProvisionedProducts', []):
launch_name = provisioned_product.get('Name')
status = provisioned_product.get('Status')
if status == "AVAILABLE":
status = Color("{green}"+status+"{/green}")
else:
status = Color("{red}"+status+"{/red}")
table_data.append([
account_id,
region_name,
portfolio.get('DisplayName'),
launch_name,
manifest.get('launches').get(launch_name).get('product'),
manifest.get('launches').get(launch_name).get('version'),
status,
])
output_path = os.path.sep.join([
LAUNCHES,
account_id,
Expand All @@ -795,6 +816,7 @@ def list_launches(f):
provisioned_product,
indent=4, default=str
))
click.echo(AsciiTable(table_data).table)


def expand_path(account, client):
Expand Down
2 changes: 2 additions & 0 deletions servicecatalog_puppet/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ click==7.0
boto3==1.9.102
pykwalify==1.7.0
better-boto==0.6.14
terminaltables==3.1.0
colorclass==2.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="aws-service-catalog-puppet",
version="0.0.25",
version="0.0.26",
author="Eamonn Faherty",
author_email="aws-service-catalog-tools@amazon.com",
description="Making it easier to deploy ServiceCatalog products",
Expand Down

0 comments on commit 0bca4c4

Please sign in to comment.