Exemplo n.º 1
0
    for line in row_csv:
        writers.writerows([line])

    csvfile.close()
    cur_csv.close()


# Main
if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)

    logging.info("Downloading the CloudWatch metrics")
    sys.path.append('callgcw.py')
    import callgcw
    ls_cwfile = callgcw.call_gcw(CW_REGION, CW_ACCOUNT, CW_MODE, CW_STATISTICS,
                                 CW_PERIOD, CW_STARTTIME, CW_ENDTIME,
                                 CW_OUTPUT)
    #ls_cwfile = "result.20160825.csv.gz"
    logging.info("Finish to download the CloudWatch metrics to the file %s " %
                 ls_cwfile)

    logging.info("Uploading the CloudWatch files to S3 ")
    upload_s3(S3_BUCKET, ls_cwfile, ls_cwfile)
    logging.info("Finish to upload the CloudWatch files to S3 bucket %s " %
                 (S3_BUCKET))

    logging.info(
        "Downloading the EC2 pricelist file and upload it to S3 bucket")
    ls_ec2pricelist_fileame = download_ec2pricelist()
    logging.info(
        "Finish to download EC2 pricelist file and upload it to S3 bucket: %s "
Exemplo n.º 2
0
    logging.info("Downloading the CloudWatch metrics")
    sys.path.append('callgcw.py')
    import callgcw

    for a, account in enumerate(new_CW_ACCOUNT):
        # creating ARN string from user fed IAM Role Name (assumes names are same across all accounts as per pre-req)
        roleARNString = "arn:aws:iam::{0}:role/{1}".format(account, CW_ROLE)
        roleSessionName = "{}-{}".format(account, CW_ROLE)
        logging.info(
            "getting temp credentials for role {} in account {} with ARN {}".
            format(roleARNString, account, roleARNString))
        sts_credentials = get_assumeRoleCreds(roleARNString, roleSessionName)
        logging.info("Received credentials: {}".format(sts_credentials))
        ls_cwfile = callgcw.call_gcw(CW_REGION, account, CW_MODE,
                                     CW_STATISTICS, CW_PERIOD, CW_STARTTIME,
                                     CW_ENDTIME, CW_OUTPUT, sts_credentials)

        logging.info(
            "Finished to download the CloudWatch metrics for account {0} to the file {1} "
            .format(account, ls_cwfile))

        # checking list to see if its the last account, then upload to s3
        if a == (len(new_CW_ACCOUNT) - 1):
            os.system('gzip -f ' + ls_cwfile)
            ls_cwfile += ".gz"
            logging.info("Uploading the CloudWatch files to S3 ")
            upload_s3(S3_BUCKET, ls_cwfile, ls_cwfile)
            logging.info(
                "Finish to upload the CloudWatch files to S3 bucket %s " %
                (S3_BUCKET))