Skip to content

Commit

Permalink
Allow custom path to vtysh in FRRoutingPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
SRv6d committed Oct 5, 2023
1 parent 6b69891 commit fab9d2e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/anycastd/prefix/frrouting.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import asyncio
import ipaddress
import json
import subprocess
from contextlib import suppress
from ipaddress import IPv4Network, IPv6Network
from pathlib import Path

from anycastd.prefix.base import BasePrefix

VTYSH_BIN = "/usr/bin/vtysh"


class FRRoutingPrefix(BasePrefix):
vtysh: Path

def __init__(
self, prefix: IPv4Network | IPv6Network, *, vtysh: Path = Path("/usr/bin/vtysh")
):
super().__init__(prefix)
self.vtysh = vtysh

async def is_announced(self) -> bool:
"""Returns True if the prefix is announced.
Expand Down Expand Up @@ -83,7 +90,7 @@ async def _run_vtysh_commands(self, commands: tuple[str, ...]) -> str:
RuntimeError: The command exited with a non-zero exit code.
"""
proc = await asyncio.create_subprocess_exec(
VTYSH_BIN, "-c", *commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE
self.vtysh, "-c", *commands, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)

stdout, stderr = await proc.communicate()
Expand All @@ -101,4 +108,4 @@ async def _run_vtysh_commands(self, commands: tuple[str, ...]) -> str:

def get_afi(prefix: BasePrefix) -> str:
"""Return the FRR string AFI for the given IP type."""
return "ipv6" if not isinstance(prefix.prefix, ipaddress.IPv4Network) else "ipv4"
return "ipv6" if not isinstance(prefix.prefix, IPv4Network) else "ipv4"

0 comments on commit fab9d2e

Please sign in to comment.