aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/NodePath.py14
-rw-r--r--resources/libraries/python/topology.py40
2 files changed, 46 insertions, 8 deletions
diff --git a/resources/libraries/python/NodePath.py b/resources/libraries/python/NodePath.py
index bbc6d31811..dfcee4d720 100644
--- a/resources/libraries/python/NodePath.py
+++ b/resources/libraries/python/NodePath.py
@@ -55,16 +55,20 @@ class NodePath(object):
def __init__(self):
self._nodes = []
+ self._nodes_filter = []
self._links = []
self._path = []
self._path_iter = []
- def append_node(self, node):
+ def append_node(self, node, filter_list=None):
"""Append node to the path.
:param node: Node to append to the path.
+ :param filter_list: Filter criteria list.
:type node: dict
+ :type filter_list: list of strings
"""
+ self._nodes_filter.append(filter_list)
self._nodes.append(node)
def append_nodes(self, *nodes):
@@ -81,6 +85,7 @@ class NodePath(object):
def clear_path(self):
"""Clear path."""
self._nodes = []
+ self._nodes_filter = []
self._links = []
self._path = []
self._path_iter = []
@@ -96,6 +101,7 @@ class NodePath(object):
.. note:: First add at least two nodes to the topology.
"""
nodes = self._nodes
+ nodes_filer = self._nodes_filter
if len(nodes) < 2:
raise RuntimeError('Not enough nodes to compute path')
@@ -103,7 +109,11 @@ class NodePath(object):
topo = Topology()
node1 = nodes[idx]
node2 = nodes[idx + 1]
- links = topo.get_active_connecting_links(node1, node2)
+ n1_list = self._nodes_filter[idx]
+ n2_list = self._nodes_filter[idx + 1]
+ links = topo.get_active_connecting_links(node1, node2,
+ filter_list_node1=n1_list,
+ filter_list_node2=n2_list)
if not links:
raise RuntimeError('No link between {0} and {1}'.format(
node1['host'], node2['host']))
diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py
index 20745eb0a2..7e9400757e 100644
--- a/resources/libraries/python/topology.py
+++ b/resources/libraries/python/topology.py
@@ -359,10 +359,13 @@ class Topology(object):
return None
@staticmethod
- def _get_node_active_link_names(node):
+ def _get_node_active_link_names(node, filter_list=None):
"""Return list of link names that are other than mgmt links.
:param node: Node topology dictionary.
+ :param filter_list: Link filter criteria.
+ :type node: dict
+ :type filter_list: list of strings
:return: List of strings that represent link names occupied by the node.
:rtype: list
"""
@@ -370,28 +373,53 @@ class Topology(object):
link_names = []
for interface in interfaces.values():
if 'link' in interface:
- link_names.append(interface['link'])
+ if (filter_list is not None) and ('model' in interface):
+ for filt in filter_list:
+ if filt == interface['model']:
+ link_names.append(interface['link'])
+ elif (filter_list is not None) and ('model' not in interface):
+ logger.trace("Cannot apply filter on interface: {}" \
+ .format(str(interface)))
+ else:
+ link_names.append(interface['link'])
if len(link_names) == 0:
link_names = None
return link_names
@keyword('Get active links connecting "${node1}" and "${node2}"')
- def get_active_connecting_links(self, node1, node2):
+ def get_active_connecting_links(self, node1, node2,
+ filter_list_node1=None,
+ filter_list_node2=None):
"""Return list of link names that connect together node1 and node2.
:param node1: Node topology dictionary.
:param node2: Node topology dictionary.
+ :param filter_list_node1: Link filter criteria for node1.
+ :param filter_list_node2: Link filter criteria for node2.
:type node1: dict
:type node2: dict
+ :type filter_list1: list of strings
+ :type filter_list2: list of strings
:return: List of strings that represent connecting link names.
:rtype: list
"""
logger.trace("node1: {}".format(str(node1)))
logger.trace("node2: {}".format(str(node2)))
- node1_links = self._get_node_active_link_names(node1)
- node2_links = self._get_node_active_link_names(node2)
- connecting_links = list(set(node1_links).intersection(node2_links))
+ node1_links = self._get_node_active_link_names(
+ node1,
+ filter_list=filter_list_node1)
+ node2_links = self._get_node_active_link_names(
+ node2,
+ filter_list=filter_list_node2)
+
+ connecting_links = None
+ if node1_links is None:
+ logger.error("Unable to find active links for node1")
+ elif node2_links is None:
+ logger.error("Unable to find active links for node2")
+ else:
+ connecting_links = list(set(node1_links).intersection(node2_links))
return connecting_links