'Find all datasets that are currently associated with this host and
return a ``BlockDeviceDeployerLocalState`` containing all the datasets
that are not manifest or are located on this node.'

def discover_state(self, cluster_state, persistent_state):

    raw_state = self._discover_raw_state()
    datasets = {}
    for volume in raw_state.volumes:
        dataset_id = volume.dataset_id
        owning_blockdevice_id = persistent_state.blockdevice_ownership.get(dataset_id)
        if (owning_blockdevice_id is None):
            datasets[dataset_id] = DiscoveredDataset(state=DatasetStates.UNREGISTERED, dataset_id=dataset_id, maximum_size=volume.size, blockdevice_id=volume.blockdevice_id)
        elif (volume.blockdevice_id != owning_blockdevice_id):
            if (volume.attached_to is not None):
                UNREGISTERED_VOLUME_ATTACHED(dataset_id=dataset_id, block_device_id=volume.blockdevice_id).write()
        elif (dataset_id in raw_state.devices):
            device_path = raw_state.devices[dataset_id]
            mount_point = self._mountpath_for_dataset_id(unicode(dataset_id))
            if ((device_path in raw_state.system_mounts) and (raw_state.system_mounts[device_path] == mount_point)):
                datasets[dataset_id] = DiscoveredDataset(state=DatasetStates.MOUNTED, dataset_id=dataset_id, maximum_size=volume.size, blockdevice_id=volume.blockdevice_id, device_path=device_path, mount_point=mount_point)
            else:
                if (device_path in raw_state.devices_with_filesystems):
                    state = DatasetStates.ATTACHED
                else:
                    state = DatasetStates.ATTACHED_NO_FILESYSTEM
                datasets[dataset_id] = DiscoveredDataset(state=state, dataset_id=dataset_id, maximum_size=volume.size, blockdevice_id=volume.blockdevice_id, device_path=device_path)
        elif (volume.attached_to in (None, raw_state.compute_instance_id)):
            datasets[dataset_id] = DiscoveredDataset(state=DatasetStates.NON_MANIFEST, dataset_id=dataset_id, maximum_size=volume.size, blockdevice_id=volume.blockdevice_id)
        else:
            if raw_state.is_known_dead_instance(volume.attached_to):
                state = DatasetStates.ATTACHED_TO_DEAD_NODE
            else:
                state = DatasetStates.ATTACHED_ELSEWHERE
            datasets[dataset_id] = DiscoveredDataset(state=state, dataset_id=dataset_id, maximum_size=volume.size, blockdevice_id=volume.blockdevice_id)
    for (dataset_id, blockdevice_id) in persistent_state.blockdevice_ownership.items():
        if (dataset_id not in datasets):
            datasets[dataset_id] = DiscoveredDataset(state=DatasetStates.REGISTERED, dataset_id=dataset_id, blockdevice_id=blockdevice_id)
    local_state = BlockDeviceDeployerLocalState(node_uuid=self.node_uuid, hostname=self.hostname, datasets=datasets)
    return succeed(local_state)
