Skip to content
Draft
Show file tree
Hide file tree
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
35 changes: 21 additions & 14 deletions images/sonic/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, name: str, smp: str, memory: str):
self._smp = smp
self._memory = memory
self._p = None
self._disk = '/overlay.img'
self._disk = '/persistent/overlay.img'

def prepare_overlay(self, base: str) -> None:
cmd = [
Expand Down Expand Up @@ -130,13 +130,7 @@ def initial_configuration(g: GuestFS, hwsku: str) -> None:
g.ln_s(linkname=sonic_share + 'platform', target=VS_DEVICES_PATH)

ifaces = get_ethernet_interfaces()
# The port_config.ini file contains the assignment of front panels to lanes.
port_config = parse_port_config()
# The lanemap.ini file is used by the virtual switch image to assign front panels to the Linux interfaces ethX.
# This assignment will later also be used by the script mirror_tap_to_front_panel.sh.
lanemap = create_lanemap(port_config, ifaces)
with open('/lanemap.ini', 'w') as f:
f.write('\n'.join(lanemap))

g.copy_in(localpath='/lanemap.ini', remotedir=hwsku_dir)
g.copy_in(localpath='/port_config.ini', remotedir=hwsku_dir)
Expand Down Expand Up @@ -188,17 +182,30 @@ def main():

vm = Qemu(name, smp, memory)

logger.info('Prepare disk')
vm.prepare_overlay(BASE_IMG)
overlay_exists = os.path.exists(vm._disk)

if not overlay_exists:
logger.info('Prepare disk')
vm.prepare_overlay(BASE_IMG)

logger.info(f'Waiting for {interfaces} interfaces to be connected')
wait_until_all_interfaces_are_connected(interfaces)

logger.info('Deploy initial config')
g = vm.guestfs()
initial_configuration(g, hwsku)
g.shutdown()
g.close()
# mirror_tap_to_front_panel.sh reads /lanemap.ini from the container filesystem
# at TAP interface setup time, so it must be written on every container startup.
ifaces = get_ethernet_interfaces()
lanemap = create_lanemap(parse_port_config(), ifaces)
with open('/lanemap.ini', 'w') as f:
f.write('\n'.join(lanemap))

if not overlay_exists:
logger.info('Deploy initial config')
g = vm.guestfs()
initial_configuration(g, hwsku)
g.shutdown()
g.close()
else:
logger.info('Reusing existing overlay')

logger.info('Start QEMU')
vm.start()
Expand Down
2 changes: 2 additions & 0 deletions mini-lab.sonic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ topology:
image: ${MINI_LAB_SONIC_IMAGE}
binds:
- files/ssh/id_ed25519.pub:/authorized_keys
- /persistent # using an anonymous volume because containerlab expects host bind directories to already exist
env:
QEMU_MEMORY: 4096
leaf02:
group: leaves
image: ${MINI_LAB_SONIC_IMAGE}
binds:
- files/ssh/id_ed25519.pub:/authorized_keys
- /persistent # using an anonymous volume because containerlab expects host bind directories to already exist
env:
QEMU_MEMORY: 4096
machine01:
Expand Down
Loading