Nornir Worker
Nornir Worker Inventory Reference¤
watchdog_interval
- watchdog run interval in seconds, default is 30connections_idle_timeout
- watchdog connection idle timeout, default isNone
- no timeout, connection always kept alive, if set to 0, connections disconnected imminently after task completed, if positive number, connection disconnected after not being used for overconnections_idle_timeout
WatchDog(worker)
¤
Bases: WorkerWatchDog
Class to monitor Nornir worker performance
Source code in norfab\workers\nornir_worker.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
connections_update(nr, plugin)
¤
Function to update connection use timestamps for each host
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nr
|
Nornir object |
required | |
plugin
|
str
|
connection plugin name |
required |
Source code in norfab\workers\nornir_worker.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
connections_clean()
¤
Check if need to tear down connections that are idle - not being used over connections_idle_timeout
Source code in norfab\workers\nornir_worker.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 |
|
connections_keepalive()
¤
Keepalive connections and clean up dead connections if any
Source code in norfab\workers\nornir_worker.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
NornirWorker(broker, service, worker_name, exit_event=None, init_done_event=None, log_level='WARNING', log_queue=None)
¤
Bases: NFPWorker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
broker
|
str
|
broker URL to connect to |
required |
service
|
str
|
name of the service with worker belongs to |
required |
worker_name
|
str
|
name of this worker |
required |
exit_event
|
if set, worker need to stop/exit |
None
|
|
init_done_event
|
event to set when worker done initializing |
None
|
|
log_level
|
str
|
logging level of this worker |
'WARNING'
|
Source code in norfab\workers\nornir_worker.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
render_jinja2_templates(templates, context, filters=None)
¤
Helper function to render a list of Jinja2 templates and combine them in a single string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
templates
|
list[str]
|
list of template strings to render |
required |
context
|
dict
|
Jinja2 context dictionary |
required |
filter
|
custom Jinja2 filters |
required |
Returns:
Type | Description |
---|---|
str
|
list of rendered strings |
Source code in norfab\workers\nornir_worker.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
load_job_data(job_data)
¤
Helper function to download job data and load it using YAML
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_data
|
str
|
URL to job data |
required |
Source code in norfab\workers\nornir_worker.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
get_nornir_hosts(details=False, **kwargs)
¤
Produce a list of hosts managed by this worker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
dict
|
dictionary of nornir-salt Fx filters |
{}
|
Source code in norfab\workers\nornir_worker.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
|
get_nornir_inventory(**kwargs)
¤
Retrieve running Nornir inventory for requested hosts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
dict
|
dictionary of nornir-salt Fx filters |
{}
|
Source code in norfab\workers\nornir_worker.py
533 534 535 536 537 538 539 540 541 542 543 |
|
get_nornir_version()
¤
Produce Python packages version report
Source code in norfab\workers\nornir_worker.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
task(plugin, **kwargs)
¤
Task to invoke any of supported Nornir task plugins. This function
performs dynamic import of requested plugin function and executes
nr.run
using supplied args and kwargs
plugin
attribute can refer to a file to fetch from file service. File must contain
function named task
accepting Nornir task object as a first positional
argument, for example:
# define connection name for RetryRunner to properly detect it
CONNECTION_NAME = "netmiko"
# create task function
def task(nornir_task_object, **kwargs):
pass
CONNECTION_NAME
CONNECTION_NAME
must be defined within custom task function file if
RetryRunner in use, otherwise connection retry logic skipped and connections
to all hosts initiated simultaneously up to the number of num_workers
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plugin
|
str
|
(str) |
required |
kwargs
|
(dict) arguments to use with specified task plugin |
{}
|
Source code in norfab\workers\nornir_worker.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
|
cli(commands=None, plugin='netmiko', cli_dry_run=False, run_ttp=None, job_data=None, to_dict=True, add_details=False, **kwargs)
¤
Task to collect show commands output from devices using Command Line Interface (CLI)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands
|
list
|
list of commands to send to devices |
None
|
plugin
|
str
|
plugin name to use - valid options are |
'netmiko'
|
cli_dry_run
|
bool
|
do not send commands to devices just return them |
False
|
job_data
|
str
|
URL to YAML file with data or dictionary/list of data to pass on to Jinja2 rendering context |
None
|
add_details
|
bool
|
if True will add task execution details to the results |
False
|
to_dict
|
bool
|
default is True - produces dictionary results, if False will produce results list |
True
|
run_ttp
|
str
|
TTP Template to run |
None
|
Source code in norfab\workers\nornir_worker.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
|
nb_get_next_ip(*args, **kwargs)
¤
Task to query next available IP address from Netbox service
Source code in norfab\workers\nornir_worker.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 |
|
cfg(config, plugin='netmiko', cfg_dry_run=False, to_dict=True, add_details=False, job_data=None, **kwargs)
¤
Task to send configuration commands to devices using Command Line Interface (CLI)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
list
|
list of commands to send to devices |
required |
plugin
|
str
|
plugin name to use - |
'netmiko'
|
cfg_dry_run
|
bool
|
if True, will not send commands to devices but just return them |
False
|
job_data
|
str
|
URL to YAML file with data or dictionary/list of data to pass on to Jinja2 rendering context |
None
|
add_details
|
bool
|
if True will add task execution details to the results |
False
|
to_dict
|
bool
|
default is True - produces dictionary results, if False will produce results list |
True
|
kwargs
|
additional arguments to pass to the task plugin |
{}
|
Returns:
Type | Description |
---|---|
dict
|
dictionary with the results of the configuration task |
Source code in norfab\workers\nornir_worker.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
test(suite, subset=None, dry_run=False, remove_tasks=True, failed_only=False, return_tests_suite=False, job_data=None, **kwargs)
¤
Function to tests data obtained from devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
suite
|
Union[list, str]
|
path to YAML file with tests |
required |
dry_run
|
bool
|
if True, returns produced per-host tests suite content only |
False
|
subset
|
str
|
list or string with comma separated non case sensitive glob patterns to filter tests' by name, subset argument ignored by dry run |
None
|
failed_only
|
bool
|
if True returns test results for failed tests only |
False
|
remove_tasks
|
bool
|
if False results will include other tasks output |
True
|
return_tests_suite
|
bool
|
if True returns rendered per-host tests suite content in addition to test results using dictionary with |
False
|
job_data
|
str
|
URL to YAML file with data or dictionary/list of data to pass on to Jinja2 rendering context |
None
|
kwargs
|
any additional arguments to pass on to Nornir service task |
{}
|
Source code in norfab\workers\nornir_worker.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
|
network(fun, **kwargs)
¤
Task to call various network related utility functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fun
|
(str) utility function name to call |
required | |
kwargs
|
(dict) function arguments Available utility functions. resolve_dns function resolves hosts' hostname DNS returning IP addresses using |
{}
|
Source code in norfab\workers\nornir_worker.py
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 |
|
parse(plugin='napalm', getters='get_facts', template=None, commands=None, to_dict=True, add_details=False, **kwargs)
¤
Function to parse network devices show commands output
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plugin
|
str
|
plugin name to use - |
'napalm'
|
getters
|
str
|
NAPALM getters to use |
'get_facts'
|
commands
|
list
|
commands to send to devices for TextFSM or TTP template |
None
|
template
|
str
|
TextFSM or TTP parsing template string or path to file For NAPALM plugin |
None
|
Source code in norfab\workers\nornir_worker.py
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
|
file_copy(source_file, plugin='netmiko', to_dict=True, add_details=False, dry_run=False, **kwargs)
¤
Task to transfer files to and from hosts using SCP
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_file
|
str
|
path to file to copy, support |
required |
plugin
|
str
|
plugin name to use - |
'netmiko'
|
to_dict
|
bool
|
default is True - produces dictionary results, if False produces list |
True
|
add_details
|
bool
|
if True will add task execution details to the results |
False
|
dry_run
|
bool
|
if True will not copy files just return what would be copied |
False
|
kwargs
|
additional arguments to pass to the plugin function |
{}
|
Returns:
Type | Description |
---|---|
dict
|
dictionary with the results of the file copy task |
Source code in norfab\workers\nornir_worker.py
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 |
|