Skip to content

Commit af60c0b

Browse files
Add support for a starting index when connecting nodes. (#126)
* Add support for a starting index when connecting nodes. By default, the `lab.connect_two_nodes()` connects the next two available indexes. Extend this to allow an index where you can start at, for example, 1. This could allow to skip mgmt interfaces. * Consume the position element. Spotted by: Patrick Mosko --------- Co-authored-by: Joe Clarke <[email protected]>
1 parent 22693cd commit af60c0b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

virl2_client/models/lab.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -955,16 +955,17 @@ def _create_link_local(
955955

956956
@check_stale
957957
@locked
958-
def connect_two_nodes(self, node1: Node, node2: Node) -> Link:
958+
def connect_two_nodes(self, node1: Node, node2: Node, index: int = 0) -> Link:
959959
"""
960960
Connect two nodes within a lab.
961961
962962
:param node1: The first node object.
963963
:param node2: The second node object.
964+
:param index: An optional starting interface index (default: 0).
964965
:returns: The created link.
965966
"""
966-
iface1 = node1.next_available_interface() or node1.create_interface()
967-
iface2 = node2.next_available_interface() or node2.create_interface()
967+
iface1 = node1.next_available_interface(index) or node1.create_interface()
968+
iface2 = node2.next_available_interface(index) or node2.create_interface()
968969
return self.create_link(iface1, iface2)
969970

970971
@check_stale

virl2_client/models/node.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,19 @@ def create_interface(
253253
return self._lab.create_interface(self, slot, wait=wait)
254254

255255
@locked
256-
def next_available_interface(self) -> Interface | None:
256+
def next_available_interface(self, index: int = 0) -> Interface | None:
257257
"""
258258
Return the next available physical interface on this node.
259259
260260
Note: On XR 9000v, the first two physical interfaces are marked
261261
as "do not use"... Only the third physical interface can be used
262262
to connect to other nodes!
263263
264+
:param index: An optional starting interface index (default: 0).
264265
:returns: An available physical interface or None if all existing
265266
ones are connected.
266267
"""
267-
for iface in self.interfaces():
268+
for _, iface in enumerate(self.interfaces(), index):
268269
if not iface.connected and iface.physical:
269270
return iface
270271
return None

0 commit comments

Comments
 (0)