本文整理汇总了Python中misc.Misc类的典型用法代码示例。如果您正苦于以下问题:Python Misc类的具体用法?Python Misc怎么用?Python Misc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Misc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gather_information_for_cloudofrmation_parameters
def gather_information_for_cloudofrmation_parameters(stack_data, vpc, ami):
parameters = []
env = Misc.get_value_from_array_hash(dictlist=vpc.get('Tags'), key="Environment")
if 'cloudformation_parameters' in stack_data:
for parameter in stack_data['cloudformation_parameters']:
if parameter["ParameterKey"] == "Environment":
parameters.append({"ParameterKey": "Environment", "ParameterValue": env, "UsePreviousValue": False})
elif parameter["ParameterKey"] == "InstanceType":
instance = None
if 'instance_type' in stack_data and env in stack_data['instance_type']:
instance = stack_data["instance_type"][env]
else:
instance = Misc.get_value_from_array_hash(dictlist=ami.get('Tags'), key="Instancetype")
parameters.append(
{"ParameterKey": "InstanceType", "ParameterValue": instance, "UsePreviousValue": False})
elif parameter["ParameterKey"] == "Puppetrole":
parameters.append({"ParameterKey": "Puppetrole", "ParameterValue": stack_data['puppet_role'],
"UsePreviousValue": False})
elif parameter["ParameterKey"] == "XivelyService":
parameters.append({"ParameterKey": "XivelyService", "ParameterValue": stack_data['xively_service'],
"UsePreviousValue": False})
elif parameter["ParameterKey"] == "Ami":
parameters.append(
{"ParameterKey": "Ami", "ParameterValue": stack_data['ami'], "UsePreviousValue": False})
elif parameter["ParameterKey"] == "KeyName":
key = Misc.get_value_from_array_hash(dictlist=vpc.get('Tags'), key="Keypair")
parameters.append({"ParameterKey": "KeyName", "ParameterValue": key, "UsePreviousValue": False})
else:
parameter["UsePreviousValue"] = False
parameters.append(parameter)
else:
logger.warning(msg="No cloudformation parameter object in json")
logger.debug(msg="Cloudformation parameters is: %s" % (parameters,))
return parameters
示例2: main
def main():
killer = Killer()
args = _parse_argv()
logger = get_logger("DNSWatch", log_level=args.loglevel, log_file=args.logfile)
logger.info("Starting dnswatch v.{}.".format(__version__))
misc = Misc(logger)
try:
exit_code = 2
if not get_lock("dnswatch", timeout=5):
misc.die("Lock exists")
c = Config()
action = None
while True:
config = c.read(args.config)
dw = DNSWatch(config)
if action == 'reload':
dw.reload_config()
else:
dw.initial_config()
try:
action = dw.watch(pause=config["watch"]["pause"])
except:
action = dw.watch()
if action == "kill":
# Do DNS cleanup and exit loop
dw.cleanup()
break
elif action == "softkill":
# Exit loop without DNS cleanup
break
elif action == "reload":
# Do nothing
pass
else:
misc.die("Unknown action requested: {}".format(action))
logger.info("Finished successfully.")
exit_code = 0
except SystemExit:
exit_code = sys.exc_info()[1]
except:
logger.error("Exiting with errors.")
if args.trace:
print(sys.exc_info())
trace = sys.exc_info()[2]
traceback.print_tb(trace)
exit_code = 1
finally:
sys.exit(exit_code)
示例3: report_elb
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'])
示例4: upload_apigateway
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)
示例5: info_certs
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'])
示例6: instance_status
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'])
示例7: __init__
def __init__(self):
print "Starting account creation and buildup"
self.step = 0
from misc import Misc
from core.base import base
base = base()
if Misc.confirm(prompt="Are you sure you want to create an account infrastructure?", resp=False):
self.account = base.get_account_information()
if 'profile_name' in self.account['cli_arguments']:
print "Aws account has been provided"
else:
logger.error("Aws account not provided")
exit(1)
if 'region_name' in self.account['cli_arguments']:
print "Aws region has been provided"
else:
logger.error("Aws region not provided")
exit(1)
if 'session' in self.account and self.account['session'] is not (None or ""):
logger.info("Session object created succesfully")
else:
logger.error("Aws Session not created successfuly")
exit(1)
self.run_workflow()
else:
print "You are not prepared - Illidian"
示例8: create_method
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
示例9: compare_elb_tags
def compare_elb_tags(elb_tags=None, tags=None):
for tag in tags:
elb_tag_value = Misc.get_value_from_array_hash(dictlist=elb_tags, key=tag)
if elb_tag_value == tags[tag]:
continue
else:
return False
return True
示例10: list_user_groups
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'])
示例11: create_elb
def create_elb(self, name=None, listeners=None, scheme=None, tags=None, env=None, sg_name=None):
subnets = self.get_subnets_for_elb(scheme=scheme, env=env)
yaml_tags = Misc.get_yaml_tags_for_sub(sub="elb")
lb_name = self.generate_elb_name(stack=name, facing=scheme, env=env)
for y in yaml_tags:
logger.debug("Checking if tag exists %s" % y, )
if y == "Environment":
tags.append({'Key': y, 'Value': env})
continue
if y == "Name":
tags.append({'Key': y, 'Value': lb_name})
continue
t = Misc.get_value_from_array_hash(dictlist=tags, key=y)
if t is None:
tags.append({'Key': y, 'Value': ""})
sgs = self.get_sgs_for_elb(env=env, name=sg_name)
self.elb.create_load_balancer(LoadBalancerName=lb_name, Scheme=scheme, Tags=tags, SecurityGroups=sgs,
Subnets=subnets, Listeners=listeners)
return lb_name
示例12: __init__
def __init__(self, config, sync=True):
self.logger = logging.getLogger("DNSWatch.Route53")
self.misc = Misc(self.logger)
self.config = config
self.sync = sync
self.unchecked_requests = list()
self.client = boto3.client(
"route53",
aws_access_key_id=config["update_key"]["name"],
aws_secret_access_key=config["update_key"]["key"])
示例13: info
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'])
示例14: get_all_subnets
def get_all_subnets(self, filters=None, subnetids=None):
"""
This function returns all subnets, or filters them as requested
:param filters: A dict list with the boto3 filters
:param subnetids: A list of subnetids that should only be returned
:return: A list of subnets that were requested
"""
if subnetids:
response = self.vpc_client.describe_subnets(SubnetIds=subnetids)
elif filters:
response = self.vpc_client.describe_subnets(Filters=filters)
else:
response = self.vpc_client.describe_subnets()
result = []
for s in response['Subnets']:
allowed = Misc.get_value_from_array_hash(dictlist=s.get('Tags'), key="Allowed")
if Misc.str2bool(allowed):
result.append(s)
logger.debug("Allowed az subnets are: %s" % (result,))
return result
示例15: __init__
def __init__(self, config):
self.logger = logging.getLogger("DNSWatch.BindProvider")
self.misc = Misc(self.logger)
self.dhcl = DHClient()
self.dnso = DNSOps(config["dnsupdate"])
self.zone = config["dnsupdate"]["zone"]
self.fqdn = config["host"]["fqdn"]
self.private_ip = config["host"]["private_ip"]
self.public_ip = config["host"]["public_ip"]
self.alias_dict = config["dnsupdate"]["alias"]
self.aliases = None