Skip to content

Implement generic device hooks - #4021

Merged
ipspace merged 1 commit into
devfrom
device-hook
Nov 2, 2026
Merged

ipspace merged 1 commit into
devfrom
device-hook

Conversation

@ipspace

@ipspace ipspace commented Nov 2, 2026

Copy link
Copy Markdown
Owner

The 'device quirks' system is expanded into generic 'device hooks' -- methods in the device '_Quirks' object that can do whatever we need them to do. The infrastructure changes in this commit:

  • Add 'exec_device_hook' method that calls any device object method with node, topology, and any extra parameters supplied by the caller. The parameters cannot be checked in advance :(. The function returns the method results or None to allow the caller to check whether the hook was executed.
  • Use 'exec_device_hook' to implement 'exec_device_quirk'
  • Add 'hooks' debugging parameter

The 'device quirks' system is expanded into generic 'device hooks' --
methods in the device '_Quirks' object that can do whatever we need
them to do. The infrastructure changes in this commit:

* Add 'exec_device_hook' method that calls any device object method
  with node, topology, and any extra parameters supplied by the caller.
  The parameters cannot be checked in advance :(. The function returns
  the method results or None to allow the caller to check whether the
  hook was executed.
* Use 'exec_device_hook' to implement 'exec_device_quirk'
* Add 'hooks' debugging parameter

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active documentation issue remains because the new hooks debug flag is not listed in the relevant debug-flag documentation.

1 open issue
What changed in this PR

This pull request expands device quirks into generic device hooks while preserving the existing quirk API.

Changes:

  • Added exec_device_hook for invoking device methods with extra parameters and returning results.
  • Refactored exec_device_quirk to use the generic hook executor.
  • Added the hooks CLI debugging flag.

This pull request is ready to be approved.

File Description
netsim/​devices/​__init__.py Implements generic device-hook dispatch and retains quirk compatibility.
netsim/​cli/​__init__.py Registers the new hooks debugging option. Documentation for the flag should be added alongside the existing quirks documentation.

Review effort: Lite

Comment thread netsim/cli/__init__.py Resolved
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying netlab with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5f98f48
Status: ✅  Deploy successful!
Preview URL: https://df103006.netlab.pages.dev
Branch Preview URL: https://device-hook.netlab.pages.dev

View logs

@ipspace
ipspace merged commit 7a96d5b into dev Nov 2, 2026
10 checks passed
@ipspace
ipspace deleted the device-hook branch November 2, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants