6.4. nettoolkit common functions
- nettoolkit.nettoolkit_common.common.blank_line(line)[source]
checks if provided line is blank line or not.
- Parameters:
line (str) – input line
- Returns:
is line blank or not
- Return type:
bool
- nettoolkit.nettoolkit_common.common.dataframe_generate(d)[source]
convert dicationary to dataframe. multi-level dictionary will be converted flattened first inorder to convert to DataFrame.
- Parameters:
d (dict) – input can be multi-nested dictionary.
- Returns:
pandas DataFrame
- Return type:
DataFrame
- nettoolkit.nettoolkit_common.common.flatten(d, parent_key='', sep='_')[source]
flattens the dictionary
- Parameters:
d (dict) – input can be multi-nested dictionary.
parent_key (str, optional) – key from previous dictionary to be prefixed with current keys. Defaults to ‘’.
sep (str, optional) – keys separator. Defaults to ‘_’.
- Returns:
dictionary of lists if input is dictinoary, list with input dictionary if input is anything else
- Return type:
dict, list
- nettoolkit.nettoolkit_common.common.get_device_manufacturar(file)[source]
finds out manufacturer (cisco/juniper) from given capture file. in case if not found, it will return as Unidentified.
- Parameters:
file (str) – input capture file
- Returns:
Either one from - Cisco, Juniper, Unidentified
- Return type:
str
- nettoolkit.nettoolkit_common.common.get_op(file, cmd)[source]
filter the command output from given captured file. Note: output should be taken from capture_it utility or it should be in the format derived by it.
- Parameters:
file (str) – capture file
cmd (str) – show command for which output to capture
- Returns:
filtered command output in list format
- Return type:
list
- nettoolkit.nettoolkit_common.common.get_ops(file, cmd_startswith)[source]
filter the command outputs from given captured file. Note: output should be taken from capture_it utility or it should be in the format derived by it.
- Parameters:
file (str) – capture file
cmd_startswith (str) – show command start string
- Returns:
filtered command output in dict format
- Return type:
dict
- nettoolkit.nettoolkit_common.common.get_string_part(line, begin, end)[source]
get the sub-string out of provided long string(line)
- Parameters:
line (str) – string line
begin (int) – sub-str start point
end (int) – sub-str end point
- Raises:
TypeError – Raise error if input is invalid or sub-string falls outside
- Returns:
sub-string
- Return type:
str
- nettoolkit.nettoolkit_common.common.get_string_trailing(line, begin_at)[source]
get the training part of sub-string starting from provided index
- Parameters:
line (str) – string line
begin_at (int) – sub-str start point
- Raises:
TypeError – Raise error if input is invalid or sub-string falls outside
- Returns:
sub-string
- Return type:
str
- nettoolkit.nettoolkit_common.common.mac_2digit_separated(mac)[source]
converts input mac to 2 digit separated mac format, separator=`:`
- Parameters:
mac (str) – mac address
- Returns:
2 digit separated format of mac address
- Return type:
str
- nettoolkit.nettoolkit_common.common.mac_4digit_separated(mac)[source]
converts input mac to 4 digit separated mac format, separator=`.`
- Parameters:
mac (str) – mac address
- Returns:
4 digit separated format of mac address
- Return type:
str
- nettoolkit.nettoolkit_common.common.read_file(file)[source]
read the provided text file and retuns output in list format
- Parameters:
file (str) – text file name
- Returns:
output converted to list (separated by lines)
- Return type:
list
- nettoolkit.nettoolkit_common.common.remove_domain(hn)[source]
Removes domain suffix from provided hostname string
- Parameters:
hn (str) – fully qualified dns hostname
- Returns:
hostname left by removing domain suffix
- Return type:
str
- nettoolkit.nettoolkit_common.common.standardize_mac(mac)[source]
removes . or : from mac address and make it a standard
- Parameters:
mac (str) – mac address
- Returns:
standard format of mac address
- Return type:
str
- nettoolkit.nettoolkit_common.common.verifid_output(cmd_op)[source]
vefifies if command output is in valid state. Multiline string are splits with CR. and retuns as list. if input is a list, it will be returned as is. any other input will throw error.
- Parameters:
cmd_op (list, str) – Either list or Multiline string of output
- Raises:
TypeError – Raise error if input is other than string or list.
- Returns:
output in list format
- Return type:
list