From 728f092a13387938a860526f7d9f789e28738898 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Wed, 2 Sep 2015 12:10:31 +0200 Subject: [PATCH] Add filesize for images Fix #8 --- appliances/arista-veos.json | 4 +++- appliances/cisco-asav.json | 2 ++ appliances/cumulus-vx.json | 1 + appliances/hp-vsr1001.json | 1 + appliances/microcore-linux.json | 2 ++ appliances/openwrt-realview.json | 1 + appliances/ostinato.json | 3 ++- build.py | 9 +++++++++ schemas/appliance.json | 5 +++++ templates/appliance.html | 8 ++++++++ templates/downloads.html | 7 ------- templates/layout/default.html | 7 +++++++ templates/myimages.html | 3 ++- 13 files changed, 43 insertions(+), 10 deletions(-) diff --git a/appliances/arista-veos.json b/appliances/arista-veos.json index df690f0..9685d18 100644 --- a/appliances/arista-veos.json +++ b/appliances/arista-veos.json @@ -8,7 +8,7 @@ "product_name": "vEOS", "product_url": "https://eos.arista.com/", "registry_version": 1, - "status": "stable", + "status": "experimental", "maintainer": "GNS3 Team", "maintainer_email": "developers@gns3.net", @@ -24,6 +24,7 @@ { "filename": "Aboot-veos-serial-2.1.0.iso", "version": "2.1.0", + "filesize": 5242880, "md5sum": "2687534f2ff11b998dec0511066457c0", "download_url": "https://www.arista.com/en/support/software-download" }, @@ -31,6 +32,7 @@ "filename": "vEOS-lab-4.13.8M.vmdk", "version": "4.13.8M", "md5sum": "a47145b9e6e7a24171c0850f8755535e", + "filesize": 409010176, "download_url": "https://www.arista.com/en/support/software-download" } ], diff --git a/appliances/cisco-asav.json b/appliances/cisco-asav.json index e15e22d..a915de1 100644 --- a/appliances/cisco-asav.json +++ b/appliances/cisco-asav.json @@ -25,12 +25,14 @@ { "filename": "asav941-202.qcow2", "version": "9.4.1-202", + "filesize": 155713536, "md5sum": "6992d2a35d5682a99b124b5eaf5c603a", "download_url": "N/A" }, { "filename": "asav932-200.qcow2", "version": "9.3.2-200", + "filesize": 150208512, "md5sum": "bcf3a9a4735a195fb70599637936ab38", "download_url": "N/A" } diff --git a/appliances/cumulus-vx.json b/appliances/cumulus-vx.json index d9f2283..7d806a2 100644 --- a/appliances/cumulus-vx.json +++ b/appliances/cumulus-vx.json @@ -28,6 +28,7 @@ { "filename": "CumulusVX-2.5.3-4eb681f3df86c478.qcow2", "version": "2.5.3", + "filesize": 1040973824, "md5sum": "5128aec2568991ea0586293cb85f7a97", "download_url": "https://cumulusnetworks.com/cumulus-vx/download/thanks/kvm/" } diff --git a/appliances/hp-vsr1001.json b/appliances/hp-vsr1001.json index 1460312..cc9013f 100644 --- a/appliances/hp-vsr1001.json +++ b/appliances/hp-vsr1001.json @@ -25,6 +25,7 @@ "filename": "VSR1000_HP-CMW710-R0204P01-X64.iso", "version": "7.10.R0204P01", "md5sum": "d0b539f3ba9723ad8c3ed46f6d772627", + "filesize": 236687360, "download_url": "https://h10145.www1.hp.com/Downloads/DownloadSoftware.aspx?SoftwareReleaseUId=11832&ProductNumber=JG811AAE&lang=en&cc=us&prodSeriesId=5443163&OrderNumber=&PurchaseDate=" } ], diff --git a/appliances/microcore-linux.json b/appliances/microcore-linux.json index b09cd9e..8c76a92 100644 --- a/appliances/microcore-linux.json +++ b/appliances/microcore-linux.json @@ -25,6 +25,7 @@ "filename": "linux-microcore-3.4.1.img", "version": "3.4.1", "md5sum": "fa2ec4b1fffad67d8103c3391bbf9df2", + "filesize": 24969216, "download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/", "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/linux-microcore-3.4.1.img" }, @@ -32,6 +33,7 @@ "filename": "linux-microcore-4.0.2-clean.img", "version": "4.0.2", "md5sum": "e13d0d1c0b3999ae2386bba70417930c", + "filesize": 26411008, "download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/", "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/linux-microcore-4.0.2-clean.img" } diff --git a/appliances/openwrt-realview.json b/appliances/openwrt-realview.json index 1bf970d..124f5b0 100644 --- a/appliances/openwrt-realview.json +++ b/appliances/openwrt-realview.json @@ -26,6 +26,7 @@ "filename": "openwrt-realview-vmlinux-initramfs-14.07.elf", "version": "14.07", "md5sum": "2411307d0794baa618537c5dfcb19575", + "filesize": 2183520, "download_url": "http://downloads.openwrt.org/barrier_breaker/14.07/realview/generic/", "direct_download_url": "http://downloads.openwrt.org/barrier_breaker/14.07/realview/generic/openwrt-realview-vmlinux-initramfs.elf" } diff --git a/appliances/ostinato.json b/appliances/ostinato.json index a12005e..6a4eeee 100644 --- a/appliances/ostinato.json +++ b/appliances/ostinato.json @@ -8,7 +8,7 @@ "product_name": "Drone", "product_url": "http://ostinato.org/", "registry_version": 1, - "status": "stable", + "status": "experimental", "maintainer": "Bernhard Ehler", "maintainer_email": "be@bernhard-ehlers.de", "usage": "The traffic generator listen on port 50001.\n Use the Ostinato GUI to control it. If you want to use two traffic geneator at the same time you need to modify the port in the VM Qemu options.\nThe drone VM and the Ostinato GUI must use the same version.", @@ -27,6 +27,7 @@ "filename": "ost-drone-0.7-v1.qcow2", "version": "0.7", "md5sum": "6c20f767f89782e66929e6cbb7143ab1", + "filesize": 18415616, "download_url": "http://www.bernhard-ehlers.de/projects/ostinato4gns3/install-qemu.html", "direct_download_url": "http://www.bernhard-ehlers.de/projects/ostinato4gns3/ost-drone-0.7-v1.qcow2" } diff --git a/build.py b/build.py index de58210..779e766 100644 --- a/build.py +++ b/build.py @@ -48,12 +48,21 @@ os.mkdir(os.path.join('build', 'appliances')) os.mkdir(os.path.join('build', 'images')) +def human_filesize(num): + for unit in ['B','KB','MB','GB']: + if abs(num) < 1024.0: + return "%3.1f%s" % (num, unit) + num /= 1024.0 + return "%.1f%s" % (num, 'TB') + + def render(template_file, out, **kwargs): log.info('Build %s', out) env = Environment(loader=FileSystemLoader('templates')) env.filters['nl2br'] = lambda s: s.replace('\n', '
') env.filters['jsonify'] = json.dumps env.filters['b64encode'] = lambda s: base64.b64encode(s.encode()).decode("utf-8") + env.filters['human_filesize'] = human_filesize template = env.get_template(template_file) template.stream(**kwargs).dump(os.path.join('build', out)) diff --git a/schemas/appliance.json b/schemas/appliance.json index d4434fd..170619d 100644 --- a/schemas/appliance.json +++ b/schemas/appliance.json @@ -138,6 +138,10 @@ "format": "md5", "title": "md5sum of the file" }, + "filesize": { + "type": "integer", + "title": "File size in bytes" + }, "download_url": { "type": "string", "format": "uri", @@ -153,6 +157,7 @@ "filename", "version", "md5sum", + "filesize", "download_url" ] } diff --git a/templates/appliance.html b/templates/appliance.html index 8b0c1f6..eb65f97 100644 --- a/templates/appliance.html +++ b/templates/appliance.html @@ -23,6 +23,13 @@ function download(appliance, md5sum) { This appliance is actually not working {% endif %} + {% if appliance["status"] == "experimental" %} + + {% endif %}

