FakeNOS Worker
FakeNOSStartInput
¤
Bases: BaseModel
Input model for the FakeNOSWorker.start task.
FakeNOSStopInput
¤
Bases: BaseModel
Input model for the FakeNOSWorker.stop task.
FakeNOSRestartInput
¤
Bases: BaseModel
Input model for the FakeNOSWorker.restart task.
FakeNOSListNetworksInput
¤
Bases: BaseModel
Input model for the FakeNOSWorker.inspect_networks task.
FakeNOSWorker(inventory: Any, broker: str, worker_name: str, exit_event: Any = None, init_done_event: Any = None, log_level: str = 'WARNING', log_queue: object = None)
¤
Bases: NFPWorker, FakeNOSNornirInventoryTasks
NorFab worker that manages one or more FakeNOS virtual networks.
Each FakeNOS network runs in its own child process so that slow or blocking SSH sessions do not affect the main worker event loop. The worker exposes task methods for starting, stopping, restarting, and inspecting networks, as well as helpers for querying version and inventory information.
Initialise the FakeNOS worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inventory
|
Any
|
NorFab inventory object or dictionary used to configure the worker. |
required |
broker
|
str
|
ZeroMQ address of the NorFab broker. |
required |
worker_name
|
str
|
Unique name identifying this worker instance. |
required |
exit_event
|
Any
|
Optional :class: |
None
|
init_done_event
|
Any
|
Event set when initialisation is complete, signalling the parent that the worker is ready. |
None
|
log_level
|
str
|
Logging level string (e.g. |
'WARNING'
|
log_queue
|
object
|
Optional queue used for multi-process log forwarding. |
None
|
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
worker_exit() -> None
¤
Gracefully stop all running FakeNOS networks on worker shutdown.
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
190 191 192 193 194 195 | |
call_network(network: str, method: str, *args: Any, timeout: float = 10, **kwargs: Any) -> Any
¤
Send a method call to a running FakeNOS process and return the result.
Places a (method, args, kwargs) request on the network's command
queue and blocks until the child process posts a response on the
result queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
str
|
Name of the target FakeNOS network. |
required |
method
|
str
|
Name of the method to invoke inside the child process. |
required |
*args
|
Any
|
Positional arguments forwarded to the method. |
()
|
timeout
|
float
|
Maximum time in seconds to wait for a response. |
10
|
**kwargs
|
Any
|
Keyword arguments forwarded to the method. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The value returned by the child process. |
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
load_nos_plugins() -> List[dict]
¤
Load NOS plugin definitions declared in the worker inventory.
Fetches each plugin file listed under the nos_plugins key of the
FakeNOS inventory, parses the YAML content, and returns the list of
plugin dictionaries ready to be passed to :class:FakeNOS.
Returns:
| Type | Description |
|---|---|
List[dict]
|
List of parsed NOS plugin dictionaries. Empty if no plugins are |
List[dict]
|
configured or all plugins fail to load. |
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
get_version() -> Result
¤
Return version information for key packages and the Python runtime.
Returns:
| Type | Description |
|---|---|
Result
|
class: |
Result
|
names ( |
Result
|
|
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
get_inventory() -> Result
¤
Return the raw FakeNOS inventory loaded by this worker.
Returns:
| Type | Description |
|---|---|
Result
|
class: |
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
270 271 272 273 274 275 276 277 278 | |
stop(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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job context injected by the |
required |
network
|
Union[str, None]
|
Name of the network to stop. If |
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 | |
start(job: Job, network: str, inventory: Union[str, dict, None] = None) -> Result
¤
Start a new FakeNOS network in a dedicated child process.
If inventory is a URL or file path, it is fetched and parsed before
the network is started. The network entry stored in
self.networks preserves the resolved inventory dict so that
restart can reuse it without re-fetching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job context injected by the |
required |
network
|
str
|
Unique name to assign to this FakeNOS network. |
required |
inventory
|
Union[str, dict, None]
|
Inventory definition for the network. Can be:
|
None
|
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
restart(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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job context injected by the |
required |
network
|
str
|
Name of the FakeNOS network to restart. Must already
exist in |
required |
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
inspect_networks(job: Job, network: Union[str, None] = None, details: bool = True) -> Result
¤
Return status information for one or all FakeNOS networks.
When details is True each network entry includes the child
process PID, liveness flag, and a list of host dicts retrieved from
the child process. When details is False only the list of
network names is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job context injected by the |
required |
network
|
Union[str, None]
|
Name of the network to inspect. If |
None
|
details
|
bool
|
When |
True
|
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
fakenos_network_process(inventory: dict, stop_event: multiprocessing.Event, cmd_queue: multiprocessing.Queue, result_queue: multiprocessing.Queue, nos_plugins: list = None) -> None
¤
Target function executed in a dedicated process for each FakeNOS network.
Runs a :class:FakeNOS instance and services method-call requests from the
parent process via cmd_queue. Each request must be a
(method_name, args, kwargs) 3-tuple. The return value (or a string
representation of any exception) is placed on result_queue so the parent
can retrieve it synchronously.
Supported method_name values:
"_get_hosts_as_list"– returns a list of host-info dicts with the keysname,platform,port,username,password.
The loop exits when stop_event is set, after which the FakeNOS network is gracefully stopped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inventory
|
dict
|
FakeNOS inventory dictionary passed directly to
:class: |
required |
stop_event
|
Event
|
Shared :class: |
required |
cmd_queue
|
Queue
|
Incoming method-call requests from the parent process. |
required |
result_queue
|
Queue
|
Outgoing results delivered back to the parent process. |
required |
nos_plugins
|
list
|
Optional list of NOS plugin definitions to register with FakeNOS. |
None
|
Source code in norfab\workers\fakenos_worker\fakenos_worker.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |