mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Raise an error if image is missing on compute
This commit is contained in:
23 files changed
+108
-108
No files matched your search
@@ -39,7 +39,7 @@ from .nios.nio_udp import NIOUDP
|
||||
from .nios.nio_tap import NIOTAP
|
||||
from .nios.nio_ethernet import NIOEthernet
|
||||
from ..utils.images import md5sum, remove_checksum
|
||||
from .node_error import NodeError
|
||||
from .error import NodeError, ImageMissingError
|
||||
|
||||
|
||||
class BaseManager:
|
||||
@@ -432,18 +432,27 @@ class BaseManager:
|
||||
path = self._recursive_search_file_in_directory(directory, orig_path)
|
||||
if path:
|
||||
return force_unix_path(path)
|
||||
# Not found we return the default directory
|
||||
|
||||
# Not found we try the default directory
|
||||
s = os.path.split(orig_path)
|
||||
return force_unix_path(os.path.join(self.get_images_directory(), *s))
|
||||
path = force_unix_path(os.path.join(self.get_images_directory(), *s))
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
raise ImageMissingError(path)
|
||||
|
||||
# For non local server we disallow using absolute path outside image directory
|
||||
if server_config.get("local", False) is True:
|
||||
return force_unix_path(path)
|
||||
path = force_unix_path(path)
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
raise ImageMissingError(path)
|
||||
|
||||
path = force_unix_path(path)
|
||||
for directory in self.images_directories():
|
||||
if os.path.commonprefix([directory, path]) == directory:
|
||||
return path
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
raise ImageMissingError(path)
|
||||
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, self.get_images_directory()))
|
||||
|
||||
def _recursive_search_file_in_directory(self, directory, searched_file):
|
||||
|
||||
@@ -28,7 +28,7 @@ import platform
|
||||
from ..utils.asyncio import wait_run_in_executor
|
||||
from ..ubridge.hypervisor import Hypervisor
|
||||
from ..ubridge.ubridge_error import UbridgeError
|
||||
from .node_error import NodeError
|
||||
from .error import NodeError
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
from .nodes.cloud import Cloud
|
||||
from .nodes.ethernet_hub import EthernetHub
|
||||
from .nodes.ethernet_switch import EthernetSwitch
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
import sys
|
||||
import asyncio
|
||||
|
||||
from ...node_error import NodeError
|
||||
from ...error import NodeError
|
||||
from ...base_node import BaseNode
|
||||
from ...nios.nio_udp import NIOUDP
|
||||
|
||||
@@ -181,7 +181,6 @@ class Cloud(BaseNode):
|
||||
yield from self._ubridge_send('bridge start_capture {name} "{pcap_file}"'.format(name=bridge_name,
|
||||
pcap_file=nio.pcap_output_file))
|
||||
|
||||
|
||||
yield from self._ubridge_send('bridge start {name}'.format(name=bridge_name))
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -269,7 +268,6 @@ class Cloud(BaseNode):
|
||||
id=self.id,
|
||||
port_number=port_number))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, port_number):
|
||||
"""
|
||||
@@ -291,5 +289,5 @@ class Cloud(BaseNode):
|
||||
yield from self._ubridge_send("bridge stop_capture {name}".format(name=bridge_name))
|
||||
|
||||
log.info("Cloud'{name}' [{id}]: stopping packet capture on port {port_number}".format(name=self.name,
|
||||
id=self.id,
|
||||
port_number=port_number))
|
||||
id=self.id,
|
||||
port_number=port_number))
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from ...node_error import NodeError
|
||||
from ...error import NodeError
|
||||
from ...base_node import BaseNode
|
||||
|
||||
import logging
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from ...node_error import NodeError
|
||||
from ...error import NodeError
|
||||
from ...base_node import BaseNode
|
||||
|
||||
import logging
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the Docker module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class DockerError(NodeError):
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the Dynamips module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class DynamipsError(NodeError):
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
class NodeError(Exception):
|
||||
|
||||
def __init__(self, message, original_exception=None):
|
||||
|
||||
super().__init__(message)
|
||||
if isinstance(message, Exception):
|
||||
message = str(message)
|
||||
@@ -27,9 +26,16 @@ class NodeError(Exception):
|
||||
self._original_exception = original_exception
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
return self._message
|
||||
|
||||
def __str__(self):
|
||||
|
||||
return self._message
|
||||
|
||||
|
||||
class ImageMissingError(Exception):
|
||||
"""
|
||||
Raised when an image is missing
|
||||
"""
|
||||
|
||||
def __init__(self, image):
|
||||
super().__init__("The image {} is missing".format(image))
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the IOU module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class IOUError(NodeError):
|
||||
|
||||
@@ -91,6 +91,9 @@ class IOUVM(BaseNode):
|
||||
self._ram = 256 # Megabytes
|
||||
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
|
||||
|
||||
def _config(self):
|
||||
return self._manager.config.get_section_config("IOU")
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
"""
|
||||
@@ -129,15 +132,6 @@ class IOUVM(BaseNode):
|
||||
|
||||
self._path = self.manager.get_abs_image_path(path)
|
||||
|
||||
# In 1.2 users uploaded images to the images roots
|
||||
# after the migration their images are inside images/IOU
|
||||
# but old topologies use old path
|
||||
if "IOU" not in self._path:
|
||||
location, filename = os.path.split(self._path)
|
||||
fix_path = os.path.join(location, "IOU", filename)
|
||||
if os.path.isfile(fix_path):
|
||||
self._path = fix_path
|
||||
|
||||
@property
|
||||
def use_default_iou_values(self):
|
||||
"""
|
||||
@@ -232,7 +226,7 @@ class IOUVM(BaseNode):
|
||||
:returns: path to IOUYAP
|
||||
"""
|
||||
|
||||
path = self._manager.config.get_section_config("IOU").get("iouyap_path", "iouyap")
|
||||
path = self._config().get("iouyap_path", "iouyap")
|
||||
if path == "iouyap":
|
||||
path = shutil.which("iouyap")
|
||||
return path
|
||||
@@ -245,7 +239,7 @@ class IOUVM(BaseNode):
|
||||
:returns: path to IOURC
|
||||
"""
|
||||
|
||||
iourc_path = self._manager.config.get_section_config("IOU").get("iourc_path")
|
||||
iourc_path = self._config().get("iourc_path")
|
||||
if not iourc_path:
|
||||
# look for the iourc file in the user home dir.
|
||||
path = os.path.join(os.path.expanduser("~/"), ".iourc")
|
||||
@@ -380,7 +374,7 @@ class IOUVM(BaseNode):
|
||||
Checks for a valid IOU key in the iourc file (paranoid mode).
|
||||
"""
|
||||
|
||||
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", True)
|
||||
license_check = self._config().getboolean("license_check", True)
|
||||
if license_check is False:
|
||||
return
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the Qemu module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class QemuError(NodeError):
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the VirtualBox module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class VirtualBoxError(NodeError):
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the VMware module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class VMwareError(NodeError):
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Custom exceptions for the VPCS module.
|
||||
"""
|
||||
|
||||
from ..node_error import NodeError
|
||||
from ..error import NodeError
|
||||
|
||||
|
||||
class VPCSError(NodeError):
|
||||
|
||||
Reference in new issue
Block a user