pyntc.utils
¶
PyNTC Utilities.
pyntc.utils.convert_dict_by_key(original, key_map, fill_in=False, whitelist=[], blacklist=[])
¶
Use a key map to convert a dictionary to desired keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
dict
|
Original dictionary to be converted. |
required |
key_map
|
dict
|
Key map to use to convert dictionary. |
required |
fill_in
|
dict
|
Whether the returned dictionary should contain keys and values from the original dictionary if not specified in the key map. |
False
|
whitelist
|
list
|
If fill_in is True, and whitelist isn't empty, only fill in the keys in the whitelist in the returned dictionary. |
[]
|
blacklist
|
list
|
If fill_in is True, and blacklist isn't empty, fill in with all keys from the original dictionary besides those in the blacklist. |
[]
|
Returns:
| Type | Description |
|---|---|
dict
|
A converted dictionary through the key map. |
pyntc.utils.convert_list_by_key(original_list, key_map, fill_in=False, whitelist=[], blacklist=[])
¶
Apply a list conversion for all items in original_list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_list
|
list
|
Original list to be converted. |
required |
key_map
|
dict
|
Key map to use to convert list. |
required |
fill_in
|
dict
|
Whether the returned list should contain keys and values from the original dictionary if not specified in the key map. |
False
|
whitelist
|
list
|
If fill_in is True, and whitelist isn't empty, only fill in the keys in the whitelist in the returned dictionary. |
[]
|
blacklist
|
list
|
If fill_in is True, and blacklist isn't empty, fill in with all keys from the original dictionary besides those in the blacklist. |
[]
|
Returns:
| Type | Description |
|---|---|
list
|
A converted list. |
pyntc.utils.get_structured_data(template_name, rawtxt)
¶
Return structured data given raw text using TextFSM templates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_name
|
str
|
Name of template to use. |
required |
rawtxt
|
str
|
Raw output from device. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A dict per entry returned by TextFSM. |
pyntc.utils.recursive_key_lookup(keys, obj)
¶
Lookup nested object by indexing through a dictionary sequentally through keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
list
|
The dictionary keys to use to lookup an object. |
required |
obj
|
dict
|
The dictionary to traverse. |
required |
Example
keys = ["a", "b", "c"] data = {"a": {"b": {"c": 1}}} recursive_key_lookup(keys, data) 1