'Prepare to receive an event for an instance.
This will register an event for the given instance that we will
wait on later. This should be called before initiating whatever
action will trigger the event. The resulting eventlet.event.Event
object should be wait()\'d on to ensure completion.
:param instance: the instance for which the event will be generated
:param event_name: the name of the event we\'re expecting
:returns: an event object that should be wait()\'d on'

def prepare_for_instance_event(self, instance, event_name):

    if (self._events is None):
        raise exception.NovaException('In    shutdown,    no    new    events    can    be    scheduled')
    @utils.synchronized(self._lock_name(instance))
    def _create_or_get_event():
        instance_events = self._events.setdefault(instance.uuid, {})
        return instance_events.setdefault(event_name, eventlet.event.Event())
    LOG.debug('Preparing    to    wait    for    external    event    %(event)s', {'event': event_name}, instance=instance)
    return _create_or_get_event()
