Applies the values of the resource dictionaries to infra traffic resources,
    creating the infra traffic resource if required
    (vim.DistributedVirtualSwitchProductSpec)

def _apply_dvs_infrastructure_traffic_resources(infra_traffic_resources,
                                                resource_dicts):
    '''
    Applies the values of the resource dictionaries to infra traffic resources,
    creating the infra traffic resource if required
    (vim.DistributedVirtualSwitchProductSpec)
    '''
    for res_dict in resource_dicts:
        filtered_traffic_resources = \
                [r for r in infra_traffic_resources if r.key == res_dict['key']]
        if filtered_traffic_resources:
            traffic_res = filtered_traffic_resources[0]
        else:
            traffic_res = vim.DvsHostInfrastructureTrafficResource()
            traffic_res.key = res_dict['key']
            traffic_res.allocationInfo = \
                    vim.DvsHostInfrastructureTrafficResourceAllocation()
            infra_traffic_resources.append(traffic_res)
        if res_dict.get('limit'):
            traffic_res.allocationInfo.limit = res_dict['limit']
        if res_dict.get('reservation'):
            traffic_res.allocationInfo.reservation = res_dict['reservation']
        if res_dict.get('num_shares') or res_dict.get('share_level'):
            if not traffic_res.allocationInfo.shares:
                traffic_res.allocationInfo.shares = vim.SharesInfo()
        if res_dict.get('share_level'):
            traffic_res.allocationInfo.shares.level = \
                    vim.SharesLevel(res_dict['share_level'])
        if res_dict.get('num_shares'):
            #XXX Even though we always set the number of shares if provided,
            #the vCenter will ignore it unless the share level is 'custom'.
            traffic_res.allocationInfo.shares.shares = res_dict['num_shares']