Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Oct 27, 2023
2 parents 612d7ef + 269e34f commit bd1b2a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
- Summary:
- Insert something here

## Version: 1.9.9

- Released: 2023-10-27
- Summary:
- Add more IPv4 / IPv6 address parsing examples in `README.md`

## Version: 1.9.8

- Released: 2023-10-26
Expand Down
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,35 @@ for ccp_obj in parse.find_objects('^interface'):
intf_class = ccp_obj.interface_object.interface_class or ""

##########################################################################
# Extract an IPv4Obj() with re_match_iter_typed()
# Extract all IPv4Obj() with re_match_iter_typed()
##########################################################################
intf_dict = ccp_obj.re_match_iter_typed(
r"ip\s+address\s+(?P<v4addr>\S.+)$",
groupdict={"v4addr": IPv4Obj},
default=None
)
intf_ipv4obj = intf_dict["v4addr"]
for _obj in ccp_obj.children:
# Get a dict() from re_match_iter_typed() by caling it with 'groupdict'
intf_dict = _obj.re_match_iter_typed(
# Add a regex match-group called 'v4addr'
r"ip\s+address\s+(?P<v4addr>\S.+)$",
# Cast the v4addr regex match group as an IPv4Obj() type
groupdict={"v4addr": IPv4Obj},
# Default to None if there is no regex match
default=None
)
intf_ipv4obj = intf_dict["v4addr"]

##########################################################################
# Extract an IPv6Obj() (only EUI-64 portion) with re_match_iter_typed()
# Extract all IPv6Obj() with re_match_iter_typed()
##########################################################################
intf_dict = ccp_obj.re_match_iter_typed(
r"ipv6\s+address\s+(?P<v6addr>\S.+)\s+(eui.64)$",
groupdict={"v6addr": IPv6Obj},
default=None
)
intf_ipv6obj = intf_dict["v6addr"]
for _obj in ccp_obj.children:
# Get a dict() from re_match_iter_typed() by caling it with 'groupdict'
intf_dict = _obj.re_match_iter_typed(
# Add regex match-groups called 'v6addr' and an optional 'ipv6type'
r"ipv6\s+address\s+(?P<v6addr>\S.+)\s*(?P<v6type>eui.64|link.local)*$",
# Cast the v6addr regex match group as an IPv6Obj() type
groupdict={"v6addr": IPv6Obj, "v6type": str},
# Default to None if there is no regex match
default=None
)
intf_ipv6obj = intf_dict["v6addr"]
intf_ipv6type = intf_dict["v6type"]
```

When that is run, you will see information similar to this...
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ requires-python = ">=3.8.0"

[tool.poetry]
name = "ciscoconfparse"
version = "1.9.8"
version = "1.9.9"
description = "Parse, Audit, Query, Build, and Modify Cisco IOS-style and JunOS-style configs"
license = "GPL-3.0-only"
authors = [
Expand Down

0 comments on commit bd1b2a9

Please sign in to comment.