- def _get_candidates(candidate_info):
- return [dict(inventory_type=x['candidateType'], candidate_id=x['candidates']) for x in candidate_info]
- properties = []
- for policy in policies:
- for resourceInstanceType in policy['content']['resourceInstanceType']:
- if resourceInstanceType in demand['resourceModuleName']:
- for x in policy['content']['property']:
- property = dict(inventory_provider=x['inventoryProvider'],
- inventory_type=x['inventoryType'],
- service_resource_id=demand['serviceResourceId'])
- if 'attributes' in x:
- attributes = {}
- for k,v in x['attributes'].items():
- # key=data_mapping.convert(k)
- key = k
- attributes[key] = v
- if(key=="model-invariant-id"):
- attributes[key]=demand['resourceModelInfo']['modelInvariantId']
- elif(key=="model-version-id"):
- attributes[key]=demand['resourceModelInfo']['modelVersionId']
- property.update({"attributes": attributes})
- if x['inventoryType'] == "cloud":
- property['region'] = {'get_param': "CHOSEN_REGION"}
- if 'exclusionCandidateInfo' in demand:
- property['excluded_candidates'] = _get_candidates(demand['exclusionCandidateInfo'])
- if 'requiredCandidateInfo' in demand:
- property['required_candidates'] = _get_candidates(demand['requiredCandidateInfo'])
- properties.append(property)
- if len(properties) == 0:
- properties.append(dict(customer_id="", service_type="", inventory_provider="", inventory_type=""))
- return properties
+ demand_properties = []
+ for policy_property in get_policy_properties(demand, policies):
+ prop = dict(inventory_provider=policy_property['inventoryProvider'],
+ inventory_type=policy_property['inventoryType'],
+ service_resource_id=demand['serviceResourceId'])
+ if 'attributes' in policy_property:
+ prop['attributes'] = get_augmented_policy_attributes(policy_property, demand)
+ for k1, v1, k2, v2 in policy_config_mapping['extra_fields']:
+ if k1 == v1:
+ prop[k2] = v2
+ prop.update(get_candidates_demands(demand)) # for excluded and partial-rehoming cases
+ demand_properties.append(prop)
+ return demand_properties