Skip to content

Commit

Permalink
sanitize port name according to the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Italo Valcy committed Nov 18, 2024
1 parent 899b96d commit 953a419
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions convert_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ def get_port(self, sdx_node_name: str, interface: dict) -> dict:

sdx_port = {}
sdx_port["id"] = self.get_port_urn(interface)
sdx_port["name"] = interface["metadata"].get("port_name", "")[:30]
if not sdx_port["name"]:
if interface["metadata"].get("port_name"):
port_name = interface["metadata"]["port_name"]
port_name = re.sub(r"\s+", "_", port_name)
port_name = re.sub("[^A-Za-z0-9_.,/-]", "", port_name)
sdx_port["name"] = port_name[:30]
else:
sdx_port["name"] = interface["name"][:30]
sdx_port["node"] = f"urn:sdx:node:{self.oxp_url}:{sdx_node_name}"
sdx_port["type"] = self.get_type_port_speed(str(interface["speed"]))
Expand Down

0 comments on commit 953a419

Please sign in to comment.