7.3. hierarchy

class nettoolkit.pyJuniper.hierarchy.Convert(dic, tabs, is_tailed=True, is_grouped=False, is_distributed=False, is_straight=False, is_straight_anyway=False, parent_prefix='', test=False)[source]

Bases: object

Converts Dicationary to Hierarchical config string

Parameters:
  • dic (dict) – dictionary

  • tabs (int) – front tabs

  • is_tailed (bool, optional) – tailed config. Defaults to True.

  • is_grouped (bool, optional) – grouped config. Defaults to False.

  • is_distributed (bool, optional) – distributed config. Defaults to False.

  • is_straight (bool, optional) – straight config. Defaults to False.

  • is_straight_anyway (bool, optional) – straight anyway config. Defaults to False.

  • parent_prefix (str, optional) – parent prefix. Defaults to ‘’.

add_to_str(s)[source]
property closure

Append Section closure to string

clubbed_candidate_terminator_lines(dic_key, dic_value)[source]

Clubbed candidates terminator words getting added to string

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

property convert

start Converting dictionary to config string.

Returns:

None

Return type:

None

distributed_candidate_terminator_lines(dic_key, dic_value)[source]

Distributed terminator candidate words getting added to string

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

exception(dic_key)[source]

Exceptional identifiex configurations - Add more as found any

Parameters:

dic_key (str) – key to be found in set line

property front_tabs
grp_candidate_straight(dic_key, dic_value)[source]

group config, which has straight candidate

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

grp_candidates_clubbed(dic_key, dic_value)[source]

clubbed group config

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

grp_candidates_distributed(dic_key, dic_value)[source]

Distributed group config

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

grp_has_suffix_candidate(dic_key, dic_value)[source]

group config, which has suffix candidate.

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

grp_nested(dic_key, dic_value)[source]

nested group config

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

grp_suffixes(dic_key, dic_value)[source]

group config

Parameters:
  • dic_key (str) – key/string to be added to config

  • dic_value (dict) – sub-section config (if any)

logic_groups(dic_key, dic_value)[source]

section group selector logic

Parameters:
  • dic_key (str) – string key to be pass on to selector logic

  • dic_value (dic) – dictionary for the key to be pass on to selector logic

logic_terminators(dic_key, dic_value)[source]

line terminators selector logic

Parameters:
  • dic_key (str) – string key to be pass on to selector logic

  • dic_value (dic) – dictionary for the key to be pass on to selector logic

Returns:

Returns True if any terminator logic matches found else None

Return type:

bool

property terminator_line
update_front_tabs(n)[source]

update front tab value with add of n

Parameters:

n (int) – adds n to tabs

update_prefix(k)[source]

update prefix value to k

Parameters:

k (str) – key to be added

class nettoolkit.pyJuniper.hierarchy.Hierarchy(input_file, output_file)[source]

Bases: object

Hierarchical config conversion

Parameters:
  • input_file (str) – input set config file

  • output_file (str) – output file

convert()[source]

convert input file

class nettoolkit.pyJuniper.hierarchy.Section(in_list, ordered=False)[source]

Bases: object

Configuration Section Creator

add(ordered)[source]

add the key value to self.dic go thru recursive lookup for dictionary tree

Parameters:

ordered (bool) – dictionary to be ordered or not

nettoolkit.pyJuniper.hierarchy.excluded(dic, members, member_key)[source]

Checks for matching key from provided dictionary (dic) in to members dictionary’s member_key, returns True if found any.

Parameters:
  • dic ([type]) – input dictionary for which keys to be searched in to members dictinary members

  • members ([type]) – members dicationary to be looked in to.

  • member_key (str) – member key to be looked in to members dictionary

Returns:

True if any excluded member found, None Else

Return type:

bool

nettoolkit.pyJuniper.hierarchy.included(dic, members, member_key)[source]

Checks for matching key from provided dictionary (dic) in to members dictionary’s member_key, returns True if found or member_key not found in members dict.

Parameters:
  • dic ([type]) – input dictionary for which keys to be searched in to members dictinary members

  • members ([type]) – members dicationary to be looked in to.

  • member_key (str) – member key to be looked in to members dictionary

Returns:

True if any excluded member found or member_key not in members, False Else

Return type:

bool

nettoolkit.pyJuniper.hierarchy.li_li_words(in_str)[source]

converts multiline string in to list of list of words.

Parameters:

in_str (str) – Multiline string

Returns:

list of list of words.

Return type:

list

nettoolkit.pyJuniper.hierarchy.mysplit(line, by=' ')[source]

split line by (default space), also retain the strings like descriptions as it is.

Parameters:
  • line (str) – string line

  • by (character, optional) – Split by option. Defaults to “ “.

Returns:

split line and return list

Return type:

list

nettoolkit.pyJuniper.hierarchy.recursive_item_lookup(lili_words)[source]

create and yields dictionary/list from provided list of list of words.

Parameters:

lili_words (list) – input list of list of words

Yields:

dict – yields dictionary item/value pairs

nettoolkit.pyJuniper.hierarchy.related_list(in_list, word)[source]

filter input list for the given word in index-0 position

Parameters:
  • in_list (list) – input list of list

  • word (str) – word to be check in index-0 position.

Returns:

filtered output list

Return type:

list

nettoolkit.pyJuniper.hierarchy.section_dict(in_list, word, full_review=False)[source]

create section dectionary from given input list for the selected word.

Parameters:
  • in_list (list, str) – Input list or string

  • word (str) – selected word for which list to be search up on and generate dictionary

  • full_review (bool, optional) – go thru full list if set to true, else only check first match only. Defaults to False.

Raises:

NotImplementedError – Unmatched input type for input.

Returns:

dictionary with key equal input word and value as list of words from matched suffixes.

Return type:

dict

nettoolkit.pyJuniper.hierarchy.zero_items(in_list)[source]

Return all Zero (0) indexed Items from list of lists

Parameters:

in_list (list) – input list of lists

Returns:

all 0-index items from list of lists

Return type:

list