{{ appliance["name"] }}

Category {{ appliance["category"] }}
Product: {{ appliance["product_name"] }}
@@ -55,6 +62,7 @@ function download(appliance, md5sum) {

{{image["filename"]}}

Slot: {{image["type"]}}
File Version: {{image["version"]}}
+ Size: {{ image["filesize"] | human_filesize}}
Checksum: {{image["md5sum"]}}
Download url: {{image["download_url"]}}
{% if "direct_download_url" in image %} diff --git a/templates/downloads.html b/templates/downloads.html index 5158001..0fb7957 100644 --- a/templates/downloads.html +++ b/templates/downloads.html @@ -1,13 +1,6 @@ {% extends "layout/default.html" %} {% block script %} -function humanFileSize(bytes) { - var exp = Math.log(bytes) / Math.log(1024) | 0; - var result = (bytes / Math.pow(1024, exp)).toFixed(2); - - return result + ' ' + (exp == 0 ? 'bytes': 'KMGTPEZY'[exp - 1] + 'B'); -} - function update_progress_download_div(div, download_info) { var percent = Math.round(100 / download_info.total * download_info.received) div.text(percent + "% "+ humanFileSize(download_info.received) + " / " + humanFileSize(download_info.total)); diff --git a/templates/layout/default.html b/templates/layout/default.html index 9aa0a2e..70e8bc6 100644 --- a/templates/layout/default.html +++ b/templates/layout/default.html @@ -52,6 +52,13 @@ return false; } } + + function humanFileSize(bytes) { + var exp = Math.log(bytes) / Math.log(1024) | 0; + var result = (bytes / Math.pow(1024, exp)).toFixed(2); + + return result + ' ' + (exp == 0 ? 'bytes': 'KMGTPEZY'[exp - 1] + 'B'); + }