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 5719f5e + 38e4d83 commit 68a2c26
Show file tree
Hide file tree
Showing 11 changed files with 601 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ tags
.tox
.undodir

go.sum
*go.sum
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
- Summary:
- Insert something here

## Version: 1.9.8

- Released: 2023-10-26
- Summary:
- Add IPv4 secondary addresses / networks to `ciscoconfparse/models_cisco.py`
- Update `README.md` example

## Version: 1.9.7

- Released: 2023-10-26
- Summary:
- Fix HSRP decrement parsing
- Fix `README.md` example

## Version: 1.9.6

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ from ciscoconfparse import CiscoConfParse
# standby 110 priority 150
# standby 110 preempt delay minimum 15
# standby 110 track Dialer1 75
# standby 110 track FastEthernet0/1 20
# standby 110 track FastEthernet 0/1
# standby 110 track FastEthernet1/0 30
# standby 111 ip 172.16.2.253
# standby 111 priority 150
Expand Down Expand Up @@ -120,6 +120,12 @@ for ccp_obj in parse.find_objects('^interface'):
# IPv4 netmask object: ipaddress.IPv4Address()
intf_v4masklength = ccp_obj.ipv4_addr_object.masklength

# set() of IPv4 secondary address/prefixlen strings
intf_v4secondary_networks = ccp_obj.ip_secondary_networks

# set() of IPv4 secondary address strings
intf_v4secondary_addresses = ccp_obj.ip_secondary_addresses

# List of HSRP IPv4 addrs from the ciscoconfpasre/models_cisco.py HSRPInterfaceGroup()
intf_hsrp_addresses = [hsrp_grp.ip for hsrp_grp in ccp_obj.hsrp_interfaces]

Expand Down Expand Up @@ -352,10 +358,8 @@ If you already git cloned the repo and want to manually run tests either run wit

```shell
$ cd tests
$ pytest -vvs ./test_CiscoConfParse.py
$ pytest -vvs ./test_*py
...
$ pytest -vvs ./test_Ccp_Util.py
etc...
```

## Editing the Package
Expand Down
68 changes: 60 additions & 8 deletions ciscoconfparse/models_cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class HSRPInterfaceGroup(BaseCfgLine):
# This method is on HSRPInterfaceGroup()
@logger.catch(reraise=True)
def __init__(self, group, parent):
"""A HSRP Interface Group object"""
super().__init__()
self.feature = "hsrp"
self._group = int(group)
Expand Down Expand Up @@ -217,24 +218,28 @@ def __eq__(self, other):
@property
@logger.catch(reraise=True)
def hsrp_group(self):
"""Return the integer HSRP group number for this HSRP group"""
return int(self._group)

# This method is on HSRPInterfaceGroup()
@property
@logger.catch(reraise=True)
def group(self):
"""Return the integer HSRP group number for this HSRP group"""
return self.hsrp_group

# This method is on HSRPInterfaceGroup()
@property
@logger.catch(reraise=True)
def ip(self):
"""Return the string IPv4 HSRP address for this HSRP group"""
return self.ipv4

# This method is on HSRPInterfaceGroup()
@property
@logger.catch(reraise=True)
def ipv4(self):
"""Return the string IPv4 HSRP address for this HSRP group"""
## NOTE: I have no intention of checking self.is_shutdown here
## People should be able to check the sanity of interfaces
## before they put them into production
Expand All @@ -250,6 +255,7 @@ def ipv4(self):
@property
@logger.catch(reraise=True)
def has_ipv6(self):
"""Return a boolean for whether this interface is configured with an IPv6 HSRP address"""
## NOTE: I have no intention of checking self.is_shutdown here
## People should be able to check the sanity of interfaces
## before they put them into production
Expand Down Expand Up @@ -280,23 +286,25 @@ def interface_name(self):
@property
@logger.catch(reraise=True)
def interface_tracking(self):
return self.get_hsrp_tracked_interfaces()
"""Return a list of HSRP TrackingInterface() objects for this HSRPInterfaceGroup()"""
return self.get_hsrp_tracking_interfaces()

# This method is on HSRPInterfaceGroup()
@logger.catch(reraise=True)
def get_glbp_tracked_interfaces(self):
def get_glbp_tracking_interfaces(self):
"""Get a list of unique GLBP tracked interfaces. This may never be supported by HSRPInterfaceGroup()"""
raise NotImplementedError()

# This method is on HSRPInterfaceGroup()
@logger.catch(reraise=True)
def get_vrrp_tracked_interfaces(self):
def get_vrrp_tracking_interfaces(self):
"""Get a list of unique VRRP tracked interfaces. This may never be supported by HSRPInterfaceGroup()"""
raise NotImplementedError()

# This method is on HSRPInterfaceGroup()
@logger.catch(reraise=True)
def get_hsrp_tracked_interfaces(self):
def get_hsrp_tracking_interfaces(self):
"""Return a list of HSRP TrackingInterface() interfaces for this HSRPInterfaceGroup()"""
######################################################################
# Find decrement and interface
######################################################################
Expand Down Expand Up @@ -1290,32 +1298,76 @@ def ipv4_addr_object(self):
logger.warning(f"intf='{self.name}' ipv4_addr='{self.ipv4_addr}' ipv4_netmask='{self.ipv4_netmask}'")
return self.default_ipv4_addr_object

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def has_ip_secondary(self):
r"""Return an boolean for whether this interface has IPv4 secondary addresses"""
retval = self.re_match_iter_typed(
r"^\s*ip\s+address\s+\S+\s+\S+\s+(?P<secondary>secondary)\s*$",
groupdict={"secondary": bool},
default=False
)
return retval["secondary"]

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def ip_secondary_addresses(self):
r"""Return a set of IPv4 secondary addresses (as strings)"""
retval = set()
for obj in self.parent.all_children:
_gg = obj.re_match_iter_typed(
r"^\s*ip\s+address\s+(?P<secondary>\S+\s+\S+)\s+secondary\s*$",
groupdict={"secondary": IPv4Obj},
default=False
)
if _gg["secondary"]:
retval.add(str(_gg["secondary"].ip))
return retval

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def ip_secondary_networks(self):
r"""Return a set of IPv4 secondary addresses / prefixlen"""
retval = set()
for obj in self.parent.all_children:
_gg = obj.re_match_iter_typed(
r"^\s*ip\s+address\s+(?P<secondary>\S+\s+\S+)\s+secondary\s*$",
groupdict={"secondary": IPv4Obj},
default=False
)
if _gg["secondary"]:
retval.add(f"{_gg['secondary'].ip}/{_gg['secondary'].prefixlen}")
return retval

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def has_no_ipv4(self):
r"""Return an ccp_util.IPv4Obj object representing the subnet on this interface; if there is no address, return ccp_util.IPv4Obj('0.0.0.1/32')"""
r"""Return an ccp_util.IPv4Obj object representing the subnet on this interface; if there is no address, return ccp_util.IPv4Obj()"""
return self.ipv4_addr_object == IPv4Obj()

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def ip(self):
r"""Return an ccp_util.IPv4Obj object representing the IPv4 address on this interface; if there is no address, return ccp_util.IPv4Obj('0.0.0.1/32')"""
r"""Return an ccp_util.IPv4Obj object representing the IPv4 address on this interface; if there is no address, return ccp_util.IPv4Obj()"""
return self.ipv4_addr_object

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def ipv4(self):
r"""Return an ccp_util.IPv4Obj object representing the IPv4 address on this interface; if there is no address, return ccp_util.IPv4Obj('0.0.0.1/32')"""
r"""Return an ccp_util.IPv4Obj object representing the IPv4 address on this interface; if there is no address, return ccp_util.IPv4Obj()"""
return self.ipv4_addr_object

# This method is on BaseIOSIntfLine()
@property
@logger.catch(reraise=True)
def ipv4_network_object(self):
r"""Return an ccp_util.IPv4Obj object representing the subnet on this interface; if there is no address, return ccp_util.IPv4Obj('0.0.0.1/32')"""
r"""Return an ccp_util.IPv4Obj object representing the subnet on this interface; if there is no address, return ccp_util.IPv4Obj()"""
return self.ip_network_object

