mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Return md5sum and filesize in the list of images
Ref https://github.com/GNS3/gns3-gui/issues/1590
This commit is contained in:
10 files changed
+49
-18
No files matched your search
@@ -483,7 +483,9 @@ class BaseManager:
|
||||
path = os.path.relpath(os.path.join(root, filename), img_dir)
|
||||
images.append({
|
||||
"filename": filename,
|
||||
"path": path})
|
||||
"path": path,
|
||||
"md5sum": md5sum(os.path.join(root, filename)),
|
||||
"filesize": os.stat(os.path.join(root, filename)).st_size})
|
||||
return images
|
||||
|
||||
def get_images_directory(self):
|
||||
@@ -507,7 +509,7 @@ class BaseManager:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(tmp_path, 'wb+') as f:
|
||||
while True:
|
||||
packet = yield from stream.read(512)
|
||||
packet = yield from stream.read(4096)
|
||||
if not packet:
|
||||
break
|
||||
f.write(packet)
|
||||
|
||||
@@ -33,6 +33,7 @@ import glob
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from gns3server.utils.interfaces import interfaces, is_interface_up
|
||||
from gns3server.utils.images import md5sum
|
||||
from gns3server.utils.asyncio import wait_run_in_executor
|
||||
from gns3server.utils import parse_version
|
||||
from uuid import UUID, uuid4
|
||||
@@ -712,6 +713,9 @@ class Dynamips(BaseManager):
|
||||
continue
|
||||
# valid IOS images must start with the ELF magic number, be 32-bit, big endian and have an ELF version of 1
|
||||
if elf_header_start == b'\x7fELF\x01\x02\x01':
|
||||
path = os.path.relpath(path, image_dir)
|
||||
images.append({"filename": filename, "path": path})
|
||||
images.append({"filename": filename,
|
||||
"path": os.path.relpath(path, image_dir),
|
||||
"md5sum": md5sum(path),
|
||||
"filesize": os.stat(path).st_size
|
||||
})
|
||||
return images
|
||||
@@ -26,7 +26,7 @@ import os
|
||||
import io
|
||||
|
||||
from ..utils import parse_version
|
||||
from ..utils.images import scan_for_images
|
||||
from ..utils.images import scan_for_images, md5sum
|
||||
from ..controller.controller_error import ControllerError
|
||||
from ..config import Config
|
||||
from ..version import __version__
|
||||
@@ -446,7 +446,7 @@ class Compute:
|
||||
|
||||
def send_data(f):
|
||||
while True:
|
||||
chunk = f.read(1024)
|
||||
chunk = f.read(4096)
|
||||
if not chunk:
|
||||
break
|
||||
yield chunk
|
||||
@@ -543,7 +543,11 @@ class Compute:
|
||||
for path in scan_for_images(type):
|
||||
image = os.path.basename(path)
|
||||
if image not in [i['filename'] for i in images]:
|
||||
images.append({"filename": image, "path": image})
|
||||
images.append({"filename": image,
|
||||
"path": image,
|
||||
"md5sum": md5sum(path),
|
||||
"filesize": os.stat(path).st_size
|
||||
})
|
||||
return images
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -53,6 +53,16 @@ NODE_LIST_IMAGES_SCHEMA = {
|
||||
"description": "Image path",
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"md5sum": {
|
||||
"description": "md5sum of the image if available",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1
|
||||
},
|
||||
"filesize": {
|
||||
"description": "size of the image if available",
|
||||
"type": ["integer", "null"],
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
"required": ["filename", "path"],
|
||||
|
||||
@@ -92,7 +92,9 @@ def md5sum(path):
|
||||
|
||||
try:
|
||||
with open(path + '.md5sum') as f:
|
||||
return f.read()
|
||||
md5 = f.read()
|
||||
if len(md5) == 32:
|
||||
return md5
|
||||
# Unicode error is when user rename an image to .md5sum ....
|
||||
except (OSError, UnicodeDecodeError):
|
||||
pass
|
||||
|
||||
Reference in new issue
Block a user