Code Review
/
csit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Use interface key instead of interface name.
[csit.git]
/
resources
/
libraries
/
python
/
NodePath.py
diff --git
a/resources/libraries/python/NodePath.py
b/resources/libraries/python/NodePath.py
index
d1aa1f7
..
dfcee4d
100644
(file)
--- a/
resources/libraries/python/NodePath.py
+++ b/
resources/libraries/python/NodePath.py
@@
-13,7
+13,7
@@
"""Path utilities library for nodes in the topology."""
"""Path utilities library for nodes in the topology."""
-from topology import Topology
+from
resources.libraries.python.
topology import Topology
class NodePath(object):
class NodePath(object):
@@
-55,16
+55,20
@@
class NodePath(object):
def __init__(self):
self._nodes = []
def __init__(self):
self._nodes = []
+ self._nodes_filter = []
self._links = []
self._path = []
self._path_iter = []
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.
"""Append node to the path.
:param node: Node to append to the path.
+ :param filter_list: Filter criteria list.
:type node: dict
:type node: dict
+ :type filter_list: list of strings
"""
"""
+ self._nodes_filter.append(filter_list)
self._nodes.append(node)
def append_nodes(self, *nodes):
self._nodes.append(node)
def append_nodes(self, *nodes):
@@
-81,6
+85,7
@@
class NodePath(object):
def clear_path(self):
"""Clear path."""
self._nodes = []
def clear_path(self):
"""Clear path."""
self._nodes = []
+ self._nodes_filter = []
self._links = []
self._path = []
self._path_iter = []
self._links = []
self._path = []
self._path_iter = []
@@
-89,13
+94,14
@@
class NodePath(object):
"""Compute path for added nodes.
:param always_same_link: If True use always same link between two nodes
"""Compute path for added nodes.
:param always_same_link: If True use always same link between two nodes
-
in path. If False use different link (if available) between two
-
nodes if one link was used before.
+ in path. If False use different link (if available) between two
+ nodes if one link was used before.
:type always_same_link: bool
.. note:: First add at least two nodes to the topology.
"""
nodes = self._nodes
:type always_same_link: bool
.. 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')
if len(nodes) < 2:
raise RuntimeError('Not enough nodes to compute path')
@@
-103,18
+109,23
@@
class NodePath(object):
topo = Topology()
node1 = nodes[idx]
node2 = nodes[idx + 1]
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']))
if not links:
raise RuntimeError('No link between {0} and {1}'.format(
node1['host'], node2['host']))
- link = None
- l_set = set()
-
if always_same_link:
l_set = set(links).intersection(self._links)
else:
l_set = set(links).difference(self._links)
if always_same_link:
l_set = set(links).intersection(self._links)
else:
l_set = set(links).difference(self._links)
+ if not l_set:
+ raise RuntimeError(
+ 'No free link between {0} and {1}, all links already '
+ 'used'.format(node1['host'], node2['host']))
if not l_set:
link = links.pop()
if not l_set:
link = links.pop()
@@
-139,7
+150,7
@@
class NodePath(object):
.. note:: Call compute_path before.
"""
if not self._path_iter:
.. note:: Call compute_path before.
"""
if not self._path_iter:
- return
(None, None)
+ return
None, None
else:
return self._path_iter.pop()
else:
return self._path_iter.pop()