Conversation
The CLI hooks allow the lab topology to define extra commands that are executed at various points of the 'netlab up' or 'netlab down' processing. The platform integration test has an example of the netlab up hooks. Implements #3338
There was a problem hiding this comment.
Pull request overview
This PR adds support for user-defined CLI hooks that can run extra commands at specific lifecycle points during netlab up and netlab down, configured via defaults.netlab.<command>.<hook> in the topology/defaults. It addresses the workflow requested in #3338 (running an external licensing/apply step as part of up).
Changes:
- Added
run_cli_hooks()helper to execute configured hook commands and abort on failure. - Wired hook execution into multiple stages of
netlab up(probes, lab start, initial config, tool start) andnetlab down(lab stop, cleanup). - Added a platform integration test topology demonstrating
netlab uphooks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
netsim/cli/external_commands.py |
Introduces run_cli_hooks() for running hook commands from defaults. |
netsim/cli/up.py |
Executes configured up hooks at key phases (pre-probe/start/config/tools and post-start/config/tools). |
netsim/cli/down.py |
Executes configured down hooks around lab stop and cleanup. |
tests/platform-integration/hooks/01-up-hooks.yml |
Adds an integration example/test validating pre/post start hooks create artifacts. |
| def run_cli_hooks(settings: Box, cli_command: str, hook: str) -> None: | ||
| cmd = settings.get(f'netlab.{cli_command}.{hook}',None) | ||
| if not cmd: | ||
| return | ||
| if log.VERBOSE: | ||
| log.info(f'Running {hook} CLI hook',module=cli_command,more_data=[cmd]) | ||
| if not run_command(cmd): | ||
| log.fatal(f'CLI hook {hook} returned an error, aborting...',cli_command) | ||
|
|
There was a problem hiding this comment.
@a-v-popov -- What do you think? I'm OK with having str/list option, or saying "it's a single command, use the files plugin to create a bash script if needed".
In any case, the final value passed to run_command has to be a str/list to allow passing "weird" arguments (for example, embedded spaces) into run_command.
|
@a-v-popov -- This should give you the hooks needed to run the Fortinet licensing script. If you need more hooks, just let me know. I'll add documentation once you're OK with the concept. |
The CLI hooks allow the lab topology to define extra commands that are executed at various points of the 'netlab up' or 'netlab down' processing. The platform integration test has an example of the netlab up hooks.
Implements #3338