def delete_deployment(self, restid, deploymentid): if self.dryrun: logger.info("Dryrun requested no changes will be done") return None ret = self.apigateway_client.delete_deployment(restApiId=restid, deploymentId=deploymentid) super(Apigateway, self).query_information(query=ret) return ret
def report_s3(self): ''' This function is a wrapper for parsing arguments and printing for s3 attribute reports :return: ''' logger.info("Started report generation command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser( description='report generation about s3', usage='''kerrigan.py s3 report_s3 [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument( '--columns', action='store', default=a.service_supported_columns(service="s3").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:])
def upload_apigateway(self): ''' This function is a wrapper for parsing arguments and uploading apigateway :return: ''' logger.info("Started upload command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser( description='upload apigateway', usage='''kerrigan.py apigateway upload_apigateway [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--json', metavar='FILE', required=True, type=lambda x: Misc.is_valid_file(parser, x), help="Which file to upload") parser.add_argument('--dryrun', action="store_true", default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) result = a.upload_apigateway(json=Misc.parse_file_to_json(args.json), dryrun=args.dryrun)
def create_method_response(self, restid, resourceid, method, statuscode, further_ops): """ This function creates a method response :param method: the method that is requested :type method: basestring :param restid: the id of the rest api object :type restid: basestring :param resourceid: id of a single resource object :type resourceid: basestring :param statuscode: the status code :type statuscode: basestring :param further_opts: This opt passes in json_data fur not mandatory options :type further_opts: dict :return: the created method response object """ if self.dryrun: logger.info("Dryrun requested no changes will be done") return None opts = {'restApiId': restid, 'resourceId': resourceid, 'httpMethod': method, 'statusCode': statuscode} if 'responseParameters' in further_ops: opts['responseParameters'] = further_ops['responseParameters'] if 'responseModels' in further_ops: opts['responseModels'] = further_ops['responseModels'] logger.debug("The opts sent to create method response %s" % opts) resp = self.apigateway_client.put_method_response(**opts) super(Apigateway, self).query_information(query=resp) return resp
def create_integration_response(self, restid, resourceid, method, statuscode, further_opts=None): """ This function creates an integration response object :param method: the method that is requested :type method: basestring :param restid: the id of the rest api object :type restid: basestring :param resourceid: id of a single resource object :type resourceid: basestring :param statuscode: thestatus code to attach integration response :type statuscode: basestring :param further_opts: This opt passes in json_data fur not mandatory options :type further_opts: dict :return: """ if self.dryrun: logger.info("Dryrun requested no changes will be done") return None opts = {'restApiId': restid, 'resourceId': resourceid, 'httpMethod': method, 'statusCode': statuscode} for element in ['selectionPattern', 'responseParameters', 'responseTemplates']: if element in further_opts: if further_opts[element] == "None": opts[element] = None else: opts[element] = further_opts[element] logger.debug("The opts sent to create integration response %s" % opts) resp = self.apigateway_client.put_integration_response(**opts) super(Apigateway, self).query_information(query=resp) return resp
def manage_gw_for_route53(self, ips=None, zoneid=None, domain=None, dryrun=None): logger.debug("Checking if need to add IPs to route53") records = self.list_zone_records(zoneid=zoneid) for ip in ips['active']: logger.debug("Checking ip %s" % (ip,)) if record_exists(records=records, name="broker.%s." % (domain,), ip=ip): logger.info("Found IP Entry %s in route53 domain %s" % (ip, domain)) continue else: logger.info("Did not find the IP in the route53, adding them") self.add_gw_to_route53(ips=ips['active'], zoneid=zoneid, domain=domain, dryrun=dryrun) logger.debug("Ips have been updated, no point on checking further") break logger.debug("Checking if need to remove IPs from route53") records = self.list_zone_records(zoneid=zoneid) for ip in ips['deactive']: logger.debug("Checking if deactivate IP %s is active" % (ip,)) if record_exists(records=records, name="broker.%s." % (domain,), ip=ip): logger.info("Need to remove entry %s from route53" % (ip,)) self.add_gw_to_route53(ips=ips['active'], zoneid=zoneid, domain=domain, dryrun=dryrun) logger.debug("Ips have been updated, no point on checking further") break if dryrun: logger.debug("Dryrun configured, no need to test") return True logger.info("Refreshing records to see if change in place") records = self.list_zone_records(zoneid=zoneid) for record in records: if record['Name'] == "broker.%s." % (domain,): if len(record['ResourceRecords']) == len(ips['active']): logger.info("Length of current records equals actice records") else: logger.error("Length does not equal, something went wrong") break
def create_method(self, restid, resourceid, method, authorizationtype, apikeyreq=False, further_opts=None): """ This function creates a method object :param method: the method that is requested :type method: basestring :param restid: the id of the rest api object :type restid: basestring :param resourceid: id of a single resource object :type resourceid: basestring :param authorizationtype: :type authorizationtype: basestring :param apikeyreq: should apikey be required :type apikeyreq: bool :param further_opts: This opt passes in json_data fur not mandatory options :type further_opts: dict :return: the created method object """ if self.dryrun: logger.info("Dryrun requested no changes will be done") return None if isinstance(apikeyreq, bool) is False: logger.debug("apikey is not boolean, converting") apikeyreq = Misc.str2bool(apikeyreq) opts = {'restApiId': restid, 'resourceId': resourceid, 'httpMethod': method, 'authorizationType': authorizationtype, 'apiKeyRequired': apikeyreq} if 'requestParameters' in further_opts: opts['requestParameters'] = further_opts['requestParameters'] if 'requestModels' in further_opts: opts['requestModels'] = further_opts['requestModels'] logger.debug("The opts sent to create method %s" % opts) resp = self.apigateway_client.put_method(**opts) super(Apigateway, self).query_information(query=resp) return resp
def server_certificate_upload(self, cert_name=None, pub_key=None, priv_key=None, cert_chain=None): i = Iam() if pub_key and os.path.isfile(pub_key): with open(pub_key, "r") as pub_key_fh: pub_key = pub_key_fh.read() logger.info("Read pub_key to internal variable: %s" % pub_key, ) if priv_key and os.path.isfile(priv_key): with open(priv_key, "r") as priv_key_fh: priv_key = priv_key_fh.read() logger.info("Read priv_key to internal variable: %s" % priv_key, ) if cert_chain and os.path.isfile(cert_chain): with open(cert_chain, "r") as cert_chain_fh: cert_chain = cert_chain_fh.read() logger.debug( "Read cert_chain to internal variable: %s" % cert_chain, ) out = i.upload_server_cert(cert_name=cert_name, pub_key=pub_key, priv_key=priv_key, cert_chain=cert_chain) print "ServerCertificateId: %s" % out['ServerCertificateMetadata'][ 'ServerCertificateId']
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 check(self): # FIXME this whole is broken, and should be dynamic logger.info("Doing config check in AWS") parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py env check [<args>]] ''' + self.global_options)
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 create_integration(self, restid, resourceid, method, integration_type, further_opts=None): """ This function creates an integration object :param method: the method that is requested :type method: basestring :param restid: the id of the rest api object :type restid: basestring :param resourceid: id of a single resource object :type resourceid: basestring :param integration_type: an enum of the integration type :type integration_type: basestring :param further_opts: This opt passes in json_data fur not mandatory options :type further_opts: dict :return: object of the created integration """ if self.dryrun: logger.info("Dryrun requested no changes will be done") return None opts = {'restApiId': restid, 'resourceId': resourceid, 'httpMethod': method, 'type': integration_type, 'integrationHttpMethod': method} # There is aws cli bug and integrationHttpMethod also needs to be added. may change later # opts = {'restApiId': restid, 'resourceId': resourceid, 'httpMethod': method, 'type': integration_type} for element in ['integrationHttpMethod', 'uri', 'credentials', 'requestParameters', 'requestTemplates', 'cacheNamespace', 'cacheNamespace']: if element in further_opts: opts[element] = further_opts[element] logger.debug("The opts for integration object creation: %s" % opts) resp = self.apigateway_client.put_integration(**opts) super(Apigateway, self).query_information(query=resp) return resp
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 stack(self): logger.info("Starting to gather information") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py upgrade stack [<args>]] ''' + self.global_options) parser.add_argument('--stack', action='store', help="Which stack to upgrade",required=True) parser.add_argument('--env', action='store', help="Which env to do tasks in",required=True) args = parser.parse_args(sys.argv[3:])
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 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 check(self): # FIXME broken, need to fix logger.info("Checking ELB standards") parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py elb check [<args>]] ''' + self.global_options)
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 query_parameter_group(self): logger.info("Gather parameter group values") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py rds query_parameter_group [<args>]] ''' + self.global_options) parser.add_argument('--name', action='store', help="Name of db-parameter group") args = parser.parse_args(sys.argv[3:]) e = awsrds() ret = e.get_parameter_group(name=args.name)
def record_exists(records=None, name=None, ip=None): for record in records: if record['Name'] == name: for r in record['ResourceRecords']: if r['Value'] == ip: logger.info("Found IP Entry %s in route53" % (ip,)) return True return False
def compare_certs(self): logger.info("Going to check env certs") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam compare_certs [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Envs to check") args = parser.parse_args(sys.argv[3:]) a = awschecks() a.compare_certs(env=args.env)
def compare(self): logger.info("Starting to gather information") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py s3 compare [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Name of env") args = parser.parse_args(sys.argv[3:]) c = awschecks() c.compare_s3(env=args.env)
def delete_server_cert(self): logger.info("Going to delete cert") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam delete_server_cert [<args>]] ''' + self.global_options) parser.add_argument('--cert_name', action='store', help="Name of certificate to delete") args = parser.parse_args(sys.argv[3:]) a = awsrequests() a.server_certificate_delete(cert_name=args.cert_name)
def gw_watchdog(self): logger.info("Starting watchdog") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py route53 watchdog [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Environment to gather information about") args = parser.parse_args(sys.argv[3:]) a = awsservice() a.gw_watchdog(env=args.env)
def compare(self): logger.info("Creating ELB") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py elb create [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Which env to check") args = parser.parse_args(sys.argv[3:]) c = awschecks() c.compare_elb(env=args.env)
def compare(self): logger.info("Starting comparing route53 entries") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py route53 compare [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Environment to gather information about") parser.add_argument('--dryrun', action='store_true',default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) a = awschecks() a.compare_route53(env=args.env,dryrun=args.dryrun)
def compare_iam(self): logger.info("Going to check env iam certificates") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam compare_iam [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Envs to check") parser.add_argument('--dryrun', action='store_true', default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) a = awschecks() a.compare_iam(env=args.env, dryrun=args.dryrun)
def sync_instances(self): logger.info("Syncing Instances to ELB") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py elb sync_instances [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Which env to check") parser.add_argument('--dryrun', action='store_true',default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) c = awschecks() c.sync_instances_to_elbs(env=args.env,dryrun=args.dryrun)
def validate_kerrigan_json(stack_data, env): # do some tests logger.debug(msg="Validating if stack can be deployed to env") if 'envs' in stack_data and env in stack_data['envs']: logger.info(msg="Stack can be deployed to environment %s" % (env,)) else: logger.error(msg="Stack should not be deployed to Environment %s" % (env,)) exit(20) return stack_data
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 compare(self): logger.info("Starting to gather information") parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py s3 compare [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Name of env") args = parser.parse_args(sys.argv[3:]) c = awschecks() c.compare_s3(env=args.env)
def overflow(self): logger.info("Started stack provision command") a = awsrequests(session=self.account_information['session']) parser = argparse.ArgumentParser(description='stack provision', usage='''kerrigan.py stack overflow [<args>]] ''' + self.global_options, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="kerrigan") parser.add_argument('--json', action='store', required=True, help="Stack json to provision") parser.add_argument('--env', action='store', required=True, help="Which env to deploy to") parser.add_argument('--dryrun', action='store_true', default=False, help="No changes should be done") args = parser.parse_args(sys.argv[3:]) a.deploy_stack_to_env(env=args.env, file=args.json, dryrun=args.dryrun)
def generate_elb_name(self, stack=None, facing=None, env=None): if facing == "internal": avail = "int" else: avail = "pub" lb_name = env + "-" + avail + "-" + stack if len(lb_name) > 32: logger.error("ELB name is longer than 32 chars. there will be an issue creating the elb") logger.info("ELB name is going to be: %s" % lb_name, ) return lb_name
def change_record_for_zoneid(self, zoneid=None, changebatch=None, dryrun=None): if dryrun: logger.debug("Dryrun requested") logger.warning("Not running changebatch: %s" % changebatch, ) return True ret = self.boto3.change_resource_record_sets(HostedZoneId=zoneid, ChangeBatch=changebatch) if ret['ResponseMetadata']['HTTPStatusCode'] == 200: logger.info("Change was succesful") else: logger.error("There was an issue with the change")
def compare(self): logger.info("Going to compare security groups") a = awsrequests() parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py instance compare_securitygroups [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Environment to check") parser.add_argument('--dryrun', action='store_true', default=False, help="No actions should be taken") args = parser.parse_args(sys.argv[3:]) a = awschecks() a.compare_securitygroups(env=args.env, dryrun=args.dryrun)
def put_rest_api(self, restid, parameters, body, mode="overwrite", failonwarnings=True): if self.dryrun: logger.info("Dryrun requested no changes will be done") return None args = {'restApiId': restid, 'body': body, 'mode': mode, 'failOnWarnings': failonwarnings} if parameters: args['parameters'] = parameters resp = self.apigateway_client.put_rest_api(**args) super(Apigateway, self).query_information(query=resp) return resp
def import_rest_api(self, restid, parameters, body): if self.dryrun: logger.info("Dryrun requested no changes will be done") return None args = {'restApiId': restid, 'body': body} if parameters: args['parameters'] = parameters resp = self.apigateway_client.import_rest_api(**args) super(Apigateway, self).query_information(query=resp) return resp
def compare(self): logger.info("Creating ELB") parser = argparse.ArgumentParser( description='ec2 tool for devops', usage='''kerrigan.py elb create [<args>]] ''' + self.global_options) parser.add_argument('--env', action='store', help="Which env to check") args = parser.parse_args(sys.argv[3:]) c = awschecks() c.compare_elb(env=args.env)
def update(self): logger.info("Going to update env certs") parser = argparse.ArgumentParser(description='ec2 tool for devops', usage='''kerrigan.py iam update [<args>]] ''' + self.global_options) parser.add_argument('--domain', action='store', required=True, help="Which domain cert to update: example: star.dev.xively.com") parser.add_argument('--intermediate', action='store_true', default=False, help="Should intermediate certificate be uploaded") args = parser.parse_args(sys.argv[3:]) a = awsrequests() a.server_certficate_update(domain=args.domain, intermediate=args.intermediate)
def create_deployment(self, restid, stagename, stagedesc, desc, cacheclusterenabled, cacheclustersize=None): if self.dryrun: logger.info("Dryrun requested no changes will be done") return None args = {'restApiId': restid, 'stageName': stagename, 'stageDescription': stagedesc, 'description': desc} if cacheclusterenabled: args.update({'cacheClusterEnabled': cacheclusterenabled, 'cacheClusterSize': cacheclustersize}) else: args['cacheClusterEnabled'] = cacheclusterenabled resp = self.apigateway_client.create_deployment(**args) super(Apigateway, self).query_information(query=resp) return resp
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 listener_has_cert(listeners=None, cert=None): for listener in listeners: if 'Listener' in listener and 'SSLCertificateId' in listener['Listener']: logger.info("listener has certificate ID, inspecting") if listener['Listener']['SSLCertificateId'] == cert: logger.info("Certificate is used for elb") return True else: logger.debug("ELB listener has different cert") else: logger.debug("ELB has no cert or listener") return False
def ec_launch_status(self, instanceids, dryrun): """ This function uses the waiter to wait till the instance reaches a running state :param instanceids: The instance object returned by describe_intance or run_instance :type instanceids: boto3.Ec2 :param dryrun: If the operation is only dryrun, and no changes should be done :type dryrun: bool :return: None """ logger.info("Checking launch status of %s" % (instanceids,)) waiter = self.ec2_client.get_waiter('instance_running') waiter.wait(DryRun=dryrun, InstanceIds=instanceids)