From 0bca4c404ceb5af09763f8035823ca37a8d6d17a Mon Sep 17 00:00:00 2001 From: Eamonn Faherty <273558+eamonnfaherty@users.noreply.github.com> Date: Mon, 29 Apr 2019 17:10:21 +0100 Subject: [PATCH] improving list_launches command (#25) --- servicecatalog_puppet/cli.py | 22 ++++++++++++++++++++++ servicecatalog_puppet/requirements.txt | 2 ++ setup.py | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/servicecatalog_puppet/cli.py b/servicecatalog_puppet/cli.py index cca9d8cad..6ab6e2ea6 100644 --- a/servicecatalog_puppet/cli.py +++ b/servicecatalog_puppet/cli.py @@ -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 @@ -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: @@ -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, @@ -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): diff --git a/servicecatalog_puppet/requirements.txt b/servicecatalog_puppet/requirements.txt index c62b9ad1a..5d6df0bee 100644 --- a/servicecatalog_puppet/requirements.txt +++ b/servicecatalog_puppet/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index 34963c78d..0b358e845 100644 --- a/setup.py +++ b/setup.py @@ -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",