def METHOD_NAME(network_location):
    """
    Perform a connection check that the network location is contactable and the instance ID matches
    what we expect, or if there was a previous conflict from an instance ID mismatch, we'll check
    the facilities as the final source of truth
    :param network_location: The network location modal
    :type network_location: kolibri.core.discovery.models.NetworkLocation
    """
    from kolibri.core.auth.models import Facility
    prior_status = network_location.connection_status
    with capture_connection_state(network_location):
        with NetworkClient.build_from_network_location(network_location) as client:
            client.connect()
            # if the last connection attempt resulted in a conflict, likely from instance ID
            # mismatch, then we fall back to checking the facilities
            if prior_status == ConnectionStatus.Conflict:
                response = client.get("api/public/v1/facility")
                network_location_facilities = response.json()
                network_location_facility_ids = [
                    f.get("id") for f in network_location_facilities
                ]
                if not Facility.objects.filter(
                    id__in=network_location_facility_ids
                ).exists():
                    raise errors.NetworkLocationConflict(
                        "Instance does not have matching facility"
                    )
            elif (
                not network_location.reserved
                and network_location.instance_id
                and network_location.instance_id
                != client.device_info.get("instance_id")
            ):
                raise errors.NetworkLocationConflict(
                    "Instances do not match | {} != {}".format(
                        network_location.instance_id,
                        client.device_info.get("instance_id"),
                    )
                )
            # finally, capture the location's network state (ip, url, etc)
            capture_network_state(network_location, client)