7.1. Facts Generator

7.1.1. facts_gen

Boiler plate code for the facts generation. fg_dict: attribute will provide the output dictionary with pandas dataframe as values to be readily available to write it to excel. dev_type: attribute returns the device type of configuraton provided

class nettoolkit.facts_finder.generators.facts_gen.FactsGen(capture_file)[source]

Bases: object

Facts Generator class (boiler plate code)

Parameters:

capture_file (str) – configuration capture file

property dev_type

detected device type for the given configuration capture

Raises:
  • Exception – for Invalid device type

  • Exception – for Missing FactsGen call

Returns:

returns device type in string

Return type:

str

property fg_dict

facts generator dictionary

Returns:

dataframe dictionary

Return type:

dict

reset_interfaces_index(df_dict)[source]

reset Interfaces to interface and remove it from index

Parameters:

df_dict (dict) – dataframe dictionary

split_interfaces(df_dict)[source]

splits different types of interfaces

Parameters:

df_dict (dict) – dataframe dictionary

verify_capture_existance()[source]

verifications of all mandatory commands existance in output

nettoolkit.facts_finder.generators.facts_gen.get_absolute_command(dev_type, cmd)[source]

retrive absolute command for given command of device type.

Parameters:
  • dev_type (str) – device type (cisco_ios, juniper_junos)

  • cmd (str) – full/shortened command

Returns:

full length absolute command

Return type:

str

nettoolkit.facts_finder.generators.facts_gen.get_necessary_cmds(dev_type)[source]

retrive necessary/mandatory commands for the given device type (cisco_ios, juniper_junos)

Parameters:

dev_type (str) – device type

Returns:

set of mandatory commands

Return type:

set

7.1.2. clean

Device Facts cleanup

class nettoolkit.facts_finder.clean.CleanFacts(capture_log_file, capture_parsed_file=None, convert_to_cit=False, remove_cit_bkp=True, skip_txtfsm=False, new_suffix='-clean', use_cdp=False, debug=False, output_folder='.')[source]

Bases: object

cleans the captured parsed file and writes out the modified facts in new clean file using additional information provided from capture log file. Also can get a few additional properties to process futher. A new clean file will be generated upon instance calling.

Parameters:
  • capture_log_file (str) – configuration capture log file name

  • capture_parsed_file (str) – configuration parsed excel file name

  • convert_to_cit (bool, optional) – convert normal capture log file to capture_it output format (useful if capture was taken manually). Defaults to False.

  • remove_cit_bkp (bool, optional) – remove duplicated log file (capture_it output format). Defaults to True.

  • skip_txtfsm (bool, optional) – skip evaluation of capture excel file (textfsm parsed file), and use native facts-finder parsers. Defaults to False.

  • new_suffix (str, optional) – file suffix. Defaults to ‘-clean’.

  • use_cdp (bool, optional) – use cdp neighbor (overrides lldp neighbor) . Defaults to False.

  • debug (bool, optional) – for trouble shooting purpose only. Defaults to False.

call(MergeClass)[source]

calls the modifier merge class

Parameters:

MergeClass (cls) – MergeClass

property clean_file

new output clean filename

property config

device configuration. for cisco show running, for juniper show configuration - set output

property dev_type

device type string either(cisco/juniper)

get_facts_gen()[source]

gets Facts from generators

property hostname

device hostname

merge_class()[source]

returns Modifier Merge Class from the generated Facts

remove_bkp_log()[source]

removes the backup file created during normal caprure read

set_config()[source]

set the appropriate configuration for device types.

Raises:

Exception – undetected device type

nettoolkit.facts_finder.clean.cisco_config(capture_log_file)[source]

returns cisco running configuration

Parameters:

capture_log_file (str) – device captured log

Returns:

configuration output in list

Return type:

list

nettoolkit.facts_finder.clean.get_clean_filename(path, file, suffix)[source]

get a new clened filename appended with suffix string

Parameters:
  • path (str) – full path with output file name

  • file (str) – capture file name

  • suffix (str) – suffix to be appened

Returns:

updated file name

Return type:

str

nettoolkit.facts_finder.clean.get_hostname_from_logfile(file)[source]

get device hostname from log file name

Parameters:

file (str) – full path with output file name

Returns:

updated file name

Return type:

str

nettoolkit.facts_finder.clean.juniper_config(capture_log_file)[source]

returns juniper configuration in set commnand output format

Parameters:

capture_log_file (str) – device captured log

Returns:

configuration output in list

Return type:

list

nettoolkit.facts_finder.clean.remove_file(xl)[source]

try to delete file if available, skip else

Parameters:

xl (str) – file to be deleted

7.1.3. device

class nettoolkit.facts_finder.generators.device.DevicePapa(file)[source]

Bases: object

Parent class defining common methods/properties of device

Parameters:

file (str) – file name

7.1.4. excel facts generator - execution boilerplate codes

nettoolkit.facts_finder.exec_fns.exec_facts_finder(log_files, custom=None, convert_to_cit=True, remove_cit_bkp=True, skip_txtfsm=True, new_suffix='-clean', use_cdp=False, debug=False, output_folder='.')[source]
nettoolkit.facts_finder.exec_fns.get_host(log_file)[source]
nettoolkit.facts_finder.exec_fns.update_device_dict(device_dict, field, value)[source]