Add a JSON schema to the registry

Fix #6
This commit is contained in:
Julien Duponchelle 2015-09-02 11:21:50 +02:00
parent 97dd30fb6b
commit c9c960c639
11 changed files with 312 additions and 16 deletions

View File

@ -4,25 +4,48 @@ GNS3-registry
This is the GNS3 registry.
Add a new appliance
###################
Copy paste a JSON from the appliances directory and send a pull request.
In schemas/appliance.json you have a JSON with a schema for controlling the file.
Tools
#######
All tools require python3 and the installation of dependencies via:
.. code:: bash
pip3 install -r requirements.txt
Build website
#############
--------------
.. code:: bash
python build.py
python3 build.py
Run website
#############
-------------
.. code:: bash
python server.py
python3 server.py
Check appliance files
-----------------------
.. code:: bash
python3 check.py

View File

@ -11,7 +11,8 @@
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
"symbol": ":/symbols/asa.svg",
"qemu": {
"adapter_type": "e1000",
"adapters": 8,

View File

@ -1,13 +1,13 @@
{
"name": "Cumulus VX",
"category": "router",
"category": "multilayer_switch",
"description": "Cumulus VX is a community-supported virtual appliance that enables cloud admins and network engineers to preview and test Cumulus Networks technology at zero cost. You can build sandbox environments to learn Open Networking concepts, prototype network operations and script & develop applications risk-free. With Cumulus VX, you can get started with Open Networking at your pace, on your time, and in your environment!",
"vendor_name": "Cumulus Network",
"vendor_url": "https://www.cumulusnetworks.com",
"documentation_url": "http://docs.cumulusnetworks.com/",
"product_name": "Cumulus VX",
"product_url": "https://cumulusnetworks.com/cumulus-vx/",
"repository_version": 1,
"registry_version": 1,
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",
@ -19,7 +19,6 @@
"qemu": {
"adapter_type": "virtio-net-pci",
"adapters": 4,
"graphic": false,
"console_type": "vnc",
"ram": 256,
"arch": "x86_64"

View File

@ -17,11 +17,7 @@
"adapters": 16,
"ram": 1024,
"arch": "x86_64",
"console_type": "vnc",
"hda_disk_image": "vsr1000-hp.img",
"hda_disk_size": "8G",
"install_cdrom_to_hda": true,
"install_instructions": "* Wait for boot\n* Run fresh install\n* Say yes to reboot\nClose the window after reboot success"
"console_type": "vnc"
},
"images": [

View File

@ -7,7 +7,7 @@
"documentation_url": "http://wiki.tinycorelinux.net/",
"product_name": "Micro Core Linux",
"product_url": "http://distro.ibiblio.org/tinycorelinux",
"repository_version": 1,
"registry_version": 1,
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",

View File

@ -7,7 +7,7 @@
"documentation_url": "http://wiki.openwrt.org/doc/",
"product_name": "OpenWrt",
"product_url": "http://openwrt.org",
"repository_version": 1,
"registry_version": 1,
"status": "stable",
"maintainer": "GNS3 Team",
"maintainer_email": "developers@gns3.net",

View File

@ -7,7 +7,7 @@
"documentation_url": "http://ostinato.org/docs.html",
"product_name": "Drone",
"product_url": "http://ostinato.org/",
"repository_version": 1,
"registry_version": 1,
"status": "stable",
"maintainer": "Bernhard Ehler",
"maintainer_email": "be@bernhard-ehlers.de",

View File

@ -23,16 +23,19 @@ import copy
import base64
from jinja2 import Environment, FileSystemLoader
from check import check_schema
import logging
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
if os.path.exists('build'):
for file in os.listdir('build'):
if os.path.isdir(os.path.join('build', file)):
@ -85,6 +88,9 @@ render('myimages.html', 'myimages.html')
appliances = []
for appliance_file in os.listdir('appliances'):
log.info("Check the schema for " + appliance_file)
check_schema(appliance_file)
log.info("Process " + appliance_file)
out_filename = appliance_file[:-5]
with open(os.path.join('appliances', appliance_file)) as f:

38
check.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python
#
# Copyright (C) 2015 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/>.
import os
import jsonschema
import json
def check_schema(appliance):
with open('schemas/appliance.json') as f:
schema = json.load(f)
with open(os.path.join('appliances', appliance)) as f:
appliance_json = json.load(f)
jsonschema.validate(appliance_json, schema)
def main():
for appliance in os.listdir('appliances'):
print('Check {}'.format(appliance))
check_schema(appliance)
if __name__ == '__main__':
main()

View File

@ -1 +1,2 @@
Jinja2==2.7.3
json-schema==2.4.0

232
schemas/appliance.json Normal file
View File

@ -0,0 +1,232 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "JSON schema validating a GNS3 appliance",
"properties": {
"name": {
"type": "string",
"title": "Appliance name"
},
"category": {
"enum": [
"router",
"multilayer_switch",
"firewall",
"guest"
],
"title": "Category of the appliance"
},
"description": {
"type": "string",
"title": "Description of the appliance. Could be a marketing description"
},
"vendor_name": {
"type": "string",
"title": "Name of the vendor"
},
"vendor_url": {
"type": "string",
"format": "uri",
"title": "Website of the vendor"
},
"documentation_url": {
"type": "string",
"format": "uri",
"title": "Documentation for using the appliance on vendor website"
},
"product_name": {
"type": "string",
"title": "Product name"
},
"product_url": {
"type": "string",
"format": "uri",
"title": "Product url on vendor website"
},
"registry_version": {
"enum": [1],
"title": "Version of the registry compatible with this appliance"
},
"status": {
"enum": ["stable", "experimental", "broken"],
"title": "Document if the appliance is working or not"
},
"maintainer": {
"type": "string",
"title": "Maintainer name"
},
"maintainer_email": {
"type": "string",
"format": "email",
"title": "Maintainer email"
},
"usage": {
"type": "string",
"title": "How to use the appliance"
},
"symbol": {
"type": "string",
"title": "An optional symbol for the appliance"
},
"first_port_name": {
"type": "string",
"title": "Optional name of the first networking port example: eth0"
},
"port_name_format": {
"type": "string",
"title": "Optional formating of the newtorking port example: eth{0}"
},
"port_segment_size": {
"type": "integer"
},
"qemu": {
"type": "object",
"title": "Qemu specific options",
"properties": {
"adapter_type": {
"enum": ["e1000", "i82551", "i82557b", "i82559er", "ne2k_pci", "pcnet", "rtl8139", "virtio", "virtio-net-pci"],
"title": "Type of network adapter"
},
"adapters": {
"type": "integer",
"title": "Number of adapters"
},
"ram": {
"type": "integer",
"title": "Ram allocated to the appliance"
},
"arch": {
"enum": ["aarch64", "alpha", "arm", "cris", "i386", "lm32", "m68k", "microblaze", "microblazeel", "mips", "mips64", "mips64el", "mipsel", "moxie", "or32", "ppc", "ppc64", "ppcemb", "s390x", "sh4", "sh4eb", "sparc", "sparc64", "tricore", "unicore32", "x86_64", "xtensa", "xtensaeb"],
"title": "Architecture emulated"
},
"console_type": {
"enum": ["telnet", "vnc"],
"title": "Type of console connection for the administration of the appliance"
},
"options": {
"type": "string",
"title": "Optionnal additional qemu command line options"
}
},
"additionalProperties": false,
"required": [
"adapter_type",
"adapters",
"ram",
"arch",
"console_type"
]
},
"images": {
"type": "array",
"title": "Images for this appliance",
"items": {
"type": "object",
"title": "An image file",
"properties": {
"filename": {
"type": "string",
"title": "Filename"
},
"version": {
"type": "string",
"title": "Version of the file"
},
"md5sum": {
"type": "string",
"format": "md5",
"title": "md5sum of the file"
},
"download_url": {
"type": "string",
"format": "uri",
"title": "Download url where you can download the appliance from a browser"
},
"direct_download_url": {
"type": "string",
"title": "Optional. Non authenticated url to the image file where you can download the image."
}
},
"additionalProperties": false,
"required": [
"filename",
"version",
"md5sum",
"download_url"
]
}
},
"versions": {
"type": "array",
"title": "Versions of the appliance",
"items": {
"type": "object",
"title": "A version of the appliance",
"properties": {
"name": {
"type": "string",
"title": "Name of the version"
},
"images": {
"type": "object",
"title": "Images used for this version",
"properties": {
"kernel_image": {
"type": "string",
"title": "Kernel image"
},
"initrd_image": {
"type": "string",
"title": "Hda disk image"
},
"hda_disk_image": {
"type": "string",
"title": "Hdb disk image"
},
"hdb_disk_image": {
"type": "string",
"title": "Hdc disk image"
},
"hdc_disk_image": {
"type": "string",
"title": "Hdd disk image"
},
"hdd_disk_image": {
"type": "string",
"title": "Hdd diskimage"
},
"cdrom": {
"type": "string",
"title": "cdrom image"
}
},
"additionalProperties": false
}
},
"required": [
"name"
],
"additionalProperties": false
}
}
},
"additionalProperties": false,
"required": [
"name",
"category",
"description",
"vendor_name",
"vendor_url",
"documentation_url",
"product_name",
"product_url",
"registry_version",
"status",
"maintainer",
"maintainer_email",
"qemu",
"images",
"versions"
]
}