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', indent_width: int = 0, auto_commit: bool = True, ccp_ref: Any = None, debug: int = 0)
A custom list to hold
BaseCfgLineobjects. 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’.
indent_width (int) – The standard width to indent child lines (default: 0 for auto-detect).
auto_commit (bool) – Controls whether configuration changes are automatically committed.
debug (int) – Debug level of this object.
- Returns:
A
ConfigListinstance.- Return type:
Attributes
- initlistlist, tuple
A sequence of text configuration statements
- comment_delimiterslist
A sequence of text comment delimiters
- factorybool
Whether to derive beta-quality configuration attributes for Cisco configurations
- ignore_blank_linesbool
Whether to ignore blank lines in the configuration
- syntaxstr
One of ‘ios’, ‘nxos’, ‘asa’, ‘iosxr’, or ‘junos’
- auto_commitbool
Whether to automatically commit changes to the configuration
- ccp_refCiscoConfParse
The instance of the owning CiscoConfParse() instance
- debugint
Debug level of this configuration instance
- ccp_refCiscoConfParse
A reference to the CiscoConfParse instance which owns this ConfigList
- dnastr
A string representing the type of CiscoConfParse instance this is
- current_checkpointint
The value of the current checkpoint; this will be updated with each ConfigList change
- commit_checkpointint
The value of the saved checkpoint; this will only be updated when a commit() is called
- dataBaseCfgLine
An internal sequence of BaseCfgLine instances used to maintain the contents of this python UserList subclass
- __add__(other) list[BaseCfgLine]
- __attrs_props__ = ClassProps(is_exception=False, is_slotted=True, has_weakref_slot=True, is_frozen=False, kw_only=<KeywordOnly.NO: 'no'>, collected_fields_by_mro=True, added_init=False, added_repr=False, added_eq=False, added_ordering=False, hashability=<Hashability.LEAVE_ALONE: 'leave_alone'>, added_match_args=True, added_str=False, added_pickling=True, on_setattr_hook=<function pipe.<locals>.wrapped_pipe>, field_transformer=None)
- classmethod __class_getitem__(args, /)
Represent a PEP 585 generic type
E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).
- __contains__(item)
- __copy__() list[BaseCfgLine]
- __enter__() GeneratorType
- __exit__(*args, **kwargs)
- __firstlineno__ = 637
- __getattribute__(arg) Any
Call arg on ConfigList() object, and if that fails, call arg from the ccp_ref attribute
- __hash__ = None
- __iadd__(other) list[BaseCfgLine]
- __imul__(n)
- __iter__()
- __mul__(n)
- __radd__(other) list[BaseCfgLine]
- __replace__(**changes)
Method generated by attrs for class ConfigList.
- __reversed__()
- __rmul__(n)
- __static_attributes__ = ('_RE_NAMES', '_RE_OBJACL', '_RE_OBJNET', '_RE_OBJSVC', '_network_cache', 'auto_commit', 'ccp_ref', 'comment_delimiters', 'commit_checkpoint', 'current_checkpoint', 'data', 'debug', 'dna', 'factory', 'ignore_blank_lines', 'indent_width', 'initlist', 'syntax')
- property all_parents: list[BaseCfgLine]
- Returns:
A sequence of BaseCfgLine instances representing all parents in this ConfigList
- Return type:
List[BaseCfgLine]
- append(line: str) None
Append the BaseCfgLine() for
lineto the end of the ConfigList- Parameters:
item – 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
- auto_indent_config(indent_width=-1) bool
Walk all BaseCfgLine() instances and auto-indent them based on the value of CiscoConfParse().auto_indent_width.
- bootstrap(text_list: list[str] | tuple[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.
This method includes special logic for handling IOS banners and macros.
This method modifies ConfigList().data
- Returns:
Sequence of BaseCfgLine() objects.
- Return type:
List[BaseCfgLine]
- copy() list[BaseCfgLine]
- Returns:
A copy of this ConfigList()
- Return type:
List[BaseCfgLine]
- count(item: BaseCfgLine) int
- Parameters:
item (BaseCfgLine) – value
- Returns:
The number of instances of
item- Return type:
- data: list[BaseCfgLine]
- extend(other: list[BaseCfgLine] | tuple[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(item: BaseCfgLine) int
- Parameters:
item (BaseCfgLine) – The item to index
- Returns:
the index of
item- Return type:
- insert(idx: int = -1, new_val: str | BaseCfgLine | None = None) BaseCfgLine
S.insert(index, value) – insert value before index
- insert_after(exist_val: BaseCfgLine | None = None, new_val: str | BaseCfgLine | None = None) BaseCfgLine
- insert_before(exist_val: BaseCfgLine | None = None, new_val: str | BaseCfgLine | None = None) BaseCfgLine
- iter_no_comments(begin_index: int = 0) GeneratorType
- Returns:
The BaseCfgLine instance at or greater than
begin_indexif it is not a comment- Return type:
- iter_with_comments(begin_index: int = 0) GeneratorType
- 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:
- rebuild_after_modification(commit: bool = False) list[str]
Rebuild the configuration, and renumber lines. Return a list of string config lines.
- remove(item: BaseCfgLine) None
Remove first occurrence of
item.Raises
ConfigListItemDoesNotExistif the item is not present.- Parameters:
item (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_checkpointand compares it to the last knownConfigList().commit_checkpoint. If they are the same, return True.ConfigList().commit_checkpointshould 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