diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-07-06 18:30:04 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-07-06 18:30:04 +0000 |
commit | 914921d26a81db02f4e92b37d5087a39f2a262bc (patch) | |
tree | dd426ff63b5b574c64cd38e504d99e495a68ec6d /heatclient/common | |
parent | 1f73c958c45121c1ec4f83a55763263eaae77c0b (diff) | |
parent | 31278ff5f77b152b5ef7a4197e15c441c72ff163 (diff) | |
download | python-heatclient-914921d26a81db02f4e92b37d5087a39f2a262bc.tar.gz |
Merge "Implement client side of event list --nested-depth"
Diffstat (limited to 'heatclient/common')
-rw-r--r-- | heatclient/common/event_utils.py | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/heatclient/common/event_utils.py b/heatclient/common/event_utils.py index 65f89c5..d490ecf 100644 --- a/heatclient/common/event_utils.py +++ b/heatclient/common/event_utils.py @@ -67,29 +67,57 @@ def get_hook_events(hc, stack_id, event_args, nested_depth=0, def get_events(hc, stack_id, event_args, nested_depth=0, marker=None, limit=None): + event_args = dict(event_args) + if marker: + event_args['marker'] = marker + if limit: + event_args['limit'] = limit + if not nested_depth: + # simple call with no nested_depth + return _get_stack_events(hc, stack_id, event_args) + + # assume an API which supports nested_depth + event_args['nested_depth'] = nested_depth events = _get_stack_events(hc, stack_id, event_args) - if nested_depth > 0: - events.extend(_get_nested_events(hc, nested_depth, - stack_id, event_args)) - # Because there have been multiple stacks events mangled into - # one list, we need to sort before passing to print_list - # Note we can't use the prettytable sortby_index here, because - # the "start" option doesn't allow post-sort slicing, which - # will be needed to make "--marker" work for nested_depth lists - events.sort(key=lambda x: x.event_time) - - # Slice the list if marker is specified - if marker: - try: - marker_index = [e.id for e in events].index(marker) - events = events[marker_index:] - except ValueError: - pass - - # Slice the list if limit is specified - if limit: - limit_index = min(int(limit), len(events)) - events = events[:limit_index] + + if not events: + return events + + first_links = getattr(events[0], 'links', []) + root_stack_link = [l for l in first_links + if l.get('rel') == 'root_stack'] + if root_stack_link: + # response has a root_stack link, indicating this is an API which + # supports nested_depth + return events + + # API doesn't support nested_depth, do client-side paging and recursive + # event fetch + marker = event_args.pop('marker', None) + limit = event_args.pop('limit', None) + event_args.pop('nested_depth', None) + events = _get_stack_events(hc, stack_id, event_args) + events.extend(_get_nested_events(hc, nested_depth, + stack_id, event_args)) + # Because there have been multiple stacks events mangled into + # one list, we need to sort before passing to print_list + # Note we can't use the prettytable sortby_index here, because + # the "start" option doesn't allow post-sort slicing, which + # will be needed to make "--marker" work for nested_depth lists + events.sort(key=lambda x: x.event_time) + + # Slice the list if marker is specified + if marker: + try: + marker_index = [e.id for e in events].index(marker) + events = events[marker_index:] + except ValueError: + pass + + # Slice the list if limit is specified + if limit: + limit_index = min(int(limit), len(events)) + events = events[:limit_index] return events |