Exemplo n.º 1
0
def cli():
    import argparse, csv
    parser = argparse.ArgumentParser(prog='{} {}'.format(*(sys.argv[0], sys.argv[1])))
    parser.add_argument('--config', required=True, help='Config file to load for Ariel configuration')

    args = parser.parse_args(args=sys.argv[2:])
    config = utils.load_config(args.config)

    from ariel import get_account_names, get_account_instance_summary, get_ec2_pricing, get_reserved_instances
    account_names = get_account_names.load(config)
    instances = get_account_instance_summary.load(config)
    ris = get_reserved_instances.load(config)
    pricing = get_ec2_pricing.load(config)

    reports = generate(config, instances, ris, pricing)

    for key, report in reports.items():
        LOGGER.info("Writing {} report to ./output_{}.csv".format(key, key.lower()))

        # Decorate report
        if 'accountid' in report.columns and 'accountname' not in report.columns:
            accountname_column = report.columns.get_loc('accountid') + 1
            input_column = 'Account ID' if 'Account ID' in report.columns else 'accountid'
            accountname_value = report[input_column].apply(lambda x: account_names[x] if x in account_names else x)
            report.insert(accountname_column, 'accountname', accountname_value)

        store_index = type(report.index) != pd.RangeIndex
        report.to_csv("output_{}.csv".format(key.lower()), index=store_index)
        LOGGER.debug("Report {}:\n".format(key) + str(report))
Exemplo n.º 2
0
def cli():
    import argparse, csv
    parser = argparse.ArgumentParser(prog='{} {}'.format(*(sys.argv[0],
                                                           sys.argv[1])))
    parser.add_argument('--config',
                        required=True,
                        help='Config file to load for Ariel configuration')

    args = parser.parse_args(args=sys.argv[2:])
    config = utils.load_config(args.config)

    from ariel import get_account_instance_summary, get_ec2_pricing, get_reserved_instances
    instances = get_account_instance_summary.load(config)
    ris = get_reserved_instances.load(config)
    pricing = get_ec2_pricing.load(config)

    reports = generate(config, instances, ris, pricing)

    for key, report in reports.items():
        LOGGER.info("Writing {} report to ./output_{}.csv".format(
            key, key.lower()))
        store_index = type(report.index) != pd.RangeIndex
        report.to_csv("output_{}.csv".format(key.lower()), index=store_index)
        LOGGER.debug("Report {}:\n".format(key) + str(report))