ciscoconfparse.ConfigList Object

class ciscoconfparse.ConfigList(initlist=None, comment_delimiter='!', debug=0, factory=False, ignore_blank_lines=True, syntax='ios', parse_braces=True, ccp_ref=None, **kwargs)

A custom list to hold BaseCfgLine objects.

Most people will never need to use this class directly.

Initialize the class.

Parameters
  • initlist (list) – A list of parsed IOSCfgLine objects

  • comment_delimiter (str) – A comment delimiter. This should only be changed when parsing non-Cisco IOS configurations, which do not use a ! as the comment delimiter. comment defaults to ‘!’

  • debug (int) – debug defaults to 0, and should be kept that way unless you’re working on a very tricky config parsing problem. Debug output is not particularly friendly

  • ignore_blank_lines (bool) – ignore_blank_lines defaults to True; when this is set True, ciscoconfparse ignores blank configuration lines. You might want to set ignore_blank_lines to False if you intentionally use blank lines in your configuration (ref: Github Issue #3).

Return type

An instance of an ConfigList object.

__eq__(other)

Return self==value.

__ge__(other)

Return self>=value.

__getattribute__(arg)

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

__gt__(other)

Return self>value.

__hash__ = None
__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

__repr__()

Return repr(self).

__str__()

Return str(self).

property access_list

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

append(val)

S.append(value) – append value to the end of the sequence

assign_braces_parent_child(input_list=None, debug=0)

Accept a list of brace-delimited *CfgLine() objects; these objects should not already have a parent assigned.

Walk the list and assign parents / children in the brace-delimited config.

Closing braces should be considered a child of the parent line (with an open curly-brace).

Return this list.


line number 0 line number 1 {

line number 2 {

line number 3 line number 4 {

line number 5 line number 6 line number 7

} # Assign this closing-brace’s parent as line 4

} # Assign this closing-brace’s parent as line 2

} # Assign this closing-brace’s parent as line 1 line number 11

clear() None -- remove all items from S
config_hierarchy()

Walk this configuration and return the following tuple at each parent ‘level’: (list_of_parent_sibling_objs, list_of_nonparent_sibling_objs)

count(value) integer -- return number of occurrences of value
extend(other)

S.extend(iterable) – extend sequence by appending elements from the iterable

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(ii, val)

S.insert(index, value) – insert value before index

insert_before(exist_val, new_val, atomic=False)

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.

  • atomic (bool) – A boolean that controls whether the config is reparsed after the insertion (default False)

Returns

An ios-style configuration list (indented by stop_width for each configuration level).

Return type

list

Examples

>>> 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.commit()
>>> parse.ioscfg
... ["a a", "X X", "b b", "c c", "X X", "b b"]
>>>
property names

Return a dictionary of name to address mappings

property object_group_network

Return a dictionary of name to object-group network mappings

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(val)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()

S.reverse() – reverse IN PLACE