ciscoconfparse2.ConfigList Object
- class ciscoconfparse2.ConfigList(initlist: List[str] | tuple[str, ...] | None = None, comment_delimiters: List[str] | None = None, factory: bool = False, ignore_blank_lines: bool = False, syntax: str = 'ios', auto_commit: bool = True, debug: int = 0, **kwargs)
A custom list to hold
BaseCfgLine
objects. Most users will never need to use this class directly.Initialize the class.
- Parameters:
initlist (Union[List[str],tuple[str, ...]]) – A sequence of text configuration statements
comment_delimiters (List[str]) – Sequence of string comment-delimiters; only change this when parsing non-Cisco configurations.
factory (bool) – Controls whether to read the configuration lines as a factory input
ignore_blank_lines (bool) – Controls whether blank configuration lines should be ignored, default to False.
syntax (str) – A valid configuration syntax, default to ‘ios’.
auto_commit (bool) – Controls whether configuration changes are automatically committed.
debug (int) – Debug level of this object.
- Returns:
A
ConfigList
instance.- Return type:
Attributes
initlist
(list, tuple) A sequence of text configuration statements
comment_delimiters
(list) A sequence of text comment delimiters
factory
(bool) Whether to derive beta-quality configuration attributes for Cisco configurations
ignore_blank_lines
(bool) Whether to ignore blank lines in the configuration
syntax
(str) One of ‘ios’, ‘nxos’, ‘asa’, ‘iosxr’, or ‘junos’
auto_commit
(bool) Whether to automatically commit changes to the configuration
debug
(int) Debug level of this configuration instance
ccp_ref
(CiscoConfParse) A reference to the CiscoConfParse instance which owns this ConfigList
dna
(str) A string representing the type of CiscoConfParse instance this is
current_checkpoint
(int) The value of the current checkpoint; this will be updated with each ConfigList change
commit_checkpoint
(int) The value of the saved checkpoint; this will only be updated when a commit() is called
data
(BaseCfgLine) An internal sequence of BaseCfgLine instances used to maintain the contents of this python UserList subclass
- __add__(other) List[BaseCfgLine]
- __class_getitem__ = <bound method GenericAlias of <class 'ciscoconfparse2.ciscoconfparse2.ConfigList'>>
- __contains__(item)
- __copy__() List[BaseCfgLine]
- __enter__() BaseCfgLine
- __exit__(*args, **kwargs)
- __getattribute__(arg) Any
Call arg on ConfigList() object, and if that fails, call arg from the ccp_ref attribute
- __getitem__(value) BaseCfgLine
- __hash__ = None
- __iadd__(other) List[BaseCfgLine]
- __imul__(n)
- __iter__()
- __mul__(n)
- __radd__(other) List[BaseCfgLine]
- __reversed__()
- __rmul__(n)
- property all_parents: List[BaseCfgLine]
- Returns:
A sequence of BaseCfgLine instances representing all parents in this ConfigList
- Return type:
List[BaseCfgLine]
- append(value: str) None
Append the BaseCfgLine() for
value
to the end of the ConfigList- Parameters:
value (str) – The value to append
- Return type:
None
- property asa_access_list: Dict[str, BaseCfgLine]
Return a dictionary of ACL name to ACE (list) mappings
- property asa_object_group_network: Dict[str, BaseCfgLine]
Return a dictionary of name to object-group network mappings
- bootstrap(text_list: List[str] | None = None, debug: int = 0) List[BaseCfgLine]
Accept a text list, and format into a list of BaseCfgLine() instances.
Parent / child relationships are assigned in this method.
- Returns:
Sequence of BaseCfgLine() objects.
- Return type:
List[BaseCfgLine]
- copy() List[BaseCfgLine]
- Returns:
A copy of this ConfigList()
- Return type:
List[BaseCfgLine]
- count(value: BaseCfgLine) int
- Parameters:
value (BaseCfgLine) – value
- Returns:
The number of instances of
value
- Return type:
- extend(other: List[BaseCfgLine] | tuple[ciscoconfparse2.ccp_abc.BaseCfgLine, ...]) None
Extend the ConfigList with
other
.- Return type:
None
- get_checkpoint() int
- Returns:
An integer representing a unique version of this ConfigList() and its contents.
- Return type:
- index(value: BaseCfgLine, *args) int
- Parameters:
value (BaseCfgLine) – The item to index
- Returns:
the index of
value
- Return type:
- insert(index: int, value: BaseCfgLine | str) None
- Parameters:
index (int) – Index to insert
value
atvalue (Union[BaseCfgLine,str]) – Object to be inserted in the ConfigList()
- Return type:
None
- insert_after(exist_val: str | None = None, new_val: str | None = None) None
Insert new_val after all occurances of exist_val.
- Parameters:
- Returns:
None
- Return type:
None
>>> parse = CiscoConfParse(config=["a a", "b b", "c c", "b b"]) >>> # Insert 'g' before any occurance of 'b' >>> retval = parse.config_objs.insert_after("b b", "X X") >>> parse.get_text() ... ["a a", "b b", "X X", "c c", "b b", "X X"] >>>
- insert_before(exist_val: str | None = None, new_val: str | None = None) None
Insert new_val before all occurances of exist_val.
- Parameters:
- Returns:
None
- Return type:
None
>>> parse = CiscoConfParse(config=["a a", "b b", "c c", "b b"]) >>> # Insert 'g' before any occurance of 'b' >>> retval = parse.insert_before("b b", "X X") >>> parse.get_text() ... ["a a", "X X", "b b", "c c", "X X", "b b"] >>>
- iter_no_comments(begin_index: int = 0) BaseCfgLine
- Returns:
The BaseCfgLine instance at or greater than
begin_index
if it is not a comment- Return type:
- iter_with_comments(begin_index: int = 0) BaseCfgLine
- Returns:
The BaseCfgLine instance at or greater than
begin_index
- Return type:
- pop(index: int = -1) BaseCfgLine
Remove and return item at
index
(default last).Raises IndexError if list is empty or index is out of range.
- Parameters:
index (int) – ConfigList index to pop
- Returns:
The pop’d value
- Return type:
- remove(value: BaseCfgLine) None
Remove first occurrence of
value
.Raises
ConfigListItemDoesNotExist
if the value is not present.- Parameters:
value (BaseCfgLine) – Value to remove from the ConfigList()
- Return type:
None
- property search_safe: bool
This is a seatbelt to ensure that configuration searches are safe; searches are not safe if the ConfigList() has changed without a commit. As such, this method checks the current version of
ConfigList().current_checkpoint
and compares it to the last knownConfigList().commit_checkpoint
. If they are the same, return True.ConfigList().commit_checkpoint
should only written byCiscoConfParse().commit()
- Return type:
- sort(cmp: Callable | None = None, key: Callable | None = None, reverse: bool = False) None
- Parameters:
cmp (Callable) – Specifies a custom comparison function of two arguments (list items) which should return a negative, zero or positive number depending on whether the first argument is considered smaller than, equal to, or larger than the second argument.
key (Callable) – Specifies a function of one argument that is used to extract a comparison key from each list element.
reverse (bool) – If True, then the list elements are sorted as if each comparison were reversed.
- Return type:
None