Skip to content

Commit

Permalink
Merge pull request #1017 from flyingcircusio/PL-132570-fix-altname-qu…
Browse files Browse the repository at this point in the history
…oting

[21.05] lldp-to-altname: fix quoting
  • Loading branch information
osnyx committed Jun 5, 2024
2 parents 2c0e92c + 481449e commit 1e1f690
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pkgs/fc/lldp-to-altname/fc-lldp-to-altname.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import json
import re
import socket
import subprocess
import sys
Expand All @@ -17,6 +18,10 @@ def has_known_prefix(name):
return False


def quote_altname(name):
return re.sub(r"[^a-z0-9A-Z]+", "-", name)


class Runner(object):
def __init__(self, args):
self.quiet = args.quiet
Expand Down Expand Up @@ -72,15 +77,13 @@ def run(self):
for iface in self.interfaces:
oldnames[iface] = set()
data = self.check_json_output("ip", "-j", "link", "show", iface)

for datum in data:
if "altnames" in datum:
names = [
name
for name in datum["altnames"]
if has_known_prefix(name)
]
oldnames[iface].update(names)
names = [
name
for name in datum.get("altnames", [])
if has_known_prefix(name)
]
oldnames[iface].update(names)

lldpnames[iface] = set()
data = self.check_json_output("lldpctl", "-f", "json", iface)
Expand All @@ -90,11 +93,11 @@ def run(self):
and iface in data["interface"]
and "chassis" in data["interface"][iface]
):
switch_name = list(data["interface"][iface]["chassis"].keys())[
0
]
switch_name = list(data["interface"][iface]["chassis"])[0]
port_name = data["interface"][iface]["port"]["id"]["value"]
lldpnames[iface].update([f"{switch_name}-port-{port_name}"])
lldpnames[iface].update(
[quote_altname(f"{switch_name}-port-{port_name}")]
)

newnames = dict()
for iface in self.interfaces:
Expand Down

0 comments on commit 1e1f690

Please sign in to comment.