def override_replica_count(ringspec, input_model,
                           model_errors, model_warnings):
    """
    The replica count cannot be greater than the number of devices

    This function works out a replica count of a ring if there are not
    enough devices. For replicated rings, we will warn the user (but build
    the ring anyway). For EC rings, we generate an error (which will stop
    the process). If the replica count is ok, we return None. We also
    return None for EC rings as the replica count is not directly
    settable.

    :param ringspec: the ring specification in the input model
    :param input_model: the input model
    :param model_errors: we append any errors here
    :param model_warnings: we append any warning here
    :return: the appropriate replica count or None if it should not be changed
    """
    replica_count = ringspec.replica_count
    ring_name = ringspec.name
    num_devices = input_model.get_num_devices(ring_name)
    if num_devices == 0:
        model_errors.append('There are no devices assigned to'
                            ' ring %s' % ring_name)
        return None
    if replica_count > num_devices:
        if ringspec.replication_policy:
            model_warnings.append('In ring %s there are not enough devices -- '
                                  ' changing the replica'
                                  ' count to %s' % (ring_name, num_devices))
            return num_devices
        else:
            model_errors.append('In ring %s there are not enough devices to'
                                ' support this number of data and parity'
                                ' fragments' % ring_name)
    # No change needed
    return None