'Lists all events associated with a given stack.
It supports pagination (``limit`` and ``marker``),
sorting (``sort_keys`` and ``sort_dir``) and filtering(filters)
of the results.
:param cnxt: RPC context.
:param stack_identity: Name of the stack you want to get events for
:param filters: a dict with attribute:value to filter the list
:param limit: the number of events to list (integer or string)
:param marker: the ID of the last event in the previous page
:param sort_keys: an array of fields used to sort the list
:param sort_dir: the direction of the sort (\'asc\' or \'desc\').
:param nested_depth: Levels of nested stacks to list events for.'

@context.request_context
def list_events(self, cnxt, stack_identity, filters=None, limit=None, marker=None, sort_keys=None, sort_dir=None, nested_depth=None):

    stack_identifiers = None
    root_stack_identifier = None
    if stack_identity:
        st = self._get_stack(cnxt, stack_identity, show_deleted=True)
        if nested_depth:
            root_stack_identifier = st.identifier()
            all_r = resource_objects.Resource.get_all_by_root_stack(cnxt, st.id, None)
            stack_ids = {r.stack_id for r in six.itervalues(all_r)}
            stack_filters = {'id': stack_ids, 'nested_depth': list(range((nested_depth + 1)))}
            stacks = stack_object.Stack.get_all(cnxt, filters=stack_filters, show_nested=True)
            stack_identifiers = {s.id: s.identifier() for s in stacks}
            if (filters is None):
                filters = {}
            filters['stack_id'] = list(stack_identifiers.keys())
            events = list(event_object.Event.get_all_by_tenant(cnxt, limit=limit, marker=marker, sort_keys=sort_keys, sort_dir=sort_dir, filters=filters))
        else:
            events = list(event_object.Event.get_all_by_stack(cnxt, st.id, limit=limit, marker=marker, sort_keys=sort_keys, sort_dir=sort_dir, filters=filters))
            stack_identifiers = {st.id: st.identifier()}
    else:
        events = list(event_object.Event.get_all_by_tenant(cnxt, limit=limit, marker=marker, sort_keys=sort_keys, sort_dir=sort_dir, filters=filters))
        stack_ids = {e.stack_id for e in events}
        stacks = stack_object.Stack.get_all(cnxt, filters={'id': stack_ids}, show_nested=True)
        stack_identifiers = {s.id: s.identifier() for s in stacks}
    include_rsrc_prop_data = (filters and ('uuid' in filters))
    return [api.format_event(e, stack_identifiers.get(e.stack_id), root_stack_identifier, include_rsrc_prop_data) for e in events]
