From efae614af24f43a676f3f62facd4c7777ed7f080 Mon Sep 17 00:00:00 2001 From: ziajka Date: Mon, 21 Aug 2017 11:03:23 +0200 Subject: [PATCH] Added checking if NIO exists (Fixes #1160) --- gns3server/handlers/api/compute/cloud_handler.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gns3server/handlers/api/compute/cloud_handler.py b/gns3server/handlers/api/compute/cloud_handler.py index bcba2c6f..f8ef826c 100644 --- a/gns3server/handlers/api/compute/cloud_handler.py +++ b/gns3server/handlers/api/compute/cloud_handler.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import os +from aiohttp.web import HTTPConflict from gns3server.web.route import Route from gns3server.schemas.node import NODE_CAPTURE_SCHEMA @@ -219,7 +220,13 @@ class CloudHandler: builtin_manager = Builtin.instance() node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) - nio = node.nios[int(request.match_info["adapter_number"])] + adapter_number = int(request.match_info["adapter_number"]) + + try: + nio = node.nios[adapter_number] + except KeyError: + raise HTTPConflict(text="NIO `{}` doesn't exist".format(adapter_number)) + if "filters" in request.json and nio: nio.filters = request.json["filters"] yield from node.update_nio(int(request.match_info["port_number"]), nio)