Configs¶
netutils.config
¶
Initialization file for config methods.
clean
¶
Functions for working with configuration to clean the config.
clean_config(config, filters)
¶
Given a list of regex patterns, delete those lines that match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
A string representation of a device configuration. |
required |
filters |
List[Dict[str, str]]
|
A list of regex patterns used to delete remove configuration. |
required |
Returns:
Type | Description |
---|---|
str
|
Stripped down configuration. |
Examples:
>>> from netutils.config.clean import clean_config
>>> config = '''Building configuration...
... Current configuration : 1582 bytes
... !
... version 12.4
... service timestamps debug datetime msec
... service timestamps log datetime msec
... no service password-encryption
... !
... hostname CSR1
... !
... !
... !'''
>>> clean_filters = [
... {"regex": r"^Current\s+configuration.*\n"},
... {"regex": r"^Building\s+configuration.*\n"},
... {"regex": r"^ntp\s+clock-period.*\n"},
... ]
>>> print(clean_config(config, clean_filters))
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname CSR1
!
!
!
>>>
Source code in netutils/config/clean.py
sanitize_config(config, filters=None)
¶
Given a dictionary of filters, remove sensitive data from the provided config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
A string representation of a device configuration. |
required |
filters |
Optional[List[Dict[str, str]]]
|
A list of dictionaries of regex patterns used to sanitize configuration, namely secrets. Defaults to an empty list. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Sanitized configuration. |
Examples:
>>> from netutils.config.clean import sanitize_config
>>> config = '''enable secret 5 $1$nc08$bizeEFbgCBKjZP4nurNCd.!'''
>>> SANITIZE_FILTERS = [
... {
... "regex": r"^(enable (password|secret)( level \d+)? \d) .+$",
... "replace": r"\1 <removed>",
... }
... ]
>>> sanitize_config(config, SANITIZE_FILTERS)
'enable secret 5 <removed>'
>>>
Source code in netutils/config/clean.py
compliance
¶
Filter Plugins for compliance checks.
compliance(features, backup, intended, network_os, cfg_type='file')
¶
Report compliance for all features provided as input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
List[Dict[str, Union[str, bool, List[str]]]]
|
List of features for particular network os. |
required |
backup |
str
|
running config or config backup file to compare against intended. |
required |
intended |
str
|
intended config to compare against backup. |
required |
network_os |
str
|
Device network operating system that is in parser_map keys. |
required |
cfg_type |
str
|
A string that is effectively a choice between |
'file'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict[str, Dict[str, Union[str, bool]]]
|
Compliance information per feature. |
Examples:
>>> features = [
... {
... "name": "hostname",
... "ordered": True,
... "section": [
... "hostname"
... ]
... },
... {
... "name": "ntp",
... "ordered": True,
... "section": [
... "ntp"
... ]
... }
... ]
>>> backup = "ntp server 192.168.1.1\nntp server 192.168.1.2 prefer"
>>> intended = "ntp server 192.168.1.1\nntp server 192.168.1.5 prefer"
>>> network_os = "cisco_ios"
>>> from pprint import pprint
>>> compliance(features, backup, intended, network_os, "string") == \
... {'hostname': {'actual': '',
... 'cannot_parse': True,
... 'compliant': True,
... 'extra': '',
... 'intended': '',
... 'missing': '',
... 'ordered_compliant': True,
... 'unordered_compliant': True},
... 'ntp': {'actual': 'ntp server 192.168.1.1\nntp server 192.168.1.2 prefer',
... 'cannot_parse': True,
... 'compliant': False,
... 'extra': 'ntp server 192.168.1.2 prefer',
... 'intended': 'ntp server 192.168.1.1\nntp server 192.168.1.5 prefer',
... 'missing': 'ntp server 192.168.1.5 prefer',
... 'ordered_compliant': False,
... 'unordered_compliant': False}}
True
Source code in netutils/config/compliance.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
config_section_not_parsed(features, device_cfg, network_os)
¶
Return device config section that is not checked by compliance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
List[Dict[str, Union[str, bool, List[str]]]]
|
List of features for particular network os. |
required |
device_cfg |
str
|
Device configuration. |
required |
network_os |
str
|
Device network operating system that is in parser_map keys. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Union[str, List[str]]]
|
Config that was not parsed or section not found. |
Examples:
>>> features = [{
... "name": "BGP",
... "ordered": True,
... "section": [
... "router bgp "
... ]
... }]
>>> network_os = 'cisco_ios'
>>> device_cfg = '''router bgp 100
... bgp router-id 10.6.6.5
... !
... access-list 1 permit 10.10.10.10
... access-list 1 permit 10.10.10.11'''
>>> config_section_not_parsed(features, device_cfg, network_os)
{'remaining_cfg': '!\naccess-list 1 permit 10.10.10.10\naccess-list 1 permit 10.10.10.11', 'section_not_found': []}
Source code in netutils/config/compliance.py
diff_network_config(compare_config, base_config, network_os)
¶
Identify which lines in compare_config are not in base_config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compare_config |
str
|
The config to evaluate against base_config. |
required |
base_config |
str
|
The config to compare compare_config against. |
required |
network_os |
str
|
Device network operating system that is in parser_map keys. |
required |
Returns:
Name | Type | Description |
---|---|---|
base_config |
str
|
The string of additional commands in compare_config separated by a newline. |
Examples:
>>> compare_config = '''router bgp 100
... bgp router-id 10.6.6.5
... !
... snmp-server ifindex persist
... snmp-server packetsize 4096
... snmp-server location SFO
... access-list 1 permit 10.15.20.20
... access-list 1 permit 10.15.20.21'''
>>>
>>> base_config = '''router bgp 100
... bgp router-id 10.6.6.5
... !
... snmp-server packetsize 4096
... snmp-server location SFO
... access-list 1 permit 10.15.20.20
... access-list 1 permit 10.15.20.21'''
>>>
>>> network_os = "cisco_ios"
>>> diff_network_config(compare_config, base_config, network_os)
'snmp-server ifindex persist'
>>>
Source code in netutils/config/compliance.py
feature_compliance(feature, backup_cfg, intended_cfg, network_os)
¶
Report compliance for all features provided as input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Dict[str, Union[str, bool, List[str]]]
|
A dictionary with the attributes of the feature check |
required |
backup_cfg |
str
|
running config or config backup of a specific feature to compare. |
required |
intended_cfg |
str
|
intended config of a specific feature to compare. |
required |
network_os |
str
|
Device network operating system that is in parser_map keys. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict[str, Union[str, bool]]
|
Compliance information of a single feature. |
Examples:
>>> feature = {
... "name": "ntp",
... "ordered": True,
... "section": [
... "ntp"
... ]
... }
>>> backup = "ntp server 192.168.1.1\nntp server 192.168.1.2 prefer"
>>> intended = "ntp server 192.168.1.1\nntp server 192.168.1.5 prefer"
>>> network_os = "cisco_ios"
>>> from pprint import pprint
>>> feature_compliance(feature, backup, intended, network_os) == \
... {'actual': 'ntp server 192.168.1.1\nntp server 192.168.1.2 prefer',
... 'cannot_parse': True,
... 'compliant': False,
... 'extra': 'ntp server 192.168.1.2 prefer',
... 'intended': 'ntp server 192.168.1.1\nntp server 192.168.1.5 prefer',
... 'missing': 'ntp server 192.168.1.5 prefer',
... 'ordered_compliant': False,
... 'unordered_compliant': False}
True
Source code in netutils/config/compliance.py
find_unordered_cfg_lines(intended_cfg, actual_cfg)
¶
Check if config lines are miss-ordered, i.e in ACL-s.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
intended_cfg |
str
|
Feature intended configuration. |
required |
actual_cfg |
str
|
Feature actual configuration. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
Tuple[bool, List[Tuple[str, str]]]
|
List of tuples with unordered_compliant cfg lines. |
Examples:
>>> intended_cfg = '''
... ntp server 10.10.10.10
... ntp server 10.10.10.11
... ntp server 10.10.10.12'''
>>>
>>> actual_cfg = '''
... ntp server 10.10.10.12
... ntp server 10.10.10.11
... ntp server 10.10.10.10'''
>>>
>>> find_unordered_cfg_lines(intended_cfg, actual_cfg)
(True, [('ntp server 10.10.10.10', 'ntp server 10.10.10.12'), ('ntp server 10.10.10.12', 'ntp server 10.10.10.10')])
Source code in netutils/config/compliance.py
section_config(feature, device_cfg, network_os)
¶
Parse feature section config from device cfg.
In case section attribute of the the feature is not provided
entire content of the device_cfg is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature |
Dict[str, Union[str, bool, List[str]]]
|
Feature name and cfg lines that should be parsed. |
required |
device_cfg |
str
|
Device configuration. |
required |
network_os |
Device network operating system that is in parser_map keys. |
required |
Returns:
Type | Description |
---|---|
str
|
The hash report data mapping file hashes to report data. |
Examples:
>>> feature = {
... "name": "BGP",
... "ordered": False,
... "section": [
... "router bgp "
... ]
... }
>>>
>>> device_cfg = '''router bgp 100
... bgp router-id 10.6.6.5
... !
... snmp-server ifindex persist
... snmp-server packetsize 4096
... snmp-server location SFO
... access-list 1 permit 10.10.15.15
... access-list 1 permit 10.10.20.20'''
>>>
>>> print(section_config(feature, device_cfg, "cisco_ios"))# ==
router bgp 100
bgp router-id 10.6.6.5
Source code in netutils/config/compliance.py
conversion
¶
Configuration conversion methods for different network operating systems.
paloalto_panos_brace_to_set(cfg, cfg_type='file')
¶
Convert Palo Alto Brace format configuration to set format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
str
|
Configuration as a string |
required |
cfg_type |
str
|
A string that is effectively a choice between |
'file'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Converted configuration as a string. |
Examples:
>>> config = '''
... config {
... mgt-config {
... users {
... admin {
... phash *;
... permissions {
... role-based {
... superuser yes;
... }
... }
... public-key thisisasuperduperlongbase64encodedstring;
... }
... panadmin {
... permissions {
... role-based {
... superuser yes;
... }
... }
... phash passwordhash;
... }
... }
... }
... }'''
>>> paloalto_panos_brace_to_set(cfg=config, cfg_type='string') == \
... '''set mgt-config users admin phash *
... set mgt-config users admin permissions role-based superuser yes
... set mgt-config users admin public-key thisisasuperduperlongbase64encodedstring
... set mgt-config users panadmin permissions role-based superuser yes
... set mgt-config users panadmin phash passwordhash'''
True
Source code in netutils/config/conversion.py
parser
¶
Parsers for different network operating systems.
AIREOSConfigParser
¶
Bases: CiscoConfigParser
, BaseSpaceConfigParser
AireOSConfigParser implementation fo ConfigParser Class.
Source code in netutils/config/parser.py
ASAConfigParser
¶
Bases: CiscoConfigParser
Cisco ASA implementation of ConfigParser Class.
Source code in netutils/config/parser.py
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
Source code in netutils/config/parser.py
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = '''
... interface Management0/0
... management-only
... nameif Management
... security-level 100
... ip address 10.1.1.10 255.255.255.0'''
>>> config_tree = ASAConfigParser(str(config))
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line="interface Management0/0", parents=()),
... ConfigLine(config_line=" management-only", parents=("interface Management0/0",)),
... ConfigLine(config_line=" nameif Management", parents=("interface Management0/0",)),
... ConfigLine(config_line=" security-level 100", parents=("interface Management0/0",)),
... ConfigLine(config_line=" ip address 10.1.1.10 255.255.255.0", parents=("interface Management0/0",)),
... ]
True
Source code in netutils/config/parser.py
ArubaConfigParser
¶
Bases: BaseSpaceConfigParser
Aruba AOS-CX implementation fo ConfigParser Class.
Source code in netutils/config/parser.py
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 |
|
config_lines_only: str
property
¶
Remove spaces and unwanted lines from config lines.
Returns:
Type | Description |
---|---|
str
|
The non-space and non-comment lines from |
BaseBraceConfigParser
¶
Bases: BaseConfigParser
Base parser class for config syntax that demarcates using braces.
Source code in netutils/config/parser.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
|
config_lines_only: str
property
¶
Remove trailing spaces and empty lines from config lines.
Returns:
Type | Description |
---|---|
str
|
The non-space lines from |
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = '''auth ldap system-auth {
... port ldaps
... servers { ams-lda01.ntc.com }
... }
... auth partition Common {
... description "Repository for system objects and shared objects."
... }
... auth password-policy { }'''
>>> config_tree = BaseBraceConfigParser(config)
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line='auth ldap system-auth {', parents=()),
... ConfigLine(config_line=' port ldaps', parents=('auth ldap system-auth {',)),
... ConfigLine(config_line=' servers { ams-lda01.ntc.com }', parents=('auth ldap system-auth {',)),
... ConfigLine(config_line=' }', parents=('auth ldap system-auth {',)),
... ConfigLine(config_line=' auth partition Common {', parents=()),
... ConfigLine(config_line=' description "Repository for system objects and shared objects."', parents=(' auth partition Common {',)), ConfigLine(config_line=' }', parents=(' auth partition Common {',)),
... ConfigLine(config_line=' auth password-policy { }', parents=())
... ]
True
Source code in netutils/config/parser.py
BaseConfigParser
¶
Base class for parsers.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
config_lines_only: str
property
¶
Remove lines not related to config.
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
Source code in netutils/config/parser.py
BaseSpaceConfigParser
¶
Bases: BaseConfigParser
Base parser class for config syntax that demarcates using spaces/indentation.
Source code in netutils/config/parser.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
config_lines_only: str
property
¶
Remove spaces and comments from config lines.
Returns:
Type | Description |
---|---|
str
|
The non-space and non-comment lines from |
Examples:
indent_level: int
property
writable
¶
Count the number of spaces a config line is indented.
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = (
... "interface Ethernet1/1\n"
... " vlan 10\n"
... " no shutdown\n"
... "interface Ethernet1/2\n"
... " shutdown\n"
... )
>>> config_tree = BaseSpaceConfigParser(config)
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line='interface Ethernet1/1', parents=()),
... ConfigLine(config_line=' vlan 10', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line=' no shutdown', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line='interface Ethernet1/2', parents=(),),
... ConfigLine(config_line=' shutdown', parents=('interface Ethernet1/2',))
... ]
True
Source code in netutils/config/parser.py
find_all_children(pattern, match_type='exact')
¶
Returns configuration part for a specific pattern not including parents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
str
|
pattern that describes parent. |
required |
match_type |
optional
|
Exact or regex. Defaults to "exact". |
'exact'
|
Returns:
Type | Description |
---|---|
List[str]
|
configuration under that parent pattern. |
Examples:
>>> config = '''
... router bgp 45000
... address-family ipv4 unicast
... neighbor 192.168.1.2 activate
... network 172.17.1.0 mask'''
>>> bgp_conf = BaseSpaceConfigParser(str(config)).find_all_children(pattern="router bgp", match_type="startswith")
>>> print(bgp_conf)
['router bgp 45000', ' address-family ipv4 unicast', ' neighbor 192.168.1.2 activate', ' network 172.17.1.0 mask']
Source code in netutils/config/parser.py
find_children_w_parents(parent_pattern, child_pattern, match_type='exact')
¶
Returns configuration part for a specific pattern including parents and children.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent_pattern |
str
|
pattern that describes parent. |
required |
child_pattern |
str
|
pattern that describes child. |
required |
match_type |
optional
|
Exact or regex. Defaults to "exact". |
'exact'
|
Returns:
Type | Description |
---|---|
List[str]
|
configuration under that parent pattern. |
Examples:
>>> config = '''
... router bgp 45000
... address-family ipv4 unicast
... neighbor 192.168.1.2 activate
... network 172.17.1.0 mask'''
>>> bgp_conf = BaseSpaceConfigParser(str(config)).find_children_w_parents(parent_pattern="router bgp", child_pattern=" address-family", match_type="regex")
>>> print(bgp_conf)
[' address-family ipv4 unicast', ' neighbor 192.168.1.2 activate', ' network 172.17.1.0 mask']
Source code in netutils/config/parser.py
get_leading_space_count(config_line)
staticmethod
¶
Determine how many spaces the config_line
is indented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_line |
str
|
A line of text in the config. |
required |
Returns:
Type | Description |
---|---|
int
|
The number of leading spaces. |
Examples:
>>> config = '''interface GigabitEthernet1\n description link to ISP'''
>>> config_line = " description link to ISP"
>>> indent_level = BaseSpaceConfigParser(config).get_leading_space_count(config_line)
>>> indent_level
1
>>>
Source code in netutils/config/parser.py
is_banner_end(line)
¶
Determine if line ends the banner config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line |
str
|
The current config line in iteration. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if line ends banner, else False. |
Source code in netutils/config/parser.py
is_banner_start(line)
¶
Determine if the line starts a banner config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line |
str
|
The current config line in iteration. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if line starts banner, else False. |
Source code in netutils/config/parser.py
is_comment(line)
¶
Determine if line is a comment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line |
str
|
A config line from the device. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if line is a comment, else False. |
Examples:
>>> BaseSpaceConfigParser("interface Ethernet1/1").is_comment("interface Ethernet1/1")
False
>>> BaseSpaceConfigParser("!").is_comment("!")
True
>>>
Source code in netutils/config/parser.py
CiscoConfigParser
¶
Bases: BaseSpaceConfigParser
Cisco Implementation of ConfigParser Class.
Source code in netutils/config/parser.py
banner_end: str
property
writable
¶
Demarcate End of Banner char(s).
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
is_banner_one_line(config_line)
staticmethod
¶
Determine if all banner config is on one line.
Source code in netutils/config/parser.py
is_banner_start(line)
¶
Determine if the line starts a banner config.
EOSConfigParser
¶
Bases: BaseSpaceConfigParser
EOSConfigParser implementation fo ConfigParser Class.
Source code in netutils/config/parser.py
F5ConfigParser
¶
Bases: BaseBraceConfigParser
F5ConfigParser implementation for ConfigParser Class.
Source code in netutils/config/parser.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
|
banner_end: str
property
¶
Demarcate End of Banner char(s).
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = '''apm resource webtop-link aShare {
... application-uri http://funshare.example.com
... customization-group a_customization_group
... }
... apm sso form-based portal_ext_sso_form_based {
... form-action /Citrix/Example/ExplicitAuth/LoginAttempt
... form-field "LoginBtn Log+On
... StateContext "
... form-password password
... form-username username
... passthru true
... start-uri /Citrix/Example/ExplicitAuth/Login*
... success-match-type cookie
... success-match-value CtxsAuthId
... }
... '''
>>>
>>> config_tree = F5ConfigParser(config)
>>> print(config_tree.build_config_relationship())
[ConfigLine(config_line='apm resource webtop-link aShare {', parents=()), ConfigLine(config_line=' application-uri http://funshare.example.com', parents=('apm resource webtop-link aShare {',)), ConfigLine(config_line=' customization-group a_customization_group', parents=('apm resource webtop-link aShare {',)), ConfigLine(config_line='}', parents=('apm resource webtop-link aShare {',)), ConfigLine(config_line='apm sso form-based portal_ext_sso_form_based {', parents=()), ConfigLine(config_line=' form-action /Citrix/Example/ExplicitAuth/LoginAttempt', parents=('apm sso form-based portal_ext_sso_form_based {',)), ConfigLine(config_line=' form-field "LoginBtn Log+On\nStateContext "', parents=('apm sso form-based portal_ext_sso_form_based {',)), ConfigLine(config_line=' form-password password', parents=()), ConfigLine(config_line=' form-username username', parents=()), ConfigLine(config_line=' passthru true', parents=()), ConfigLine(config_line=' start-uri /Citrix/Example/ExplicitAuth/Login*', parents=()), ConfigLine(config_line=' success-match-type cookie', parents=()), ConfigLine(config_line=' success-match-value CtxsAuthId', parents=()), ConfigLine(config_line='}', parents=())]
Source code in netutils/config/parser.py
FastironConfigParser
¶
Bases: CiscoConfigParser
Ruckus FastIron ICX config parser.
Source code in netutils/config/parser.py
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
FortinetConfigParser
¶
Bases: BaseSpaceConfigParser
Fortinet Fortios config parser.
Source code in netutils/config/parser.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 |
|
banner_end: str
property
¶
Demarcate End of Banner char(s).
config_lines_only: str
property
¶
Remove spaces and comments from config lines.
Returns:
Type | Description |
---|---|
str
|
The non-space and non-comment lines from |
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
is_end_next(line)
¶
Determine if line has 'end' or 'next' in it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
line |
str
|
A config line from the device. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if line has 'end' or 'next', else False. |
Examples:
>>> FortinetConfigParser("config system virtual-switch").is_end_next("config system virtual-switch")
False
>>> FortinetConfigParser("end").is_end_next("end")
True
>>>
Source code in netutils/config/parser.py
IOSConfigParser
¶
Bases: CiscoConfigParser
, BaseSpaceConfigParser
Cisco IOS implementation of ConfigParser Class.
Source code in netutils/config/parser.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
Source code in netutils/config/parser.py
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = '''
... interface Ethernet1/1
... vlan 10
... no shutdown
... interface Ethernet1/2
... shutdown'''
>>> config_tree = IOSConfigParser(str(config))
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line='interface Ethernet1/1', parents=()),
... ConfigLine(config_line=' vlan 10', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line=' no shutdown', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line='interface Ethernet1/2', parents=()),
... ConfigLine(config_line=' shutdown', parents=('interface Ethernet1/2',))
... ]
True
Source code in netutils/config/parser.py
IOSXRConfigParser
¶
Bases: CiscoConfigParser
IOS-XR config parser.
Source code in netutils/config/parser.py
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 |
|
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
build_config_relationship()
¶
Parse text tree of config lines and their parents.
Examples:
>>> config = (
... "interface Ethernet1/1\n"
... " vlan 10\n"
... " no shutdown"
... "interface Ethernet1/2\n"
... " shutdown\n"
... )
>>> config_tree = IOSXRConfigParser(config)
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line='interface Ethernet1/1', parents=()),
... ConfigLine(config_line=' vlan 10', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line=' no shutdowninterface Ethernet1/2', parents=('interface Ethernet1/1',)),
... ConfigLine(config_line=' shutdown', parents=('interface Ethernet1/1',))
... ]
True
Source code in netutils/config/parser.py
set_delimiter(config_line)
¶
Find delimiter character in banner and set self.delimiter to be it.
Source code in netutils/config/parser.py
JunosConfigParser
¶
Bases: BaseSpaceConfigParser
Junos config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
LINUXConfigParser
¶
Bases: BaseSpaceConfigParser
Linux config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
NXOSConfigParser
¶
Bases: CiscoConfigParser
, BaseSpaceConfigParser
NXOS implementation of ConfigParser Class.
Source code in netutils/config/parser.py
__init__(config)
¶
Create ConfigParser Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
str
|
The config text to parse. |
required |
Source code in netutils/config/parser.py
NetironConfigParser
¶
Bases: BaseSpaceConfigParser
Extreme Netiron config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
NetscalerConfigParser
¶
Bases: BaseSpaceConfigParser
Netscaler config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
NokiaConfigParser
¶
Bases: BaseSpaceConfigParser
Nokia SrOS config parser.
Source code in netutils/config/parser.py
OptiswitchConfigParser
¶
Bases: BaseSpaceConfigParser
MRV Optiswitch config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
PaloAltoNetworksConfigParser
¶
Bases: BaseSpaceConfigParser
Palo Alto Networks config parser.
Source code in netutils/config/parser.py
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
|
build_config_relationship()
¶
Parse text of config lines and find their parents.
Examples:
>>> config = (
... "set deviceconfig system hostname firewall1\n"
... "set deviceconfig system panorama local-panorama panorama-server 10.0.0.1\n"
... "set deviceconfig system panorama local-panorama panorama-server-2 10.0.0.2\n"
... "set deviceconfig setting config rematch yes\n"
... )
>>> config_tree = PaloAltoNetworksConfigParser(config)
>>> config_tree.build_config_relationship() == \
... [
... ConfigLine(config_line="set deviceconfig system hostname firewall1", parents=()),
... ConfigLine(config_line="set deviceconfig system panorama local-panorama panorama-server 10.0.0.1", parents=()),
... ConfigLine(config_line="set deviceconfig system panorama local-panorama panorama-server-2 10.0.0.2", parents=()),
... ConfigLine(config_line="set deviceconfig setting config rematch yes", parents=()),
... ]
True
Source code in netutils/config/parser.py
is_banner_end(line)
¶
Determine if end of banner.
RouterOSConfigParser
¶
Bases: BaseSpaceConfigParser
Mikrotik RouterOS config parser.
Source code in netutils/config/parser.py
banner_end: str
property
¶
Demarcate End of Banner char(s).
UbiquitiAirOSConfigParser
¶
Bases: BaseSpaceConfigParser
Ubiquiti airOS config parser.
Source code in netutils/config/parser.py
utils
¶
Utility functions for working with device configurations.