Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect eth0 interface to be set as num_provisioned_nics #166

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions common/vrnetlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def __init__(
self.nic_type = "e1000"
self.num_nics = 0
# number of nics that are actually *provisioned* (as in nics that will be added to container)
self.num_provisioned_nics = int(os.environ.get("CLAB_INTFS", 0))
# since hellt/vrnetlab 0.15.0 the CLAB_INTFS_WITH_MGMT env var is used (instead of CLAB_INTFS)
# that counts management interface as well as data plane interfaces defined in the topology
self.num_provisioned_nics = int(os.environ.get("CLAB_INTFS_WITH_MGMT", 0))
# "highest" provisioned nic num -- used for making sure we can allocate nics without needing
# to have them allocated sequential from eth1
self.highest_provisioned_nic_num = 0
Expand Down Expand Up @@ -425,7 +427,7 @@ def gen_mgmt(self):

def nic_provision_delay(self) -> None:
self.logger.debug(
f"number of provisioned data plane interfaces is {self.num_provisioned_nics}"
f"number of provisioned data and control plane interfaces is {self.num_provisioned_nics}"
)

if self.num_provisioned_nics == 0:
Expand All @@ -442,8 +444,10 @@ def nic_provision_delay(self) -> None:
inf_path = Path("/sys/class/net/")
while True:
provisioned_nics = list(inf_path.glob("eth*"))
# if we see num provisioned +1 (for mgmt) we have all nics ready to roll!
if len(provisioned_nics) >= self.num_provisioned_nics + 1:
# if we see num provisioned interfaces we have all nics ready to roll!
# the management interface is counted as well and is included in CLAB_INTFS env var
# since containerlab v0.51.0
if len(provisioned_nics) >= self.num_provisioned_nics:
nics = [
int(re.search(pattern=r"\d+", string=nic.name).group())
for nic in provisioned_nics
Expand All @@ -456,9 +460,11 @@ def nic_provision_delay(self) -> None:
self.highest_provisioned_nic_num = max(nics)

self.logger.debug(
f"highest allocated interface id determined to be: {self.highest_provisioned_nic_num}..."
f"highest allocated interface id determined to be: {self.highest_provisioned_nic_num}"
)
self.logger.debug(
"control and datap plane interfaces detected, continuing..."
)
self.logger.debug("interfaces provisioned, continuing...")
return
time.sleep(5)

Expand Down