Skip to content

FakeNOS Service Stop Task¤

task api name: stop

The FakeNOS service stop task gracefully terminates one or all running FakeNOS virtual networks. The task signals each target child process to exit, waits up to one second for a clean shutdown, and forcibly kills any process that does not stop in time.

FakeNOS Stop Task Overview¤

The stop task provides the following features:

  • Selective Stop: Stop a single network by name or all networks at once by omitting the network argument.
  • Graceful Shutdown: Sends a stop signal to the child process and waits up to one second before forcibly killing it.
  • Automatic Cleanup: Removes stopped networks from the worker's internal tracking dictionary.

FakeNOS Stop Task Arguments¤

Argument Type Default Description
network str or None None Name of the network to stop. If None, all currently running networks are stopped.

FakeNOS Stop Command Shell Reference¤

NorFab shell supports these command options for Netbox create_prefix task:

nf#man tree fakenos.stop

R - required field, M - supports multiline input, D - dynamic key

root
└── fakenos:    FakeNOS service
    └── stop:    FakeNOS stop command
        ├── network:    FakeNOS network name to stop; stops all networks if omitted
        ├── timeout:    Job timeout
        ├── workers:    Filter workers to target, default 'all'
        ├── verbose-result:    Control output details, default 'False'
        ├── progress:    Display progress events, default 'True'
        └── nowait:    Do not wait for job to complete, default 'False'
nf#

Python API Reference¤

Stop one or all running FakeNOS networks.

Signals the target child process(es) to exit via their stop event, waits up to one second for a clean shutdown, and kills any process that does not exit in time.

Parameters:

Name Type Description Default
job Job

NorFab job context injected by the @Task decorator.

required
network Union[str, None]

Name of the network to stop. If None (default), all currently running networks are stopped.

None
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
@Task(input=FakeNOSStopInput, fastapi={"methods": ["POST"]})
def stop(self, job: Job, network: Union[str, None] = None) -> Result:
    """
    Stop one or all running FakeNOS networks.

    Signals the target child process(es) to exit via their stop event,
    waits up to one second for a clean shutdown, and kills any process
    that does not exit in time.

    Args:
        job: NorFab job context injected by the ``@Task`` decorator.
        network: Name of the network to stop.  If ``None`` (default),
            all currently running networks are stopped.
    """
    ret = Result(result={})
    names = [network] if network else list(self.networks)

    for name in names:
        log.info(f"Stopping '{name}' FakeNOS network")
        entry = self.networks.get(name)
        if entry:
            entry["stop_event"].set()
            entry["process"].join(timeout=1)
            if entry["process"].is_alive():
                log.warning(f"{name} Did not stop in 1 second - killing process")
                entry["process"].kill()
                entry["process"].join()
            self.networks.pop(name, None)
            ret.result[name] = "stopped"
            log.info(f"Stopped '{name}' FakeNOS network")

    return ret