From 6a9180411611a5c53dceaaebdfd85b81dd6da632 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 22 Feb 2017 18:01:59 +0100 Subject: [PATCH] Catch error when you provide an invalid port name formating Fix #909 --- gns3server/controller/ports/port_factory.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index e0174564..bc4d509b 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import aiohttp + from .atm_port import ATMPort from .frame_relay_port import FrameRelayPort from .gigabitethernet_port import GigabitEthernetPort @@ -64,11 +66,14 @@ class StandardPortFactory: port_name = first_port_name port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet") else: - port_name = port_name_format.format( - interface_number, - segment_number, - adapter=adapter_number, - **cls._generate_replacement(interface_number, segment_number)) + try: + port_name = port_name_format.format( + interface_number, + segment_number, + adapter=adapter_number, + **cls._generate_replacement(interface_number, segment_number)) + except (ValueError, KeyError) as e: + raise aiohttp.web.HTTPConflict(text="Invalid port name format {}: {}".format(port_name_format, str(e))) port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet") interface_number += 1 if port_segment_size: