6.2. convertdict

class nettoolkit.nettoolkit_db.convertdict.ConvDict(dic=None)[source]

Bases: object

convert dictionary to and from between nested and serialzed format

convert_table_dic()[source]

convert the nested table dictionary to serialized format, returns serialized dict

Returns:

updated table dictionary

Return type:

dict

convert_var_dic()[source]

convert the var key:value pair to a dictionary of list of FIND/REPLACE pairs

Returns:

updated var dictionary

Return type:

dict

expand_dfdic_to_dict(sheetname, dic)[source]

expand the provided dictionary to nested dictionary and return it

Parameters:
  • sheetname (str) – sheet name

  • dic (dict) – dataframe dictionary

Returns:

dictionary of converted dictionary

Return type:

dict

expand_to_dict(df_var, df_table)[source]

expand the provided dataframes of var/table to nested dictionary and return it

Parameters:
  • df_var (DataFrame) – var (find/replace) pairs dictionary

  • df_table (DataFrame) – tabular data dictionary

Returns:

dictionary of converted data

Return type:

dict

set_index_keys_parents(ikp={'ifaggregates', 'ifloopbacks', 'ifphysicals', 'ifvlans', 'instances'})[source]

set the parents of index keys

Parameters:

ikp (set, optional) – Parent Index keys. Defaults to INDEX_KEY_PARENTS.

set_var_table_keys(var='var', table='table')[source]

standup variable of tab name, static variables:var , tabular data:table

Parameters:
  • var (str, optional) – static find/replace kind data variable referance. Defaults to ‘var’.

  • table (str, optional) – tabular data variable referance. Defaults to ‘table’.

to_dataframe(sheetname)[source]

convert the given sheetname dictionary to necessary serialized format and convert and return to pandas dataframe object

Parameters:

sheetname (str) – Sheet Name

Returns:

dataframe

Return type:

DataFrame

nettoolkit.nettoolkit_db.convertdict.appendkey(dic, prefix='')[source]

add the prefix to keys of dictionary and return updated dictionary. conjuction will be “_”.

Parameters:
  • dic (dict) – dictionary

  • prefix (str, optional) – prefix to add on key while removing nesting. Defaults to “”.

Returns:

updated dictionary

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.expand_table_dict(dic)[source]

rollback of recursive_dic(), revert the key:value nested pairs to its original position. returns nested dictionary

Parameters:

dic (dict) – dictionary

Returns:

updated dictionary

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.expand_var_dict(dic)[source]

rollback of varsheet(), revert the values to its original dictionary format.

Parameters:

dic (dict) – dictionary

Returns:

updated dictionary

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.recursive_dic(dic, prevkey='')[source]

recursive lookup in provided dictionary and serialize it to convert it to pandas data frame which can be later used to convert to excel. returns updated dictionary with key:[list of values]

Parameters:
  • dic (dict) – nested dictionary

  • prevkey (str, optional) – previous key to add as prefix. Defaults to ‘’.

Returns:

updated dictionary

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.standup_dic(dic, ikp)[source]

create and return a dictionary with basic basic keys/header OBSOLETE NOW.

Parameters:
  • dic (dict) – dictionary

  • ikp (_type_) – basic mandatory interface id/types/value

Returns:

dictionary with mandatory items

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.update_nested_key(dic, keys, vitem)[source]

add the nested keys in dictionary if missing, update value for trailing key, and returns updated dictionary

Parameters:
  • dic (dict) – dictionary

  • keys (str) – keys

  • vitem (str,iterator,dict) – any nested items

Returns:

updated dictionary

Return type:

dict

nettoolkit.nettoolkit_db.convertdict.varsheet(dic)[source]

convert and return captured var dictionary to FIND/REPLACE pairs of dict to generate the DataFrame. constraint: var-sheet has column names “FIND” & “REPLACE”

Parameters:

dic (dict) – dictionary with find/replace pairs as key/value pair

Returns:

dictionary which is friendly to convert to DataFrame and ultimately to Excel

Return type:

dict