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:

ConfigList

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

CiscoConfParse: Any
__add__(other) List[BaseCfgLine]
__class_getitem__ = <bound method GenericAlias of <class 'ciscoconfparse2.ciscoconfparse2.ConfigList'>>
__contains__(item)
__copy__() List[BaseCfgLine]
__delitem__(idx) None
__enter__() BaseCfgLine
__eq__(other) bool

Return self==value.

__exit__(*args, **kwargs)
__ge__(other) bool

Return self>=value.

__getattribute__(arg) Any

Call arg on ConfigList() object, and if that fails, call arg from the ccp_ref attribute

__getitem__(value) BaseCfgLine
__gt__(other) bool

Return self>value.

__hash__ = None
__iadd__(other) List[BaseCfgLine]
__imul__(n)
__iter__()
__le__(other) bool

Return self<=value.

__len__() int
__lt__(other) bool

Return self<value.

__mul__(n)
__radd__(other) List[BaseCfgLine]
__repr__() str

Return repr(self).

__reversed__()
__rmul__(n)
__setitem__(idx, value) None
__str__() str

Return str(self).

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 as_text: List[str]
Returns:

Configuration as a list of text lines

Return type:

List[str]

property asa_access_list: Dict[str, BaseCfgLine]

Return a dictionary of ACL name to ACE (list) mappings

property asa_object_group_names: Dict[str, str]

Return a dictionary of name to address mappings

property asa_object_group_network: Dict[str, BaseCfgLine]

Return a dictionary of name to object-group network mappings

auto_commit: bool
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]

ccp_ref: Any
clear() None

Remove all items from ConfigList.

Return type:

None

comment_delimiters: List[str] | None
commit() bool
Returns:

The result of the ConfigList() commit operation

Return type:

bool

commit_checkpoint: int
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:

int

current_checkpoint: int
debug: int
dna: str
extend(other: List[BaseCfgLine] | tuple[ciscoconfparse2.ccp_abc.BaseCfgLine, ...]) None

Extend the ConfigList with other.

Return type:

None

factory: bool
get_checkpoint() int
Returns:

An integer representing a unique version of this ConfigList() and its contents.

Return type:

int

ignore_blank_lines: bool
index(value: BaseCfgLine, *args) int
Parameters:

value (BaseCfgLine) – The item to index

Returns:

the index of value

Return type:

int

initlist: List[str] | tuple[str, ...] | None
insert(index: int, value: BaseCfgLine | str) None
Parameters:
  • index (int) – Index to insert value at

  • value (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:
  • exist_val (str) – An existing text value. This may match multiple configuration entries.

  • new_val (str) – A new value to be inserted in the configuration.

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:
  • exist_val (str) – An existing text value. This may match multiple configuration entries.

  • new_val (str) – A new value to be inserted in the configuration.

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:

BaseCfgLine

iter_with_comments(begin_index: int = 0) BaseCfgLine
Returns:

The BaseCfgLine instance at or greater than begin_index

Return type:

BaseCfgLine

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:

BaseCfgLine

reassign_linenums() None

Renumber the configuration line numbers

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

reverse() None

Reverse the ConfigList() in-place.

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 known ConfigList().commit_checkpoint. If they are the same, return True. ConfigList().commit_checkpoint should only written by CiscoConfParse().commit()

Return type:

bool

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

syntax: str