Skip to content

Commit 2fa70a9

Browse files
committed
Set containerlab version in installation configuration
The containerlab installation script expects the CONTAINERLAB_VERSION environment variable to contain the target clab version. We had to modify the installation script each time we wanted to change the version; this commit introduces an alternative mechanism and bumps the containerlab version to 0.68.0: * The environment variables depending on system defaults are specified in the install.yml configuration file * CONTAINERLAB_VERSION environment variable depends on clab.version value (now set to 0.68.0) * The 'netlab install' command sets the environment variables specified in the install.yml configuration file before starting the scripts Collateral fix: * 'netlab install' recognized the 'dry-run' flag but did not pass it to 'external_commands' module. Fixes #2498
1 parent 53c6d32 commit 2fa70a9

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

netsim/cli/install.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..utils import log,strings,read
1616
from ..utils.files import get_moddir
17-
from . import external_commands,error_and_exit
17+
from . import external_commands,error_and_exit,set_dry_run
1818

1919
#
2020
# CLI parser for 'netlab install' command
@@ -84,6 +84,18 @@ def read_config_setup() -> Box:
8484
error_and_exit(f'Cannot read {str(os_release)}: {str(ex)}')
8585
return setup
8686

87+
"""
88+
Adjust installation configuration:
89+
90+
* Update 'env' dictionary from topology variables
91+
"""
92+
def adjust_setup(setup: Box, topology: Box, args: argparse.Namespace) -> None:
93+
for k,v in setup.env.items():
94+
if v in topology.defaults:
95+
os.environ[k] = topology.defaults[v]
96+
if args.verbose:
97+
print(f'ENV: {k}={os.environ[k]}')
98+
8799
"""
88100
check_crazy_pip3: deals with crazy pip3 that thinks installing Python packages in
89101
local directory will break its sanity
@@ -274,13 +286,17 @@ def run(cli_args: typing.List[str]) -> None:
274286
return
275287

276288
args = install_parse(cli_args,setup)
289+
topology = read.system_defaults()
290+
adjust_setup(setup,topology,args)
291+
277292
for script in args.script:
278293
if script not in setup.scripts:
279294
error_and_exit(
280295
f'Unknown installation script {script}',
281296
more_hints='Run "netlab install" to display the available installation scripts')
282297

283298
set_quiet_flags(args)
299+
set_dry_run(args)
284300
set_sudo_flag()
285301
install_path = f'{get_moddir()}/install'
286302
os.environ['PATH'] = install_path + ":" + os.environ['PATH']

netsim/install/containerlab.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
3-
# Install a specific version of Containerlab
4-
CONTAINERLAB_VERSION="0.62.2"
3+
# Install a specific version of Containerlab -- it's now set in 'netlab install' before calling this script
4+
# CONTAINERLAB_VERSION="0.62.2"
55
#
66
set -e
77
REPLACE="--upgrade"

netsim/install/install.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
env:
2+
CONTAINERLAB_VERSION: providers.clab.version
3+
14
scripts:
25
ubuntu:
36
description: Mandatory and nice-to have Debian/Ubuntu packages

netsim/providers/clab.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config: clab.yml
66
lab_prefix: "clab" # Containerlab default, set to "" to remove prefix
77
node_config_attributes: [ type, cmd, dns, env, license, ports, startup-delay, restart-policy ]
88
template: clab.j2
9+
version: 0.68.0
910
# Preserve env to allow user to configure PATH
1011
start: sudo -E containerlab deploy --reconfigure -t clab.yml
1112
stop: sudo -E containerlab destroy --cleanup -t clab.yml

0 commit comments

Comments
 (0)