'List running instances (on all compute nodes).
This method returns a dictionary with the following keys:
- used_images
- instance_names
- used_swap_images'

def _list_running_instances(self, context, all_instances):

    used_images = {}
    instance_names = set()
    used_swap_images = set()
    instance_bdms = objects.BlockDeviceMappingList.bdms_by_instance_uuid(context, [instance.uuid for instance in all_instances])
    for instance in all_instances:
        instance_names.add(instance.name)
        instance_names.add(instance.uuid)
        if ((instance.task_state in self.resize_states) or (instance.vm_state == vm_states.RESIZED)):
            instance_names.add((instance.name + '_resize'))
            instance_names.add((instance.uuid + '_resize'))
        for image_key in ['image_ref', 'kernel_id', 'ramdisk_id']:
            image_ref_str = getattr(instance, image_key)
            if (image_ref_str is None):
                continue
            (local, remote, insts) = used_images.get(image_ref_str, (0, 0, []))
            if (instance.host == CONF.host):
                local += 1
            else:
                remote += 1
            insts.append(instance.name)
            used_images[image_ref_str] = (local, remote, insts)
        bdms = instance_bdms.get(instance.uuid)
        if bdms:
            swap = driver_block_device.convert_swap(bdms)
            if swap:
                swap_image = ('swap_' + str(swap[0]['swap_size']))
                used_swap_images.add(swap_image)
    return {'used_images': used_images, 'instance_names': instance_names, 'used_swap_images': used_swap_images}
