mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-25 23:24:34 +02:00
fix(controller): make node names from template names valid hostnames
Creating a node from a template whose name has characters invalid in a hostname, such as "MikroTik CCR1072-1G-8S+", failed on the compute with "'MikroTikCCR1072-1G-8S+-1' is an invalid name to create a Qemu node": the template name was only stripped of spaces. Replace the other invalid characters by hyphens, following the rules the compute validates node names with (RFC 1123 for Qemu and Docker, IOS for Dynamips and IOU), as project import already does for existing nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9cf9158ca
commit
dd69a01fba
4 files changed
+69
-1
No files matched your search
@@ -110,3 +110,22 @@ def to_rfc1123_hostname(name: str) -> str:
|
||||
name = name[:253]
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def template_name_to_node_name(name: str, node_type: str) -> str:
|
||||
"""
|
||||
Convert a template name to the base of the names of the nodes created from it.
|
||||
|
||||
Spaces are removed. For the node types whose names the compute validates as
|
||||
hostnames, the other invalid characters (e.g. "+" in a model name) are replaced
|
||||
by hyphens: RFC 1123 for Qemu and Docker, IOS for Dynamips and IOU.
|
||||
"""
|
||||
|
||||
name = name.replace(" ", "")
|
||||
if node_type in ("qemu", "docker"):
|
||||
name = re.sub(r"[^a-zA-Z0-9.-]", "-", name)
|
||||
elif node_type in ("dynamips", "iou"):
|
||||
name = re.sub(r"[^a-zA-Z0-9-]", "-", name)
|
||||
else:
|
||||
return name
|
||||
return name.strip("-.") or node_type
|
||||
Reference in new issue
Block a user