From 27841576d6239f39b3c6241d67c966b3580ea35f Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 16 Feb 2016 18:47:08 +0100 Subject: [PATCH] Docker container support --- appliances/openvswitch.gns3a | 37 ++++++++-------------------------- check.py | 39 ++++++++++++++++++------------------ prettify_appliances.py | 28 ++++++++++++++------------ schemas/appliance.json | 34 +++++++++++++++++++++++++++---- 4 files changed, 73 insertions(+), 65 deletions(-) diff --git a/appliances/openvswitch.gns3a b/appliances/openvswitch.gns3a index 35d0482..63e8d01 100644 --- a/appliances/openvswitch.gns3a +++ b/appliances/openvswitch.gns3a @@ -3,37 +3,16 @@ "category": "multilayer_switch", "description": "Open vSwitch is a production quality, multilayer virtual switch licensed under the open source Apache 2.0 license. It is designed to enable massive network automation through programmatic extension, while still supporting standard management interfaces and protocols (e.g. NetFlow, sFlow, IPFIX, RSPAN, CLI, LACP, 802.1ag). In addition, it is designed to support distribution across multiple physical servers similar to VMware's vNetwork distributed vswitch or Cisco's Nexus 1000V.", "vendor_name": "Open vSwitch", - "vendor_url": "http://openvswitch.net/", - "documentation_url": "http://openvswitch.net/support", + "vendor_url": "http://openvswitch.org/", + "documentation_url": "http://openvswitch.org/support/", "product_name": "Open vSwitch", - "registry_version": 1, + "registry_version": 3, "status": "stable", "maintainer": "GNS3 Team", "maintainer_email": "developers@gns3.net", - "qemu": { - "adapter_type": "e1000", - "adapters": 24, - "ram": 128, - "arch": "x86_64", - "console_type": "telnet", - "kvm": "allow" - }, - "images": [ - { - "filename": "openvswitch-3.16.6-tinycore64.img", - "version": "3.16.6", - "md5sum": "88b777ef930c1a3849b6a40c0d3fd102", - "filesize": 70254592, - "download_url": "https://sourceforge.net/projects/gns-3/files/Qemu%20Appliances/", - "direct_download_url": "http://downloads.sourceforge.net/project/gns-3/Qemu%20Appliances/openvswitch-3.16.6-tinycore64.img" - } - ], - "versions": [ - { - "name": "3.16.6", - "images": { - "hda_disk_image": "openvswitch-3.16.6-tinycore64.img" - } - } - ] + "usage": "By default all interfaces are connected to the br0", + "docker": { + "adapters": 16, + "image": "gns3/openvswitch" + } } diff --git a/check.py b/check.py index a48dac8..c1c6318 100644 --- a/check.py +++ b/check.py @@ -35,26 +35,27 @@ def check_appliance(appliance): appliance_json = json.load(f) jsonschema.validate(appliance_json, schema) - for image in appliance_json['images']: - if image['filename'] in images: - print('Duplicate image filename ' + image['filename']) - sys.exit(1) - if image['md5sum'] in md5sums: - print('Duplicate image md5sum ' + image['md5sum']) - sys.exit(1) - images.add(image['filename']) - md5sums.add(image['md5sum']) - - for version in appliance_json['versions']: - for image in version['images'].values(): - found = False - for i in appliance_json['images']: - if i['filename'] in image: - found = True - - if not found: - print('Missing relation ' + i['filename'] + ' ' + ' in ' + appliance) + if 'images' in appliance_json: + for image in appliance_json['images']: + if image['filename'] in images: + print('Duplicate image filename ' + image['filename']) sys.exit(1) + if image['md5sum'] in md5sums: + print('Duplicate image md5sum ' + image['md5sum']) + sys.exit(1) + images.add(image['filename']) + md5sums.add(image['md5sum']) + + for version in appliance_json['versions']: + for image in version['images'].values(): + found = False + for i in appliance_json['images']: + if i['filename'] in image: + found = True + + if not found: + print('Missing relation ' + i['filename'] + ' ' + ' in ' + appliance) + sys.exit(1) def check_packer(packer): diff --git a/prettify_appliances.py b/prettify_appliances.py index 6289a9c..64b0600 100644 --- a/prettify_appliances.py +++ b/prettify_appliances.py @@ -58,20 +58,22 @@ for appliance in glob.glob('appliances/*.gns3a'): if isinstance(val, dict): config[key] = OrderedDict(sorted(val.items(), key=lambda t: sort_key_using_schema(schema['properties'][key], t[0]))) - images = [] - for image in config['images']: - clean_urls(image) - images.append(OrderedDict(sorted(image.items(), key=lambda t: sort_key_using_schema(schema['properties']['images']['items'], t[0])))) - images = sorted(images, key=lambda t: t['version'], reverse=True) - config['images'] = images + if 'images' in config: + images = [] + for image in config['images']: + clean_urls(image) + images.append(OrderedDict(sorted(image.items(), key=lambda t: sort_key_using_schema(schema['properties']['images']['items'], t[0])))) + images = sorted(images, key=lambda t: t['version'], reverse=True) + config['images'] = images - versions = [] - for version in config['versions']: - version = OrderedDict(sorted(version.items(), key=lambda t: sort_key_using_schema(schema['properties']['versions']['items'], t[0]))) - version['images'] = OrderedDict(sorted(version['images'].items(), key=lambda t: sort_key_using_schema(schema['properties']['versions']['items']['properties']['images'], t[0]))) - versions.append(version) - versions = sorted(versions, key=lambda t: t['name'], reverse=True) - config['versions'] = versions + if 'versions' in config: + versions = [] + for version in config['versions']: + version = OrderedDict(sorted(version.items(), key=lambda t: sort_key_using_schema(schema['properties']['versions']['items'], t[0]))) + version['images'] = OrderedDict(sorted(version['images'].items(), key=lambda t: sort_key_using_schema(schema['properties']['versions']['items']['properties']['images'], t[0]))) + versions.append(version) + versions = sorted(versions, key=lambda t: t['name'], reverse=True) + config['versions'] = versions # Validate our changes jsonschema.validate(config, schema) diff --git a/schemas/appliance.json b/schemas/appliance.json index 9d91548..128b4bb 100644 --- a/schemas/appliance.json +++ b/schemas/appliance.json @@ -55,7 +55,7 @@ "title": "An optional product url on vendor website" }, "registry_version": { - "enum": [1, 2], + "enum": [1, 2, 3], "title": "Version of the registry compatible with this appliance" }, "status": { @@ -96,6 +96,34 @@ "title": "False if you don't want to use a single image for all nodes" }, + "docker": { + "type": "object", + "title": "Docker specific options", + "properties": { + "adapters": { + "type": "integer", + "title": "Number of ethernet adapters" + }, + "image": { + "type": "string", + "title": "Docker image in the Docker Hub" + }, + "start_command": { + "type": "string", + "title": "Command executed when the container start. Empty will use the default" + }, + "environment": { + "type": "string", + "title": "One KEY=VAR environment by line" + } + }, + "additionalProperties": false, + "required": [ + "adapters", + "image" + ] + }, + "iou": { "type": "object", "title": "IOU specific options", @@ -400,8 +428,6 @@ "registry_version", "status", "maintainer", - "maintainer_email", - "images", - "versions" + "maintainer_email" ] }