本文整理汇总了Python中misc.Misc类的典型用法代码示例。如果您正苦于以下问题:Python Misc类的具体用法?Python Misc怎么用?Python Misc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Misc类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:34,代码来源:Translater.py
示例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)
开发者ID:nixargh,项目名称:dnswatch,代码行数:58,代码来源:main.py
示例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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:32,代码来源:elb.py
示例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)
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:14,代码来源:apigateway.py
示例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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:15,代码来源:iam.py
示例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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:16,代码来源:ami.py
示例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"
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:26,代码来源:drone.py
示例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
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:33,代码来源:apigateway.py
示例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
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:8,代码来源:elb.py
示例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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:17,代码来源:iam.py
示例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
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:19,代码来源:elb.py
示例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"])
开发者ID:nixargh,项目名称:dnswatch,代码行数:10,代码来源:route53.py
示例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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:20,代码来源:route53.py
示例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
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:20,代码来源:vpc.py
示例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
开发者ID:nixargh,项目名称:dnswatch,代码行数:12,代码来源:dnsproviders.py
示例16: test_str2bool_false
def test_str2bool_false(self):
self.assertFalse(Misc.str2bool("false"))
self.assertFalse(Misc.str2bool("False"))
self.assertFalse(Misc.str2bool("f"))
self.assertFalse(Misc.str2bool("0"))
self.assertFalse(Misc.str2bool("no"))
self.assertFalse(Misc.str2bool("ILIKECARS"))
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:7,代码来源:test_Misc.py
示例17: report_ami
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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:22,代码来源:ami.py
示例18: get_account_id
def get_account_id(self):
"""
This functions extracts the AWS account id from the user object
:return: the AWs account id
:rtype: int
"""
user_data = self.get_user()
if 'Arn' in user_data:
arn = user_data['Arn']
ret = Misc.parse_arn(arn=arn)['account-id']
else:
logger.error("Can not determine the Account ID, User has no ARN")
raise ValueError
return ret
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:14,代码来源:iam.py
示例19: report_apigateway
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'])
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:16,代码来源:apigateway.py
示例20: info_all
def info_all(self):
elbs = self.get_all_elbs()
result = []
yaml = Misc.get_aws_yaml(yaml_file="elb")
V = Vpc()
for lb in elbs:
tmp = lb['LoadBalancerName'].split('-')
if len(tmp) >= 3:
elb_env = tmp.pop(0)
short_env = tmp.pop(0)
elb_stack = "-".join(tmp)
elb_facing = lb['Scheme']
if elb_stack in yaml and elb_facing in yaml[elb_stack]:
yaml_info = yaml[elb_stack][elb_facing]
v = V.get_vpc_from_env(env=elb_env)
domain = Misc.get_value_from_array_hash(dictlist=v.get('Tags'), key="Domain")
if elb_facing == "internet-facing":
elb_dns_name = yaml_info['dns'] + "." + Misc.change_domain_to_local(domain=domain)
elif elb_facing == "internal":
elb_dns_name = yaml_info['dns'] + "." + Misc.change_domain_to_local(domain=domain)
else:
elb_dns_name = None
info = {}
if elb_dns_name is not None:
info['DNS cname'] = elb_dns_name
else:
info['DNS cname'] = "This elb is not in automatisation framework. Will be decomissioned"
info['Xively_service'] = Misc.get_value_from_array_hash(dictlist=lb.get('Tags'), key="Xively_service")
info['Puppet_role'] = Misc.get_value_from_array_hash(dictlist=lb.get('Tags'), key="Puppet_role")
info['Env'] = Misc.get_value_from_array_hash(dictlist=lb.get('Tags'), key="Environment")
info['Real endpoint'] = lb['DNSName']
info['Vpcid'] = lb['VPCId']
info['Name'] = lb['LoadBalancerName']
info['CreateTime'] = lb['CreatedTime'].strftime("%Y-%m-%d %H:%M")
info['Facing'] = elb_facing
info['Availability Zones'] = lb['AvailabilityZones']
info['Securitygroups'] = lb['SecurityGroups']
instance = []
for i in lb['Instances']:
instance.append(i['InstanceId'])
info['InstanceIds'] = instance
listen = []
for listener in lb['ListenerDescriptions']:
listener = listener['Listener']
listen.append(
"%s-%s-%s" % (listener['LoadBalancerPort'], listener['InstancePort'], listener['Protocol']))
info['From-To-Protocol'] = listen
result.append(info)
return result
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:49,代码来源:elb.py
注:本文中的misc.Misc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论