ciscoconfparse.CiscoConfParse Object
- class ciscoconfparse.CiscoConfParse(config='', comment='!', debug=0, factory=False, linesplit_rgx='\\r*\\n+', ignore_blank_lines=True, syntax='ios', encoding='UTF-8', read_only=False)
Parse Cisco IOS configurations and answer queries about the configs.
Initialize CiscoConfParse.
- Parameters:
- configlist or str
A list of configuration statements, or a configuration file path to be parsed
- commentstr
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 ‘!’. This value can hold multiple characters in case the config uses multiple characters for comment delimiters; however, the comment delimiters are always assumed to be one character wide- debugint
debug
defaults to 0, and should be kept that way unless you’re working on a very tricky config parsing problem. Debug range goes from 0 (no debugging) to 5 (max debugging). Debug output is not particularly friendly.- factorybool
factory
defaults to False; if setTrue
, it enables a beta-quality configuration line classifier.- linesplit_rgxstr
linesplit_rgx
is used when parsing configuration files to find where new configuration lines are. It is best to leave this as the default, unless you’re working on a system that uses unusual line terminations (for instance something besides Unix, OSX, or Windows)- ignore_blank_linesbool
ignore_blank_lines
defaults to True; when this is set True, ciscoconfparse ignores blank configuration lines. You might want to setignore_blank_lines
to False if you intentionally use blank lines in your configuration (ref: Github Issue #3), or you are parsing configurations which naturally have blank lines (such as Cisco Nexus configurations).- syntaxstr
A string holding the configuration type. Default: ‘ios’. Must be one of: ‘ios’, ‘nxos’, ‘iosxr’, ‘asa’, ‘junos’. Use ‘junos’ for any brace-delimited network configuration (including F5, Palo Alto, etc…).
- encodingstr
A string holding the coding type. Default is locale.getpreferredencoding()
- read_onlybool
A bool indicating whether CiscoConfParse should execute read-only.
- Returns:
Examples
This example illustrates how to parse a simple Cisco IOS configuration with
CiscoConfParse
into a variable calledparse
. This example also illustrates what theConfigObjs
andioscfg
attributes contain.>>> from ciscoconfparse import CiscoConfParse >>> config = [ ... 'logging trap debugging', ... 'logging 172.28.26.15', ... ] >>> parse = CiscoConfParse(config=config) >>> parse <CiscoConfParse: 2 lines / syntax: ios / comment delimiter: '!' / factory: False> >>> parse.ConfigObjs <ConfigList, comment='!', conf=[<IOSCfgLine # 0 'logging trap debugging'>, <IOSCfgLine # 1 'logging 172.28.26.15'>]> >>> parse.ioscfg ['logging trap debugging', 'logging 172.28.26.15'] >>>
Attributes
Return a list containing all text configuration statements.
CiscoConfParse().objs is an alias for the CiscoConfParse().ConfigObjs property; it returns a ConfigList() of config-line objects.
Fix Py3.5 deprecation of universal newlines - Ref Github #114; also see https://softwareengineering.stackexchange.com/q/298677/23144.
comment_delimiter
(str) A string containing the comment-delimiter. Default: “!”
ConfigObjs
(
ConfigList
) A custom list, which contains all parsedIOSCfgLine
instances.debug
(int) An int to enable verbose config parsing debugs. Default 0.
syntax
(str) A string holding the configuration type. Default: ‘ios’. Must be one of: ‘ios’, ‘nxos’, ‘iosxr’, ‘asa’, ‘junos’. Use ‘junos’ for any brace-delimited network configuration (including F5, Palo Alto, etc…).
- ConfigObjs = None
- __repr__()
Return a string that represents this CiscoConfParse object instance. The number of lines embedded in the string is calculated from the length of the ConfigObjs attribute.
- atomic()
Use
atomic()
to manually fix upConfigObjs
relationships after modifying a parsed configuration. This method is slow; try to batch calls toatomic()
if possible.Warning
If you modify a configuration after parsing it with
CiscoConfParse
, you must callcommit()
oratomic()
before searching the configuration again with methods such asfind_objects()
. Failure to callcommit()
oratomic()
on config modifications could lead to unexpected search results.See also
- check_ccp_input_good(config=None, logger=None, linesplit_rgx='\\r*\\n+')
The config parameter is a sequence of text config commands. Return True or False based on whether the config can be parsed.
- comment_delimiter = '!'
- commit()
Alias for calling the
atomic()
method. This method is slow; try to batch calls tocommit()
if possible.Warning
If you modify a configuration after parsing it with
CiscoConfParse
, you must callcommit()
oratomic()
before searching the configuration again with methods such asfind_objects()
. Failure to callcommit()
oratomic()
on config modifications could lead to unexpected search results.See also
- property config
config
is an alias forConfigObjs
- debug = 0
- delete()
- delete_objects(linespec, exactmatch=False, ignore_ws=False)
Find all
IOSCfgLine
objects whose text matches linespec, and delete the object
- encoding = 'UTF-8'
- factory = False
- find_child_objects(parentspec, childspec=None, ignore_ws=False, recurse=False, escape_chars=False)
Parse through the children of all parents matching parentspec, and return a list of child objects, which matched the childspec.
- Parameters:
- parentspecstr or list
Text regular expression for the line to be matched; this must match the parent’s line
- childspecstr
Text regular expression for the line to be matched; this must match the child’s line
- ignore_wsbool
boolean that controls whether whitespace is ignored
- escape_charsbool
boolean that controls whether characters are escaped before searching
- Returns:
- list
A list of matching child objects
Examples
This example finds the object for “ge-0/0/0” under “interfaces” in the following config…
interfaces ge-0/0/0 unit 0 family ethernet-switching port-mode access vlan members VLAN_FOO ge-0/0/1 unit 0 family ethernet-switching port-mode trunk vlan members all native-vlan-id 1 vlan unit 0 family inet address 172.16.15.5/22
The following object should be returned:
<IOSCfgLine # 7 ' ge-0/0/1' (parent is # 0)>
We do this by quering find_child_objects(); we set our parent as ^s*interface and set the child as ^s+ge-0/0/1.
>>> from ciscoconfparse import CiscoConfParse >>> config = ['interfaces', ... ' ge-0/0/0', ... ' unit 0', ... ' family ethernet-switching', ... ' port-mode access', ... ' vlan', ... ' members VLAN_FOO', ... ' ge-0/0/1', ... ' unit 0', ... ' family ethernet-switching', ... ' port-mode trunk', ... ' vlan', ... ' members all', ... ' native-vlan-id 1', ... ' vlan', ... ' unit 0', ... ' family inet', ... ' address 172.16.15.5/22', ... ] >>> p = CiscoConfParse(config=config) >>> p.find_child_objects('^\s*interfaces', ... r'\s+ge-0/0/1') [<IOSCfgLine # 7 ' ge-0/0/1' (parent is # 0)>] >>>
- find_interface_objects(intfspec, exactmatch=True)
Find all
IOSCfgLine
orNXOSCfgLine
objects whose text is an abbreviation forintfspec
and return the objects in a python list.- Parameters:
- intfspecstr
A string which is the abbreviation (or full name) of the interface.
- exactmatchbool
Defaults to True; when True, this option requires
intfspec
match the whole interface name and number.
- Returns:
- list
A list of matching
IOSIntfLine
objects
Notes
The configuration must be parsed with
factory=True
to use this method.Examples
>>> from ciscoconfparse import CiscoConfParse >>> config = [ ... '!', ... 'interface Serial1/0', ... ' ip address 1.1.1.1 255.255.255.252', ... '!', ... 'interface Serial1/1', ... ' ip address 1.1.1.5 255.255.255.252', ... '!', ... ] >>> parse = CiscoConfParse(config=config, factory=True) >>> >>> parse.find_interface_objects('Se 1/0') [<IOSIntfLine # 1 'Serial1/0' info: '1.1.1.1/30'>] >>>
- find_object_branches(branchspec=(), regex_flags=0, allow_none=True, regex_groups=False, empty_branches=False, debug=0)
Iterate over a tuple of regular expressions in branchspec and return matching objects in a list of lists (consider it similar to a table of matching config objects). branchspec expects to start at some ancestor and walk through the nested object hierarchy (with no limit on depth).
Previous CiscoConfParse() methods only handled a single parent regex and single child regex (such as
find_objects()
).Transcend past one-level of parent-child relationship parsing to include multiple nested ‘branches’ of a single family (i.e. parents, children, grand-children, great-grand-children, etc). The result of handling longer regex chains is that it flattens what would otherwise be nested loops in your scripts; this makes parsing heavily-nested configuratations like Juniper, Palo-Alto, and F5 much simpler. Of course, there are plenty of applications for “flatter” config formats like IOS.
Return a list of lists (of object ‘branches’) which are nested to the same depth required in branchspec. However, unlike most other CiscoConfParse() methods, return an explicit None if there is no object match. Returning None allows a single search over configs that may not be uniformly nested in every branch.
- Parameters:
- branchspectuple
A tuple of python regular expressions to be matched.
- regex_flags
Chained regular expression flags, such as re.IGNORECASE|re.MULTILINE
- regex_groupsbool (default False)
If True, return a tuple of re.Match groups instead of the matching configuration objects.
- empty_branchesbool (default False)
If True, return a list of None statements if there is no match; before version 1.9.49, this defaulted True.
- debugint
Set debug > 0 for debug messages
- Returns:
- list
A list of lists of matching
IOSCfgLine
objects
Examples
>>> from operator import attrgetter >>> from ciscoconfparse import CiscoConfParse >>> config = [ ... 'ltm pool FOO {', ... ' members {', ... ' k8s-05.localdomain:8443 {', ... ' address 192.0.2.5', ... ' session monitor-enabled', ... ' state up', ... ' }', ... ' k8s-06.localdomain:8443 {', ... ' address 192.0.2.6', ... ' session monitor-enabled', ... ' state down', ... ' }', ... ' }', ... '}', ... 'ltm pool BAR {', ... ' members {', ... ' k8s-07.localdomain:8443 {', ... ' address 192.0.2.7', ... ' session monitor-enabled', ... ' state down', ... ' }', ... ' }', ... '}', ... ] >>> parse = CiscoConfParse(config=config, syntax='junos', comment='#') >>> >>> branchspec = (r'ltm\spool', r'members', r'\S+?:\d+', r'state\sup') >>> branches = parse.find_object_branches(branchspec=branchspec) >>> >>> # We found three branches >>> len(branches) 3 >>> # Each branch must match the length of branchspec >>> len(branches[0]) 4 >>> # Print out one object 'branch' >>> branches[0] [<IOSCfgLine # 0 'ltm pool FOO'>, <IOSCfgLine # 1 ' members' (parent is # 0)>, <IOSCfgLine # 2 ' k8s-05.localdomain:8443' (parent is # 1)>, <IOSCfgLine # 5 ' state up' (parent is # 2)>] >>> >>> # Get the a list of text lines for this branch... >>> [ii.text for ii in branches[0]] ['ltm pool FOO', ' members', ' k8s-05.localdomain:8443', ' state up'] >>> >>> # Get the config text of the root object of the branch... >>> branches[0][0].text 'ltm pool FOO' >>> >>> # Note: `None` in branches[1][-1] because of no regex match >>> branches[1] [<IOSCfgLine # 0 'ltm pool FOO'>, <IOSCfgLine # 1 ' members' (parent is # 0)>, <IOSCfgLine # 6 ' k8s-06.localdomain:8443' (parent is # 1)>, None] >>> >>> branches[2] [<IOSCfgLine # 10 'ltm pool BAR'>, <IOSCfgLine # 11 ' members' (parent is # 10)>, <IOSCfgLine # 12 ' k8s-07.localdomain:8443' (parent is # 11)>, None]
- find_objects(linespec, exactmatch=False, ignore_ws=False)
Find all
IOSCfgLine
objects whose text matcheslinespec
and return theIOSCfgLine
objects in a python list.- Parameters:
- linespecstr
A string or python regular expression, which should be matched
- exactmatchbool
Defaults to False. When set True, this option requires
linespec
match the whole configuration line, instead of a portion of the configuration line.- ignore_wsbool
boolean that controls whether whitespace is ignored. Default is False.
- Returns:
- list
A list of matching
IOSCfgLine
objects
Examples
This example illustrates the use of
find_objects()
>>> from ciscoconfparse import CiscoConfParse >>> config = [ ... '!', ... 'interface Serial1/0', ... ' ip address 1.1.1.1 255.255.255.252', ... '!', ... 'interface Serial1/1', ... ' ip address 1.1.1.5 255.255.255.252', ... '!', ... ] >>> parse = CiscoConfParse(config=config) >>> >>> parse.find_objects(r'^interface') [<IOSCfgLine # 1 'interface Serial1/0'>, <IOSCfgLine # 4 'interface Serial1/1'>] >>>
- find_objects_w_missing_children(parentspec, childspec, ignore_ws=False)
Return a list of parent
IOSCfgLine
objects, which matched theparentspec
and whose children do not match all elements inchildspec
. Only the parentIOSCfgLine
objects will be returned.- Parameters:
- parentspecstr
Text regular expression for the
IOSCfgLine
object to be matched; this must match the parent’s line- childspeclist
A list of text regular expressions to be matched among the children
- ignore_wsbool
boolean that controls whether whitespace is ignored
- Returns:
- list
A list of matching parent
IOSCfgLine
objects
- find_objects_w_parents(parentspec, childspec, ignore_ws=False)
Parse through the children of all parents matching parentspec, and return a list of child objects, which matched the childspec.
This is just an alias for find_child_objects()
- Parameters:
- parentspecstr
Text regular expression for the line to be matched; this must match the parent’s line
- childspecstr
Text regular expression for the line to be matched; this must match the child’s line
- ignore_wsbool
boolean that controls whether whitespace is ignored
- Returns:
- list
A list of matching child objects
- find_objects_wo_child(parentspec, childspec, ignore_ws=False, recurse=False)
Return a list of parent
IOSCfgLine
objects, which matched theparentspec
and whose children did not matchchildspec
. Only the parentIOSCfgLine
objects will be returned. For simplicity, this method only finds oldest_ancestors without immediate children that match.- Parameters:
- parentspecstr
Text regular expression for the
IOSCfgLine
object to be matched; this must match the parent’s line- childspecstr
Text regular expression for the line to be matched; this must match the child’s line
- ignore_wsbool
boolean that controls whether whitespace is ignored
- Returns:
- list
A list of matching parent configuration lines
- find_parent_objects(parentspec, childspec=None, ignore_ws=False, recurse=False, escape_chars=False)
Return a list of parent
IOSCfgLine
objects, which matched theparentspec
and whose children matchchildspec
. Only the parentIOSCfgLine
objects will be returned.- Parameters:
- parentspecstr or list
Text regular expression for the
IOSCfgLine
object to be matched; this must match the parent’s line- childspecstr
Text regular expression for the line to be matched; this must match the child’s line
- ignore_wsbool
boolean that controls whether whitespace is ignored
- recursebool
Set True if you want to search all children (children, grand children, great grand children, etc…)
- escape_charsbool
Set True if you want to escape characters before searching
- Returns:
- list
A list of matching parent
IOSCfgLine
objects
Examples
This example uses
find_parent_objects()
to find all ports that are members of access vlan 300 in following config…! interface FastEthernet0/1 switchport access vlan 532 spanning-tree vlan 532 cost 3 ! interface FastEthernet0/2 switchport access vlan 300 spanning-tree portfast ! interface FastEthernet0/3 duplex full speed 100 switchport access vlan 300 spanning-tree portfast !
The following interfaces should be returned:
interface FastEthernet0/2 interface FastEthernet0/3
We do this by quering find_objects_w_child(); we set our parent as ^interface and set the child as switchport access vlan 300.
>>> from ciscoconfparse import CiscoConfParse >>> config = ['!', ... 'interface FastEthernet0/1', ... ' switchport access vlan 532', ... ' spanning-tree vlan 532 cost 3', ... '!', ... 'interface FastEthernet0/2', ... ' switchport access vlan 300', ... ' spanning-tree portfast', ... '!', ... 'interface FastEthernet0/3', ... ' duplex full', ... ' speed 100', ... ' switchport access vlan 300', ... ' spanning-tree portfast', ... '!', ... ] >>> p = CiscoConfParse(config=config) >>> p.find_parent_objects('^interface', ... 'switchport access vlan 300') ... [<IOSCfgLine # 5 'interface FastEthernet0/2'>, <IOSCfgLine # 9 'interface FastEthernet0/3'>] >>>
- find_parent_objects_wo_child(parentspec, childspec, ignore_ws=False, recurse=False, escape_chars=False)
Return a list of parent
IOSCfgLine
objects, which matched theparentspec
and whose children did not matchchildspec
. Only the parentIOSCfgLine
objects will be returned. For simplicity, this method only finds oldest_ancestors without immediate children that match.- Parameters:
- parentspecstr
Text regular expression for the
IOSCfgLine
object to be matched; this must match the parent’s line- childspecstr
Text regular expression for the line to be matched; this must match the child’s line
- ignore_wsbool
boolean that controls whether whitespace is ignored
- recursebool
boolean that controls whether to recurse through children of children
- escape_charsbool
boolean that controls whether to escape characters before searching
- Returns:
- list
A list of matching parent configuration lines
Examples
This example finds all ports that are autonegotiating in the following config…
! interface FastEthernet0/1 switchport access vlan 532 spanning-tree vlan 532 cost 3 ! interface FastEthernet0/2 switchport access vlan 300 spanning-tree portfast ! interface FastEthernet0/2 duplex full speed 100 switchport access vlan 300 spanning-tree portfast !
The following interfaces should be returned:
interface FastEthernet0/1 interface FastEthernet0/2
We do this by quering find_parent_objects_wo_child(); we set our parent as ^interface and set the child as speedsd+ (a regular-expression which matches the word ‘speed’ followed by an integer).
>>> from ciscoconfparse import CiscoConfParse >>> config = ['!', ... 'interface FastEthernet0/1', ... ' switchport access vlan 532', ... ' spanning-tree vlan 532 cost 3', ... '!', ... 'interface FastEthernet0/2', ... ' switchport access vlan 300', ... ' spanning-tree portfast', ... '!', ... 'interface FastEthernet0/3', ... ' duplex full', ... ' speed 100', ... ' switchport access vlan 300', ... ' spanning-tree portfast', ... '!', ... ] >>> p = CiscoConfParse(config=config) >>> p.find_parent_objects_wo_child(r'^interface', r'speed\s\d+') [<IOSCfgLine # 1 'interface FastEthernet0/1'>, <IOSCfgLine # 5 'interface FastEthernet0/2'>] >>>
- finished_config_parse = False
- handle_ccp_brace_syntax(tmp_lines=None, syntax=None)
Deal with brace-delimited syntax issues, such as conditionally discarding junos closing brace-lines.
- ignore_blank_lines = True
- property ioscfg
Return a list containing all text configuration statements.
- property objs
CiscoConfParse().objs is an alias for the CiscoConfParse().ConfigObjs property; it returns a ConfigList() of config-line objects.
- property openargs
Fix Py3.5 deprecation of universal newlines - Ref Github #114; also see https://softwareengineering.stackexchange.com/q/298677/23144.
- re_match_iter_typed(regexspec, group=1, result_type=<class 'str'>, default='', untyped_default=False)
Use
regexspec
to search the root parents in the config and return the contents of the regular expression group, at the integergroup
index, cast asresult_type
; if there is no match,default
is returned.- Parameters:
- regexspecstr
A string or python compiled regular expression, which should be matched. This regular expression should contain parenthesis, which bound a match group.
- groupint
An integer which specifies the desired regex group to be returned.
group
defaults to 1.- result_typetype
A type (typically one of:
str
,int
,float
, orIPv4Obj
). All returned values are cast asresult_type
, which defaults tostr
.- defaultany
The default value to be returned, if there is no match. The default is an empty string.
- untyped_defaultbool
Set True if you don’t want the default value to be typed
- Returns:
result_type
The text matched by the regular expression group; if there is no match,
default
is returned. All values are cast asresult_type
. The default result_type is str.
Examples
This example illustrates how you can use
re_match_iter_typed()
to get the first interface name listed in the config.>>> import re >>> from ciscoconfparse import CiscoConfParse >>> config = [ ... '!', ... 'interface Serial1/0', ... ' ip address 1.1.1.1 255.255.255.252', ... '!', ... 'interface Serial2/0', ... ' ip address 1.1.1.5 255.255.255.252', ... '!', ... ] >>> parse = CiscoConfParse(config=config) >>> parse.re_match_iter_typed(r'interface\s(\S+)') 'Serial1/0' >>>
The following example retrieves the hostname from the configuration
>>> from ciscoconfparse import CiscoConfParse >>> config = [ ... '!', ... 'hostname DEN-EDGE-01', ... '!', ... 'interface Serial1/0', ... ' ip address 1.1.1.1 255.255.255.252', ... '!', ... 'interface Serial2/0', ... ' ip address 1.1.1.5 255.255.255.252', ... '!', ... ] >>> parse = CiscoConfParse(config=config) >>> parse.re_match_iter_typed(r'^hostname\s+(\S+)') 'DEN-EDGE-01' >>>
- re_search_children(regexspec, recurse=False)
Use
regexspec
to search for root parents in the config with text matching regex. If recurse is False, only root parent objects are returned. A list of matching objects is returned.This method is very similar to
find_objects()
(when recurse is True); however it was written in response to the use-case described in Github Issue #156.- Parameters:
- regexspecstr
A string or python regular expression, which should be matched.
- recursebool
Set True if you want to search all objects, and not just the root parents
- Returns:
- list
A list of matching
IOSCfgLine
objects which matched. If there is no match, an emptylist()
is returned.
- read_config_file(filepath=None, linesplit_rgx='\\r*\\n+')
Read the config lines from the filepath. Return the list of text configuration commands or raise an error.
- read_only = False
- replace_objects(linespec, replacestr, excludespec=None, exactmatch=False, atomic=False)
This method is a text search and replace (Case-sensitive). You can optionally exclude lines from replacement by including a string (or compiled regular expression) in excludespec.
- Parameters:
- linespecstr
Text regular expression for the line to be matched
- replacestrstr
Text used to replace strings matching linespec
- excludespecstr
Text regular expression used to reject lines, which would otherwise be replaced. Default value of
excludespec
is None, which means nothing is excluded- exactmatchbool
boolean that controls whether partial matches are valid
- atomicbool
boolean that controls whether the config is reparsed after replacement (default False)
- Returns:
- list
A list of changed configuration lines
Examples
This example finds statements with EXTERNAL_CBWFQ in following config, and replaces all matching lines (in-place) with EXTERNAL_QOS. For the purposes of this example, let’s assume that we do not want to make changes to any descriptions on the policy.
! policy-map EXTERNAL_CBWFQ description implement an EXTERNAL_CBWFQ policy class IP_PREC_HIGH priority percent 10 police cir percent 10 conform-action transmit exceed-action drop class IP_PREC_MEDIUM bandwidth percent 50 queue-limit 100 class class-default bandwidth percent 40 queue-limit 100 policy-map SHAPE_HEIR class ALL shape average 630000 service-policy EXTERNAL_CBWFQ !
We do this by calling replace_objects(linespec=’EXTERNAL_CBWFQ’, replacestr=’EXTERNAL_QOS’, excludespec=’description’)…
>>> from ciscoconfparse import CiscoConfParse >>> config = ['!', ... 'policy-map EXTERNAL_CBWFQ', ... ' description implement an EXTERNAL_CBWFQ policy', ... ' class IP_PREC_HIGH', ... ' priority percent 10', ... ' police cir percent 10', ... ' conform-action transmit', ... ' exceed-action drop', ... ' class IP_PREC_MEDIUM', ... ' bandwidth percent 50', ... ' queue-limit 100', ... ' class class-default', ... ' bandwidth percent 40', ... ' queue-limit 100', ... 'policy-map SHAPE_HEIR', ... ' class ALL', ... ' shape average 630000', ... ' service-policy EXTERNAL_CBWFQ', ... '!', ... ] >>> p = CiscoConfParse(config=config) >>> p.replace_objects('EXTERNAL_CBWFQ', 'EXTERNAL_QOS', 'description') ['policy-map EXTERNAL_QOS', ' service-policy EXTERNAL_QOS'] >>> >>> # Now when we call `p.find_objects('policy-map EXTERNAL_QOS')`, we get the >>> # changed configuration, which has the replacements except on the >>> # policy-map's description. >>> objs = p.find_objects('EXTERNAL_QOS')[0] >>> [ii.text for ii in objs] ['policy-map EXTERNAL_QOS', ' description implement an EXTERNAL_CBWFQ policy', ' class IP_PREC_HIGH', ' class IP_PREC_MEDIUM', ' class class-default', 'policy-map SHAPE_HEIR', ' class ALL', ' shape average 630000', ' service-policy EXTERNAL_QOS'] >>>
- save_as(filepath)
Save a text copy of the configuration at
filepath
; this method uses the OperatingSystem’s native line separators (such as\r\n
in Windows).
- syntax = 'ios'
- property text
Return a list containing all text configuration statements; it is an alias for
CiscoConfParse().ioscfg
.
- class ciscoconfparse.Diff(hostname=None, old_config=None, new_config=None, syntax='ios')
Initialize Diff().
- Parameters:
- hostnameNone
An empty parameter, which seems to be optional for the diff backend
- old_configstr
A string containing text configuration statements representing the most-recent config. Default value: None. If a filepath is provided, load the configuration from the file.
- new_configstr
A string containing text configuration statements representing the desired config. Default value: None. If a filepath is provided, load the configuration from the file.
- syntaxstr
A string holding the configuration type. Default: ‘ios’.
- Returns:
- diff()
diff() returns the list of required configuration statements to go from the old_config to the new_config
- rollback()
rollback() returns the list of required configuration statements to rollback from the new_config to the old_config