Raise an error if server flagged as local but should not

If the controller is not started with --local but the server ID
is local it's raise an error.
This commit is contained in:
Julien Duponchelle committed 2016-03-04 16:11:31 +01:00
1 parent aad69e9650
commit 4d77b2918e
5 files changed
+68 -13

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class ControllerError(Exception):
def __init__(self, message):
super().__init__(message)
self._message = message
def __repr__(self):
return self._message
def __str__(self):
return self._message
+14 -4
View File
@@ -16,6 +16,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ..controller.controller_error import ControllerError
from ..config import Config
class ServerError(ControllerError):
pass
class Server:
"""
A GNS3 server.
@@ -32,6 +40,11 @@ class Server:
# The remote server version
self._version = None
# If the server is local but the server id is local
# it's a configuration issue
if server_id == "local" and Config.instance().get_section_config("Server")["local"] is False:
raise ServerError("The local server is started without --local")
@property
def id(self):
"""
@@ -57,7 +70,4 @@ class Server:
"version": self._version
}
def __eq__(self, other):
if not isinstance(other, Server):
return False
return other._id == self._id
+1 -1
View File
@@ -20,7 +20,7 @@ class VMError(Exception):
def __init__(self, message, original_exception=None):
Exception.__init__(self, message)
super().__init__(message)
if isinstance(message, Exception):
message = str(message)
self._message = message
+6
View File
@@ -26,6 +26,7 @@ import traceback
log = logging.getLogger(__name__)
from ..modules.vm_error import VMError
from ..controller.controller_error import ControllerError
from ..ubridge.ubridge_error import UbridgeError
from .response import Response
from ..crash_report import CrashReport
@@ -185,6 +186,11 @@ class Route(object):
response = Response(request=request, route=route)
response.set_status(e.status)
response.json({"message": e.text, "status": e.status})
except (ControllerError) as e:
log.error("Controller error detected: {type}".format(type=type(e)), exc_info=1)
response = Response(request=request, route=route)
response.set_status(409)
response.json({"message": str(e), "status": 409})
except (VMError, UbridgeError) as e:
log.error("VM error detected: {type}".format(type=type(e)), exc_info=1)
response = Response(request=request, route=route)