Nornir processor plugin which calculates the duration of each task
Project description
nornir_task_duration
Nornir processor plugin
which calculates the duration of each task
This plugin will store the duration of each task as attribute in the Nornir result objects.
Installation
pip install nornir_task_duration
Purpose
The plugin will add new class attributes to the Nornir results:
- total_duration: this is the total duration to process all hosts, this is added to the AggregatedResult
- host_duration: this is the totoal duration to process a single host, this is added to the host's MultiResult
- duration: this is added to the Result of each task
Usage
This example shows the usage of the processor and an example how to print a summary. You may want to use the duration during the task execution or in another print plugin.
from nornir import InitNornir
from nornir.core.task import Result, Task, AggregatedResult, MultiResult
from nornir_task_duration.plugins.processors import TaskDuration
nr = InitNornir(
inventory={
"plugin": "YAMLInventory",
"options": {
"host_file": "tests/inventory/hosts.yaml",
"group_file": "tests/inventory/groups.yaml",
"defaults_file": "tests/inventory/defaults.yaml",
},
}
)
nrp = nr.with_processors([TaskDuration()])
results = nrp.run(task=some_task)
def printer(res):
if type(res) is AggregatedResult:
print(f"TOTAL DURATION:{res.total_duration}")
for r in res:
print(f" * HOST:{r} - DURATION:{res[r].host_duration}")
printer(res[r])
if type(res) is MultiResult:
for r in res:
printer(r)
if type(res) is Result:
print(f" -- task:{res.name} - duration:{res.duration}")
printer(results)
# TOTAL DURATION:12
# * HOST:test1 - DURATION:9
# -- task:ROOT-TASK - duration:9
# -- task:task1 - duration:4
# -- task:task2 - duration:3
# -- task:task2 - duration:3
# * HOST:test2 - DURATION:12
# -- task:ROOT-TASK - duration:12
# -- task:task1 - duration:4
# -- task:task2 - duration:3
# -- task:task2 - duration:3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for nornir_task_duration-0.0.1a0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1b7f2c9418ec858d2592522db8cc5e863bfd32f89ba942ab56d165cddb1c9ce |
|
MD5 | a6dc424934c0f37b65ab0de7b987681d |
|
BLAKE2b-256 | b178c8c9f0fd895007f873afcd6f770f7f0b896c4d149c08cad14e1ff5f500a0 |
Close
Hashes for nornir_task_duration-0.0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8854cf7d4bc65b445fac0c134c19a29ba74a5622544e932d754005bf520956a2 |
|
MD5 | fbd0fb563faa058ce595e9311d698e31 |
|
BLAKE2b-256 | ffe590d9fc32a3222cb042164109138b8e6959bf4935fc9a5aa0135b3ba42ea7 |