def _get_port_speed_price_id(items, port_speed, no_public, location):
    """Choose a valid price id for port speed."""

    for item in items:
        if utils.lookup(item,
                        'itemCategory',
                        'categoryCode') != 'port_speed':
            continue

        # Check for correct capacity and if the item matches private only
        if any([int(utils.lookup(item, 'capacity')) != port_speed,
                _is_private_port_speed_item(item) != no_public,
                not _is_bonded(item)]):
            continue

        for price in item['prices']:
            if not _matches_location(price, location):
                continue

            return price['id']

    raise SoftLayer.SoftLayerError(
        "Could not find valid price for port speed: '%s'" % port_speed)
Choose a valid price id for port speed.