mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Test all IOU requirements at VM startup
This allow user to create the node and upload the image after
This commit is contained in:
1 parent
5c4a49a8c7
commit
4aadfa3b67
2 files changed
+27
-23
No files matched your search
@@ -142,27 +142,6 @@ class IOUVM(BaseVM):
|
||||
if os.path.isfile(fix_path):
|
||||
self._path = fix_path
|
||||
|
||||
if not os.path.isfile(self._path) or not os.path.exists(self._path):
|
||||
if os.path.islink(self._path):
|
||||
raise IOUError("IOU image '{}' linked to '{}' is not accessible".format(self._path, os.path.realpath(self._path)))
|
||||
else:
|
||||
raise IOUError("IOU image '{}' is not accessible".format(self._path))
|
||||
|
||||
try:
|
||||
with open(self._path, "rb") as f:
|
||||
# read the first 7 bytes of the file.
|
||||
elf_header_start = f.read(7)
|
||||
except OSError as e:
|
||||
raise IOUError("Cannot read ELF header for IOU image '{}': {}".format(self._path, e))
|
||||
|
||||
# IOU images must start with the ELF magic number, be 32-bit, little endian
|
||||
# and have an ELF version of 1 normal IOS image are big endian!
|
||||
if elf_header_start != b'\x7fELF\x01\x01\x01':
|
||||
raise IOUError("'{}' is not a valid IOU image".format(self._path))
|
||||
|
||||
if not os.access(self._path, os.X_OK):
|
||||
raise IOUError("IOU image '{}' is not executable".format(self._path))
|
||||
|
||||
@property
|
||||
def use_default_iou_values(self):
|
||||
"""
|
||||
@@ -189,9 +168,30 @@ class IOUVM(BaseVM):
|
||||
|
||||
def _check_requirements(self):
|
||||
"""
|
||||
Checks if IOUYAP executable is available.
|
||||
Checks if IOUYAP executable is available and if image is accessible.
|
||||
"""
|
||||
|
||||
if not os.path.isfile(self._path) or not os.path.exists(self._path):
|
||||
if os.path.islink(self._path):
|
||||
raise IOUError("IOU image '{}' linked to '{}' is not accessible".format(self._path, os.path.realpath(self._path)))
|
||||
else:
|
||||
raise IOUError("IOU image '{}' is not accessible".format(self._path))
|
||||
|
||||
try:
|
||||
with open(self._path, "rb") as f:
|
||||
# read the first 7 bytes of the file.
|
||||
elf_header_start = f.read(7)
|
||||
except OSError as e:
|
||||
raise IOUError("Cannot read ELF header for IOU image '{}': {}".format(self._path, e))
|
||||
|
||||
# IOU images must start with the ELF magic number, be 32-bit, little endian
|
||||
# and have an ELF version of 1 normal IOS image are big endian!
|
||||
if elf_header_start != b'\x7fELF\x01\x01\x01':
|
||||
raise IOUError("'{}' is not a valid IOU image".format(self._path))
|
||||
|
||||
if not os.access(self._path, os.X_OK):
|
||||
raise IOUError("IOU image '{}' is not executable".format(self._path))
|
||||
|
||||
path = self.iouyap_path
|
||||
if not path:
|
||||
raise IOUError("No path to iouyap program has been set")
|
||||
|
||||
Reference in new issue
Block a user