# This method is on BaseIOSIntfLine()
Expand Down
14 changes: 0 additions & 14 deletions dev_tools/deploy_docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ lint:

dep:
@echo "$(COL_GREEN)>> getting deploy_docs dependencies$(COL_END)"
<<<<<<< HEAD
# Remove unused dependencies that may be lingering in go.mod...
go mod tidy
# Get required dependencies...
||||||| b4f0f68
=======
go mod tidy
>>>>>>> develop
go get github.com/melbahja/goph@latest
go get github.com/gleich/logoru@latest
.PHONY: dep
Expand All @@ -119,13 +111,7 @@ backup:
# Delete backups older than 30 days... dont crash if directory is empty
-find ./_bak/*tgz -maxdepth 1 -type f -mtime +30 -delete
# Create a timestamped backup tarball... exclude the _bak directory
<<<<<<< HEAD
tar --exclude=$(GO_BIN_DIR) --exclude=_bak -zcv -f _bak/$(shell date "+%Y%m%d_%H.%M.%S").tgz .
||||||| b4f0f68
tar --exclude=_bak -zcv -f _bak/$(shell date "+%Y%m%d_%H.%M.%S").tgz .
=======
tar --exclude=bin --exclude=_bak -zcv -f _bak/$(shell date "+%Y%m%d_%H.%M.%S").tgz .
>>>>>>> develop
.PHONY: backup

clean:
Expand Down
11 changes: 11 additions & 0 deletions dev_tools/deploy_docs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ require (
github.com/gleich/logoru v0.0.0-20230101033757-d86cd895c7a1
github.com/melbahja/goph v1.4.0
)

require (
github.com/fatih/color v1.10.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect
)
14 changes: 14 additions & 0 deletions dev_tools/deploy_docs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLj
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/gleich/logoru v0.0.0-20230101033757-d86cd895c7a1 h1:KkEP5qFmoabNkkRD+Fz4O3GHDwpsecWoZ2J45Luw3n0=
github.com/gleich/logoru v0.0.0-20230101033757-d86cd895c7a1/go.mod h1:sGBOiXpXj5KPWwXHhzyGJBe4+UC8NpIfQf7pTlTwMYI=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/melbahja/goph v1.3.1 h1:FxFevAwCCpLkM4WBmnVVxcJBcBz6lKQpsN5biV2hA6w=
github.com/melbahja/goph v1.3.1/go.mod h1:uG+VfK2Dlhk+O32zFrRlc3kYKTlV6+BtvPWd/kK7U68=
github.com/melbahja/goph v1.4.0 h1:z0PgDbBFe66lRYl3v5dGb9aFgPy0kotuQ37QOwSQFqs=
github.com/melbahja/goph v1.4.0/go.mod h1:uG+VfK2Dlhk+O32zFrRlc3kYKTlV6+BtvPWd/kK7U68=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go=
Expand Down Expand Up @@ -38,6 +48,9 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -61,4 +74,5 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4 changes: 3 additions & 1 deletion tests/fixtures/configs/sample_08.ios
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ interface ATM0/0.32 point-to-point
interface FastEthernet0/0
description [IPv4 and IPv6 desktop / laptop hosts on 2nd-floor North LAN]
ip address 172.16.2.1 255.255.255.0
ip address 172.16.21.1 255.255.255.0 secondary
ip address 172.16.22.1 255.255.255.0 secondary
ipv6 dhcp server IPV6_2FL_NORTH_LAN
ipv6 address fd01:ab00::/64 eui-64
ipv6 address fe80::1 link-local
Expand All @@ -242,7 +244,7 @@ interface FastEthernet0/0
standby 110 priority 150
standby 110 preempt delay minimum 15
standby 110 track Dialer1 75
standby 110 track FastEthernet0/1 20
standby 110 track FastEthernet 0/1
standby 110 track FastEthernet1/0 30
! ipv4-only HSRP group...
standby 111 ip 172.16.2.253
Expand Down
Loading

0 comments on commit 68a2c26

Please sign in to comment.