Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
cmdOut: List[Dict] = ctx.runDeviceCmds(["enable", "show ip bgp summary vrf all"])
errs: List[str] = [resp.get('error') for resp in cmdOut if resp.get('error')]
if errs:
raise ActionFailed(f"Unable to get BGP summary, failed with: {errs[0]}")
raise ActionFailed(f"Unable to get IPv4 BGP summary, failed with: {errs[0]}")
bgpSummary = cmdOut[1]["response"]

cmdOut: List[Dict] = ctx.runDeviceCmds(["enable", "show ipv6 bgp summary vrf all"])
errs: List[str] = [resp.get('error') for resp in cmdOut if resp.get('error')]
if errs:
raise ActionFailed(f"Unable to get IPv6 BGP summary, failed with: {errs[0]}")
bgpv6Summary = cmdOut[1]["response"]

checkEvpn = True
cmdOut: List[Dict] = ctx.runDeviceCmds(["enable", "show bgp evpn summary"])
errs: List[str] = [resp.get('error') for resp in cmdOut if resp.get('error')]
Expand All @@ -46,23 +52,25 @@
if pendingPeersVrfList:
bgpASN = None
for vrf in pendingPeersVrfList:
for peer in bgpSummary['vrfs'][vrf]['peers']:
for peer, peerSummary in tuple(bgpSummary['vrfs'][vrf]['peers'].items()) + tuple(bgpv6Summary['vrfs'][vrf]['peers'].items()):
# Check to see that the reason the the peer state is
# pending is not due to administrative action
if (
bgpSummary['vrfs'][vrf]['peers'][peer]['peerState'] != "Established"
peerSummary['peerState'] != "Established"
and not (
bgpSummary['vrfs'][vrf]['peers'][peer]['peerState'] == "Idle"
and bgpSummary['vrfs'][vrf]['peers'][peer]['peerStateIdleReason'] == "Admin"
peerSummary['peerState'] == "Idle"
and peerSummary['peerStateIdleReason'] == "Admin"
)
):
shutdownBgpPeerList.append((vrf, peer))
bgpASN = bgpSummary['vrfs'][vrf]['asn']
if ":" in peer:
bgpASN = bgpv6Summary['vrfs'][vrf]['asn']
else:
bgpASN = bgpSummary['vrfs'][vrf]['asn']
if checkEvpn:
bgpEvpnSummary = cmdOut[1]["response"]
# Check the peer EVPN status for the default vrf
for peer in bgpEvpnSummary['vrfs']['default']['peers']:
peerSummary = bgpEvpnSummary['vrfs']['default']['peers'][peer]
for peer, peerSummary in bgpEvpnSummary['vrfs']['default']['peers'].items():
if (
peerSummary['peerState'] != "Established"
and not (
Expand Down Expand Up @@ -108,6 +116,6 @@
if errs:
raise ActionFailed(f"Failed to shut down all peers with: {errs[0]}")

ctx.info("Inactive BGP peers successfully shutdown")
ctx.info(f"Inactive BGP peers successfully shutdown: {shutdownBgpPeerList}")
else:
ctx.info("No inactive BGP peers to shutdown")