当前位置: 首页>>代码示例>>Python>>正文


Python Misc.get_value_from_array_hash方法代码示例

本文整理汇总了Python中misc.Misc.get_value_from_array_hash方法的典型用法代码示例。如果您正苦于以下问题:Python Misc.get_value_from_array_hash方法的具体用法?Python Misc.get_value_from_array_hash怎么用?Python Misc.get_value_from_array_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在misc.Misc的用法示例。


在下文中一共展示了Misc.get_value_from_array_hash方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gather_information_for_cloudofrmation_parameters

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
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,代码行数:36,代码来源:Translater.py

示例2: info_all

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 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,代码行数:51,代码来源:elb.py

示例3: compare_elb_tags

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
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,代码行数:10,代码来源:elb.py

示例4: get_ami_stacks

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 def get_ami_stacks(self, account_id):
     '''
     This function returns all active ami Puppet_roles
     :param account_id: The account id that is being used. IAM wrapper returns this number
     :type account_id: int
     :return: Array of strings of valid puppet_roles
     :rtype: array
     '''
     images = self.get_images(account_id=account_id, filters=[{'Name': "tag-key", 'Values': ['Puppet_role']}])
     stacks = {}
     for i in images:
         v = Misc.get_value_from_array_hash(dictlist=i['Tags'], key='Puppet_role')
         if v is not "" and v is not None:
             stacks[v] = 1
     stacks = stacks.keys()
     logger.debug("Active stacks: " + str(stacks))
     return stacks
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:19,代码来源:ec2.py

示例5: rds_instance_filters

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
def rds_instance_filters(rds=None, filters=None):
    for f in filters:
        logger.debug("Filter investigation %s" % f, )
        if f['Name'] == "VpcId":
            if f['Values'][0] == rds.get('DBSubnetGroup').get('VpcId'):
                logger.info("This is the VPC we need for rds %s" % rds.get('DBSubnetGroup').get('VpcId'), )
            else:
                logger.debug("RDS is in wrong VPC")
                return False
        if f['Name'] == "tag:Name":
            if 'Tags' in rds:
                logger.debug("RDS instance has tags")
                tag_name = Misc.get_value_from_array_hash(dictlist=rds['Tags'], key='Name')
                if f['Values'][0] == tag_name:
                    logger.info("Tag name is same")
                    continue
            return False
    return True
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:20,代码来源:rds.py

示例6: create_elb

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 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,代码行数:21,代码来源:elb.py

示例7: get_all_subnets

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 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,代码行数:22,代码来源:vpc.py

示例8: get_active_envs

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 def get_active_envs(self, env=None):
     """
     This function returns an array with the active environemnts in the account
     :param env: a comma seperated list of environments that should be validated
     :type env: basestring
     :return: An array with active environments
     :rtype: list
     """
     vpcs = self.get_all_vpcs()
     envs = []
     for vpc in vpcs:
         cur = Misc.get_value_from_array_hash(dictlist=vpc['Tags'], key='Environment')
         if cur != "":
             envs.append(cur)
         else:
             logger.warning("Vpc has no Environment tag: %s" % (vpc.id))
     if env:
         envs = [env]
     logger.debug("Current envs: " + str(envs))
     return envs
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:22,代码来源:vpc.py

示例9: get_all_image_instances

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 def get_all_image_instances(self, imageid):
     if imageid:
         instances = self.ami_client.describe_instances(Filters=[{'Name': 'image-id', 'Values': [imageid]}])
     else:
         instances = self.ami_client.describe_instances()
     super(Ami, self).query_information(query=instances)
     temp = {}
     for reservation in instances['Reservations']:
         for instance in reservation['Instances']:
             if 'Tags' in instance:
                 value = Misc.get_value_from_array_hash(dictlist=instance.get('Tags'), key='Name')
             else:
                 value = instance.get('InstanceId')
             if instance['ImageId'] not in temp:
                 temp[instance['ImageId']] = [value]
             else:
                 temp[instance['ImageId']].append(value)
     ret = []
     for imageid in temp:
         img = {'ImageId': imageid}
         img['InstanceCount'] = len(temp[imageid])
         img['Instances'] = temp[imageid]
         ret.append(img)
     return ret
开发者ID:s4mur4i,项目名称:char-libv2,代码行数:26,代码来源:ami.py

示例10: test_get_value_from_array_hash_empty_array

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 def test_get_value_from_array_hash_empty_array(self):
     array_hash = []
     result = Misc.get_value_from_array_hash(dictlist=array_hash, key="test3")
     self.assertEqual(None, result)
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:6,代码来源:test_Misc.py

示例11: test_get_value_from_array_hash_invalid_key

# 需要导入模块: from misc import Misc [as 别名]
# 或者: from misc.Misc import get_value_from_array_hash [as 别名]
 def test_get_value_from_array_hash_invalid_key(self):
     array_hash = [{'Key': 'test', 'Value': 'test_value'}, {'Key': 'test2', 'Value': 'test2_value'}]
     result = Misc.get_value_from_array_hash(dictlist=array_hash, key="test3")
     self.assertEqual(None, result)
开发者ID:s4mur4i,项目名称:kerrigan,代码行数:6,代码来源:test_Misc.py


注:本文中的misc.Misc.get_value_from_array_hash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。