diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-02-09 10:45:14 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-02-09 10:45:14 +0000 |
commit | c9f96d6d79c2b20a5c39ab98f4084cfd2d842e07 (patch) | |
tree | 2b61209cb5fedf2bf5e69807c4bf1236c9d2609c /tools | |
parent | 19bf5a8b62a06840fc831cc4d807c1ab4f8f6068 (diff) | |
parent | 4f8b97dff68dcdea02f769de8d0721e8e98fa029 (diff) | |
download | ironic-c9f96d6d79c2b20a5c39ab98f4084cfd2d842e07.tar.gz |
Merge "Show transitions initiated by API requests"
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/states_to_dot.py | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/tools/states_to_dot.py b/tools/states_to_dot.py index 0a03c2c0e..10c10972b 100755 --- a/tools/states_to_dot.py +++ b/tools/states_to_dot.py @@ -67,18 +67,62 @@ def main(): if options.filename is None: options.filename = 'states.%s' % options.format + def node_attrs(state): + """Attributes used for drawing the nodes (states). + + The user can perform actions on stable states (and in a few other + cases), so we distinguish the stable states from the other states by + highlighting the node. Non-stable states are labelled with gray. + + This is a callback method used by pydot.convert(). + + :param state: name of state + :returns: A dictionary with graphic attributes used for displaying + the state. + """ + attrs = map_color(state) + if source.is_stable(state): + attrs['penwidth'] = 1.7 + else: + if 'fontcolor' not in attrs: + attrs['fontcolor'] = 'gray' + return attrs + def edge_attrs(start_state, event, end_state): + """Attributes used for drawing the edges (transitions). + + There are two types of transitions; the ones that the user can + initiate and the ones that are done internally by the conductor. + The user-initiated ones are shown with '(via API'); the others are + in gray. + + This is a callback method used by pydot.convert(). + + :param start_state: name of the start state + :param event: the event, a string + :param end_state: name of the end state (unused) + :returns: A dictionary with graphic attributes used for displaying + the transition. + """ + if not options.labels: + return {} + + translations = {'delete': 'deleted', 'deploy': 'active'} attrs = {} - if options.labels: - attrs['label'] = "on_%s" % event - attrs.update(map_color(event)) + attrs['fontsize'] = 12 + attrs['label'] = translations.get(event, event) + if (source.is_stable(start_state) or 'fail' in start_state + or event in ('abort', 'delete')): + attrs['label'] += " (via API)" + else: + attrs['fontcolor'] = 'gray' return attrs source = states.machine graph_name = '"Ironic states"' graph_attrs = {'size': 0} g = pydot.convert(source, graph_name, graph_attrs=graph_attrs, - node_attrs_cb=map_color, edge_attrs_cb=edge_attrs) + node_attrs_cb=node_attrs, edge_attrs_cb=edge_attrs) print_header(graph_name) print(g.to_string().strip()) |