summaryrefslogtreecommitdiff
path: root/heatclient/common
diff options
context:
space:
mode:
authorSteve Baker <sbaker@redhat.com>2016-06-09 08:47:17 +1200
committerSteve Baker <sbaker@redhat.com>2016-06-10 14:30:20 +1200
commit31278ff5f77b152b5ef7a4197e15c441c72ff163 (patch)
tree9c86383ba63b2b9c137179530db975ea50a2024b /heatclient/common
parenta654226dd1da9f623b6c58f29ab8e6cf2aaf6968 (diff)
downloadpython-heatclient-31278ff5f77b152b5ef7a4197e15c441c72ff163.tar.gz
Implement client side of event list --nested-depth
This change does the following: - cleans up the usage of get_events so that marker and limit are only specified in their dedicated arguments, not also in event_args (also, specifying only in event_args still works) - first attempts server-side nested_depth support - falls back to the old recursive approach if the response data lacks a link with the ref root_stack Since there is a fallback for old heat APIs, the client change can land before or after the heat change I27e1ffb770e00a7f929c081b2a505e2007f5d584 Change-Id: I43d12ec61ec359222184f07c170de3c97481f1ba Closes-Bug: #1588561
Diffstat (limited to 'heatclient/common')
-rw-r--r--heatclient/common/event_utils.py72
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