Returner Plugins
Returners responsible for returning produced results to various destinations.
Self Returner Plugin
Plugin Name: self
This plugin does nothing with results, implementing behavior where results stored in TTR object for further programmatic consumption.
- ttr.plugins.returners.self_returner.dump(data_dict, **kwargs)
This function applying no actions to results, implemented to keep plugins API consistent.
- Parameters
data_dict – (dict) dictionary keyed by
result_name_key
where values are rendered results stringkwargs – (dict) any additional arguments ignored
Terminal Returner Plugin
Plugin Name: terminal
This plugin prints rendered result to terminal screen applying minimal formatting to improve readability.
For instance if these are rendering results:
{'rt-1': 'interface Gi1/1\n'
' description Customer A\n'
' encapsulation dot1q 100\n'
' vrf forwarding cust_a\n'
' ip address 10.0.0.1 255.255.255.0\n'
' exit\n'
'!\n'
'interface Gi1/2\n'
' description Customer C\n'
' encapsulation dot1q 300\n'
' vrf forwarding cust_c\n'
' ip address 10.0.3.1 255.255.255.0\n'
' exit\n'
'!',
'rt-2': 'interface Gi1/2\n'
' description Customer B\n'
' encapsulation dot1q 200\n'
' vrf forwarding cust_b\n'
' ip address 10.0.2.1 255.255.255.0\n'
' exit\n'
'!'}
Terminal returner will print to screen:
# ---------------------------------------------------------------------------
# rt-1 rendering results
# ---------------------------------------------------------------------------
interface Gi1/1
description Customer A
encapsulation dot1q 100
vrf forwarding cust_a
ip address 10.0.0.1 255.255.255.0
exit
!
interface Gi1/2
description Customer C
encapsulation dot1q 300
vrf forwarding cust_c
ip address 10.0.3.1 255.255.255.0
exit
!
# ---------------------------------------------------------------------------
# rt-2 rendering results
# ---------------------------------------------------------------------------
interface Gi1/2
description Customer B
encapsulation dot1q 200
vrf forwarding cust_b
ip address 10.0.2.1 255.255.255.0
exit
!
This returner useful for debugging or, for instance, when it is easier to copy produced results from terminal screen.
- ttr.plugins.returners.terminal_returner.dump(data_dict, **kwargs)
This function prints results to terminal screen
- Parameters
data_dict – (dict) dictionary keyed by
result_name_key
where values are rendered results stringkwargs – (dict) any additional arguments ignored
File Returner Plugin
Plugin Name: file
This plugin responsible for saving results to text files
iterating over results dictionary keyed by result_name_key
.
For example, if results data_dict
might look like this:
{"rt-1": "interface Gi1/1\n"
" description Customer A\n"
" encapsulation dot1q 100\n"
" vrf forwarding cust_a\n"
" ip address 10.0.0.1 255.255.255.0\n"
" exit\n"
"!\n"
"interface Gi1/2\n"
" description Customer C\n"
" encapsulation dot1q 300\n"
" vrf forwarding cust_c\n"
" ip address 10.0.3.1 255.255.255.0\n"
" exit\n"
"!",
"rt-2": "interface Gi1/2\n"
" description Customer B\n"
" encapsulation dot1q 200\n"
" vrf forwarding cust_b\n"
" ip address 10.0.2.1 255.255.255.0\n"
" exit\n"
"!"}
If result_dir
argument set to ./Output/
, file returner
will iterate over data_dict
using keys as filenames
populating files with values at the end ./Output/
directory
will contain two files named rt-1.txt
and rt-2.txt
with
respective content.
- ttr.plugins.returners.file_returner.dump(data_dict, result_dir='./Output/', **kwargs)
Function to save results in text files.
- Parameters
data_dict – (dict) dictionary keyed by
result_name_key
where values are strings to save in text filesresult_dir – (str) OS path to directory to save results in
kwargs – (dict) any additional arguments ignored