How extensions work
Extensions are loaded and executed as long-lived child processes bygenieacs-cwmp. The parent process communicates with each child over IPC:
- Processes are lazily spawned — a child process is started the first time a given extension file is called, then reused for subsequent calls.
- Every call is assigned a unique request ID. When the child responds, the ID is used to route the result back to the correct waiting caller.
- Extension results are cached per session revision. Because the sandbox may re-run a script from the beginning, a cached result is returned on replay rather than making a duplicate call.
- If a child process disconnects or produces an error, it is killed and removed from the process table. A new process is spawned on the next call.
Configuration
| Environment variable | Default | Description |
|---|---|---|
GENIEACS_EXT_DIR | <installation dir>/config/ext | Directory where extension files are located. |
GENIEACS_EXT_TIMEOUT | 3000 | Maximum milliseconds to wait for a response. |
/opt/genieacs/ext/.
Writing an extension
An extension is a plain Node.js CommonJS module. Export one function for each operation you want to expose. Each exported function receives two arguments: an array of arguments forwarded from theext() call, and a Node.js-style callback (err, result).
The example below fetches the current position of the International Space Station from a public REST API and returns the latitude and longitude as an array:
ext-sample.js
config/ext/ext-sample.js (or whatever name you choose — the filename is the first argument to ext()).
The
args parameter received by each function is an array containing all
extra arguments passed after the function name in the ext() call. In the
example above, args is unused because the API takes no input.Calling an extension from a provision
Use the built-inext() function inside any provision or virtual parameter script:
| Argument | Description |
|---|---|
file | Extension filename without the .js extension. |
function | Name of the exported function to call. |
...args | Additional arguments forwarded to the function as the args array. |
Using extensions in auth expressions
TheEXT() function is also available inside cwmp.auth configuration expressions, allowing you to call extensions during device authentication. For example, to look up a device password by serial number: