Skip to content

Commit

Permalink
make sure api is applied to all peers
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Jul 18, 2022
1 parent 51f589e commit 7b99109
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/exabgp/configuration/process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from exabgp.configuration.parser import boolean

API_PREFIX = 'api-internal-cli'


class ParseProcess(Section):
syntax = 'process name-of-process {\n' ' run /path/to/command with its args;\n' ' encoder text|json;\n' '}'
Expand Down Expand Up @@ -71,10 +73,11 @@ def post(self):
def add_api(self):
if not os.environ.get('exabgp_cli_pipe', ''):
return
name = 'api-internal-cli-%x' % uuid.uuid1().fields[0]
name = '%s-%x' % (API_PREFIX, uuid.uuid1().fields[0])
prog = os.path.join(os.environ.get('PWD', ''), sys.argv[0])
api = {
name: {
'run': [sys.executable, os.path.join(os.environ.get('PWD', ''), sys.argv[0])],
'run': [sys.executable, prog],
'encoder': 'text',
'respawn': True,
}
Expand Down
10 changes: 9 additions & 1 deletion src/exabgp/reactor/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from exabgp.reactor.interrupt import Signal

from exabgp.reactor.api import API
from exabgp.configuration.process import API_PREFIX
from exabgp.environment import getenv

from exabgp.bgp.fsm import FSM
Expand Down Expand Up @@ -141,8 +142,15 @@ def established_peers(self):
def peers(self, service=''):
matching = []
for peer_name, peer in self._peers.items():
if service == '' or service in peer.neighbor.api['processes']:
if service == '':
matching.append(peer_name)
continue
if service.startswith(API_PREFIX):
matching.append(peer_name)
continue
if service in peer.neighbor.api['processes']:
matching.append(peer_name)
continue
return matching

def handle_connection(self, peer_name, connection):
Expand Down

0 comments on commit 7b99109

Please sign in to comment.