fix: Add label prefix to TaskNode and RoleNode

This commit is contained in:
Mohamed El Mouctar HAIDARA 2021-09-22 19:31:54 +02:00
parent 2b875739e4
commit 565f5e8f8d
2 changed files with 20 additions and 7 deletions

View file

@ -185,8 +185,14 @@ class TaskNode(Node):
A task node. Can be pre_task, task or post_task
"""
def __init__(self, node_label: str, node_id: str = None):
super().__init__(node_label, node_id or generate_id("task_"))
def __init__(self, node_label: str, node_id: str = None, label_prefix: str = "[task] "):
"""
:param node_label:
:param node_id:
:param label_prefix: Prefix for the label
"""
super().__init__(label_prefix + node_label, node_id or generate_id("task_"))
class RoleNode(CompositeNode):
@ -194,8 +200,14 @@ class RoleNode(CompositeNode):
A role node. A role is a composition of tasks
"""
def __init__(self, node_label: str, node_id: str = None):
super().__init__(node_label, node_id or generate_id("role_"))
def __init__(self, node_label: str, node_id: str = None, label_prefix: str = "[role] "):
"""
:param node_label:
:param node_id:
:param label_prefix: Prefix for the label
"""
super().__init__(label_prefix + node_label, node_id or generate_id("role_"))
@property
def tasks(self):

View file

@ -79,9 +79,10 @@ class BaseParser(ABC):
when = "".join(map(str, task.when))
task_edge_name += " [when: " + when + "]"
task_name = clean_name(f"[{node_type}] " + self.template(task.get_name(), task_vars))
task_name = clean_name(self.template(task.get_name(), task_vars))
edge_node = EdgeNode(task_edge_name, parent_node, TaskNode(task_name, generate_id(f"{node_type}_")))
edge_node = EdgeNode(task_edge_name, parent_node,
TaskNode(task_name, generate_id(f"{node_type}_"), label_prefix=f"[{node_type}] "))
parent_node.add_node(target_composition=f"{node_type}s", node=edge_node)
return True
@ -167,7 +168,7 @@ class PlaybookParser(BaseParser):
# Go to the next role
continue
role_node = RoleNode("[role] " + clean_name(role.get_name()))
role_node = RoleNode(clean_name(role.get_name()))
# edge from play to role
play_node.add_node("roles",
EdgeNode(str(role_counter + len(play_node.pre_tasks)), play_node, role_node))