diff --git a/virl2_client/models/lab.py b/virl2_client/models/lab.py index 8b9e91e..7cb5bf4 100644 --- a/virl2_client/models/lab.py +++ b/virl2_client/models/lab.py @@ -955,16 +955,17 @@ def _create_link_local( @check_stale @locked - def connect_two_nodes(self, node1: Node, node2: Node) -> Link: + def connect_two_nodes(self, node1: Node, node2: Node, index: int = 0) -> Link: """ Connect two nodes within a lab. :param node1: The first node object. :param node2: The second node object. + :param index: An optional starting interface index (default: 0). :returns: The created link. """ - iface1 = node1.next_available_interface() or node1.create_interface() - iface2 = node2.next_available_interface() or node2.create_interface() + iface1 = node1.next_available_interface(index) or node1.create_interface() + iface2 = node2.next_available_interface(index) or node2.create_interface() return self.create_link(iface1, iface2) @check_stale diff --git a/virl2_client/models/node.py b/virl2_client/models/node.py index ca5042e..b312675 100644 --- a/virl2_client/models/node.py +++ b/virl2_client/models/node.py @@ -253,7 +253,7 @@ def create_interface( return self._lab.create_interface(self, slot, wait=wait) @locked - def next_available_interface(self) -> Interface | None: + def next_available_interface(self, index: int = 0) -> Interface | None: """ Return the next available physical interface on this node. @@ -261,10 +261,11 @@ def next_available_interface(self) -> Interface | None: as "do not use"... Only the third physical interface can be used to connect to other nodes! + :param index: An optional starting interface index (default: 0). :returns: An available physical interface or None if all existing ones are connected. """ - for iface in self.interfaces(): + for _, iface in enumerate(self.interfaces(), index): if not iface.connected and iface.physical: return iface return None