def report_kinesis(self): ''' This function is a wrapper for parsing arguments and printing for kinesis attribute reports :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser( description='report generation about kinesis', usage='''kerrigan.py kinesis report_kinesis [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument( '--columns', action='store', default=a.service_supported_columns(service="kinesis").keys(), help="Which columns to display") args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(service="kinesis", columns=args.columns) result = a.information_kinesis(columns=columns) logger.output( data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def instance_status(self): logger.info("Started instance status command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser( description='instance status about ami', usage='''kerrigan.py ami instance_Status [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--imageid', action='store', default=None, help="Only imageIds that should be queried") args = parser.parse_args(sys.argv[3:]) result = a.image_instance_status(imageid=args.imageid) for res in result: if self.account_information['logger_arguments']['table']: res['Instances'] = Misc.list_to_multiline_string( list=res['Instances']) else: res['Instances'] = Misc.join_list_to_string( list=res['Instances']) logger.output( data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def report_elb(self): ''' This function is a wrapper for parsing arguments and printing for elb attribute reports Tested :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='report generation about elbs', usage='''kerrigan.py elb report_elb [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--columns', action='store', default=a.service_supported_columns(service="elb"), help="Which columns to display") parser.add_argument('--filters', action='store', default=None, help="The filters that should be used, example: key1:value1,key2:value2") args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(columns=args.columns, service="elb") if args.filters: filters = Misc.format_boto3_filter(filters=args.filters) else: filters = None result = a.information_elbs(columns=columns, filters=filters) for res in result: if self.account_information['logger_arguments']['table']: res['AvailabilityZones'] = Misc.list_to_multiline_string(list=res['AvailabilityZones']) res['SecurityGroups'] = Misc.list_to_multiline_string(list=res['SecurityGroups']) res['Instances'] = Misc.list_to_multiline_string(list=res['Instances']) else: res['AvailabilityZones'] = Misc.join_list_to_string(list=res['AvailabilityZones']) res['SecurityGroups'] = Misc.join_list_to_string(list=res['SecurityGroups']) res['Instances'] = Misc.join_list_to_string(list=res['Instances']) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def info_all(self): # FIXME implement possbility to scope to env logger.info("Gathering all elbs") parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py elb info_all [<args>]] ''' + self.global_options) args = parser.parse_args(sys.argv[3:]) e = awsrequests() res = e.elb_info_all() for r in res: if self.cli['csv']: r['Availability Zones'] = Misc.join_list_to_string( list=r['Availability Zones']) r['Securitygroups'] = Misc.join_list_to_string( list=r['Securitygroups']) r['InstanceIds'] = Misc.join_list_to_string( list=r['InstanceIds']) r['From-To-Protocol'] = Misc.join_list_to_string( list=r['From-To-Protocol']) elif self.cli['table']: r['Availability Zones'] = Misc.list_to_multiline_string( r['Availability Zones']) r['InstanceIds'] = Misc.list_to_multiline_string( r['InstanceIds']) r['Securitygroups'] = Misc.list_to_multiline_string( r['Securitygroups']) r['From-To-Protocol'] = Misc.list_to_multiline_string( r['From-To-Protocol']) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def info(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py route53 info [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Environment to gather information about") args = parser.parse_args(sys.argv[3:]) res = a.route53_info(env=args.env) for r in res: if self.cli['csv']: r['Values'] = Misc.join_list_to_string(list=r['Values']) elif self.cli['table']: r['Values'] = Misc.list_to_multiline_string(r['Values']) else: logger.error( 'There is an unhandled printing. Need to investigate') # Add information if not present: if 'Weight' not in r: r['Weight'] = '-' r['SetIdentifier'] = '-' logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def list_users(self): logger.info("Going to list users") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam list_users [<args>]] ''' + self.global_options) args = parser.parse_args(sys.argv[3:]) a = awsrequests() res = a.list_iam_users() logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def list_buckets(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py s3 list_buckets [<args>]] ''' + self.global_options) parser.add_argument('--extended', action='store_true', default=False, help="Gather extended info about Buckets") args = parser.parse_args(sys.argv[3:]) res = a.list_s3_buckets(extended=args.extended) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def create_user_credentials(self): logger.info("Going to create user credentials") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam create_user_credentials [<args>]] ''' + self.global_options) parser.add_argument('--username', action='store', help="Username to create credentials for", required=True) parser.add_argument('--dryrun', action='store_true', default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) a = awsrequests() resp = a.create_user_credentials(username=args.username,dryrun=args.dryrun) logger.output(data=resp, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def info_bucket(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py s3 info_bucket [<args>]] ''' + self.global_options) parser.add_argument('--name', action='store', help="Name of bucket", required=True) parser.add_argument('--level', action='store', choices=['acl', 'lifecycle', 'region', 'logging', 'policy', 'replication','tagging'], help="What information to return") args = parser.parse_args(sys.argv[3:]) res = a.info_s3_bucket(name=args.name, choice=args.level) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def report_elb(self): ''' This function is a wrapper for parsing arguments and printing for elb attribute reports Tested :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser( description='report generation about elbs', usage='''kerrigan.py elb report_elb [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--columns', action='store', default=a.service_supported_columns(service="elb"), help="Which columns to display") parser.add_argument( '--filters', action='store', default=None, help= "The filters that should be used, example: key1:value1,key2:value2" ) args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(columns=args.columns, service="elb") if args.filters: filters = Misc.format_boto3_filter(filters=args.filters) else: filters = None result = a.information_elbs(columns=columns, filters=filters) for res in result: if self.account_information['logger_arguments']['table']: res['AvailabilityZones'] = Misc.list_to_multiline_string( list=res['AvailabilityZones']) res['SecurityGroups'] = Misc.list_to_multiline_string( list=res['SecurityGroups']) res['Instances'] = Misc.list_to_multiline_string( list=res['Instances']) else: res['AvailabilityZones'] = Misc.join_list_to_string( list=res['AvailabilityZones']) res['SecurityGroups'] = Misc.join_list_to_string( list=res['SecurityGroups']) res['Instances'] = Misc.join_list_to_string( list=res['Instances']) logger.output( data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def info_certs(self): logger.info("Going to list all certs") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam info_all [<args>]] ''' + self.global_options) args = parser.parse_args(sys.argv[3:]) a = awsrequests() res = a.server_certificates_info_all() for r in res: if self.cli['csv']: r['ELB'] = Misc.join_list_to_string(list=r['ELB']) elif self.cli['table']: r['ELB'] = Misc.list_to_multiline_string(r['ELB']) else: logger.error('There is an unhandled printing. Need to investigate') logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def list_buckets(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py s3 list_buckets [<args>]] ''' + self.global_options) parser.add_argument('--extended', action='store_true', default=False, help="Gather extended info about Buckets") args = parser.parse_args(sys.argv[3:]) res = a.list_s3_buckets(extended=args.extended) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def report_apigateway(self): ''' This function is a wrapper for parsing arguments and printing for apigateway attribute reports :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='report generation about apigateway', usage='''kerrigan.py apigateway report_apigateway [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--columns', action='store', default=a.service_supported_columns(service="sg").keys(), help="Which columns to display") args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(service="apigateway", columns=args.columns) result = a.information_apigateway(columns=columns) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def instance_status(self): logger.info("Started instance status command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='instance status about ami', usage='''kerrigan.py ami instance_Status [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--imageid', action='store', default=None, help="Only imageIds that should be queried") args = parser.parse_args(sys.argv[3:]) result = a.image_instance_status(imageid=args.imageid) for res in result: if self.account_information['logger_arguments']['table']: res['Instances'] = Misc.list_to_multiline_string(list=res['Instances']) else: res['Instances'] = Misc.join_list_to_string(list=res['Instances']) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def terminate_ec2(self): """ This function is a wrapper for parsing arguments and printing for ec2 instance termination Tested :return: """ a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='creation of ec2 instance', usage='''kerrigan.py ec2 create_ec2 [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--dry_run', action='store_true', default=False, help="For testing purpose only") parser.add_argument('--instanceids', action='store', required=True, help="A comma seperated list of instance id-s") args = parser.parse_args(sys.argv[3:]) instanceids = Misc.string_to_array(string=args.instanceids, split_char=",") result = a.terminate_instance(dryrun=args.dry_run, instanceids=instanceids) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def list_user_groups(self): logger.info("Going to list groups") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam list_user_groups [<args>]] ''' + self.global_options) parser.add_argument('--username', action='store', default=None, help="Should intermediate certificate be uploaded") args = parser.parse_args(sys.argv[3:]) a = awsrequests() res = a.list_user_groups(username=args.username) out = [] for r in res: if self.cli['csv']: res[r] = Misc.join_list_to_string(list=res[r]) elif self.cli['table']: res[r] = Misc.list_to_multiline_string(res[r]) out.append({'Username': r, 'Groups': res[r]}) logger.output(data=out, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def info(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py route53 info [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Environment to gather information about") args = parser.parse_args(sys.argv[3:]) res = a.route53_info(env=args.env) for r in res: if self.cli['csv']: r['Values'] = Misc.join_list_to_string(list=r['Values']) elif self.cli['table']: r['Values'] = Misc.list_to_multiline_string(r['Values']) else: logger.error('There is an unhandled printing. Need to investigate') # Add information if not present: if 'Weight' not in r: r['Weight'] = '-' r['SetIdentifier'] = '-' logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def info_all(self): # FIXME implement possbility to scope to env logger.info("Gathering all elbs") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py elb info_all [<args>]] ''' + self.global_options) args = parser.parse_args(sys.argv[3:]) e = awsrequests() res = e.elb_info_all() for r in res: if self.cli['csv']: r['Availability Zones'] = Misc.join_list_to_string(list=r['Availability Zones']) r['Securitygroups'] = Misc.join_list_to_string(list=r['Securitygroups']) r['InstanceIds'] = Misc.join_list_to_string(list=r['InstanceIds']) r['From-To-Protocol'] = Misc.join_list_to_string(list=r['From-To-Protocol']) elif self.cli['table']: r['Availability Zones'] = Misc.list_to_multiline_string(r['Availability Zones']) r['InstanceIds'] = Misc.list_to_multiline_string(r['InstanceIds']) r['Securitygroups'] = Misc.list_to_multiline_string(r['Securitygroups']) r['From-To-Protocol'] = Misc.list_to_multiline_string(r['From-To-Protocol']) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])
def report_ami(self): ''' This function is a wrapper for parsing arguments and printing for ami attribute reports :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='report generation about ami', usage='''kerrigan.py ami report_ami [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--columns', action='store', default=a.service_supported_columns(service="ami").keys(), help="Which columns to display") parser.add_argument('--filters', action='store', default=None, help="The filters that should be used, example: key1:value1,key2:value2") args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(service="ami", columns=args.columns) if args.filters: filters = Misc.format_boto3_filter(filters=args.filters) else: filters = None result = a.information_ami(columns=columns, filters=filters) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def report_ec2_instances(self): ''' This function is a wrapper for parsing arguments and printing for ec2 instance attribute reports Tested :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='report generation about ec2 instances', usage='''kerrigan.py ec2 report_ec2_instances [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--columns', action='store', default=a.service_supported_columns(service="ec2").keys(), help="Which columns to display") parser.add_argument('--filters', action='store', default=None, help="The filters that should be used, example: key1:value1,key2:value2") args = parser.parse_args(sys.argv[3:]) columns = Misc.parse_service_columns(service="ec2", columns=args.columns) if args.filters: filters = Misc.format_boto3_filter(filters=args.filters) else: filters = None result = a.information_ec2_instances(columns=columns, filters=filters) logger.output(data=result, csvvar=self.account_information['logger_arguments']['csv'], tablevar=self.account_information['logger_arguments']['table'])
def info_bucket(self): logger.info("Starting to gather information") a = awsrequests() parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py s3 info_bucket [<args>]] ''' + self.global_options) parser.add_argument('--name', action='store', help="Name of bucket", required=True) parser.add_argument('--level', action='store', choices=[ 'acl', 'lifecycle', 'region', 'logging', 'policy', 'replication', 'tagging' ], help="What information to return") args = parser.parse_args(sys.argv[3:]) res = a.info_s3_bucket(name=args.name, choice=args.level) logger.output(data=res, csvvar=self.cli['csv'], tablevar=self.cli['table'])