Skip to content

FakeNOS Service Restart Task¤

task api name: restart

The FakeNOS service restart task stops a running virtual network and immediately starts it again using the same inventory. This allows you to refresh a network's simulated devices without having to re-supply the inventory configuration.

FakeNOS Restart Task Overview¤

The restart task provides the following features:

  • Inventory Preservation: Reuses the inventory that was provided when the network was originally started — no need to re-fetch or re-specify it.
  • Seamless Re-initialisation: Stops the existing child process cleanly, then spawns a new one with the same configuration.
  • Immediate Feedback: Returns the same detailed host and process information as the start task.

Inputs¤

Argument Type Default Description
network str required Name of the FakeNOS network to restart. The network must already be running.

Output¤

Returns the same detailed host and process information as the start task for the restarted network.

Examples¤

Restart a running network:

nf#fakenos restart network lab1

Context manager:

from norfab.core.nfapi import NorFab

with NorFab(inventory="./inventory.yaml") as nf:
    client = nf.make_client()

    result = client.run_job(
        service="fakenos",
        task="restart",
        workers="any",
        kwargs={"network": "lab1"},
    )
    print(result)

Direct lifecycle:

from norfab.core.nfapi import NorFab

nf = NorFab(inventory="./inventory.yaml")
try:
    nf.start()
    client = nf.make_client()

    result = client.run_job(
        service="fakenos",
        task="restart",
        workers="any",
        kwargs={"network": "lab1"},
    )
    print(result)
finally:
    nf.destroy()

FakeNOS Restart Command Shell Reference¤

NorFab shell supports these command options for FakeNOS restart task:

nf# man tree fakenos.restart

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

root
└── fakenos:    FakeNOS service
    └── restart:    FakeNOS restart command
        ├── network (R):    FakeNOS network name to restart
        ├── 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 and restart an existing FakeNOS network.

Retrieves the previously resolved inventory from self.networks, stops the running process, then starts a fresh child process using the same inventory. Progress events are forwarded to the caller via job.

Parameters:

Name Type Description Default
job Job

NorFab job context injected by the @Task decorator.

required
network str

Name of the FakeNOS network to restart. Must already exist in self.networks.

required
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
@Task(
    input=FakeNOSRestartInput,
    output=FakeNOSNetworkActionResult,
    fastapi={"methods": ["POST"]},
    mcp={
        "annotations": {
            "title": "Restart FakeNOS Network",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": False,
            "openWorldHint": False,
        }
    },
)
def restart(self, job: Job, network: str) -> Result:
    """
    Stop and restart an existing FakeNOS network.

    Retrieves the previously resolved inventory from ``self.networks``,
    stops the running process, then starts a fresh child process using the
    same inventory.  Progress events are forwarded to the caller via *job*.

    Args:
        job: NorFab job context injected by the ``@Task`` decorator.
        network: Name of the FakeNOS network to restart.  Must already
            exist in ``self.networks``.
    """
    ret = Result()
    log.info(f"{self.name} - Restart: Restarting '{network}' FakeNOS network")
    inventory = self.networks[network]["inventory"]
    self.stop(job, network)
    self.start(job, network, inventory)
    ret.result = self.inspect_networks(
        job=job, network=network, details=True
    ).result
    return ret