diff --git a/check.py b/check.py index cb4e23c..25ce584 100644 --- a/check.py +++ b/check.py @@ -24,7 +24,7 @@ import subprocess import jsonschema from picture import get_size - +APPLIANCE_IDS = [] SCHEMA_VERSIONS = [3, 4, 5, 6] warnings = 0 @@ -82,8 +82,15 @@ def check_appliance(appliance): with open(os.path.join('appliances', appliance)) as f: appliance_json = json.load(f) + validate_schema(appliance_json, appliance, schemas) + appliance_id = appliance_json.get("appliance_id") + if appliance_id in APPLIANCE_IDS: + print('Duplicate appliance UUID detected ' + appliance_id) + sys.exit(1) + APPLIANCE_IDS.append(appliance_id) + if 'images' in appliance_json: for image in appliance_json['images']: if image['filename'] in images: diff --git a/new_appliance.py b/new_appliance.py index c93ac29..cfba2c8 100644 --- a/new_appliance.py +++ b/new_appliance.py @@ -23,6 +23,7 @@ Create a new appliance from the terminal import json import os import sys +import uuid def ask_multiple(question, options, optional=False): @@ -71,14 +72,19 @@ def ask(question, type='string', optional=False): def ask_from_schema(schema): data = {} - for key,val in schema['properties'].items(): - optional = not key in schema['required'] - result = None + for key, val in schema['properties'].items(): - if 'enum' in val: - result = ask_multiple(val['title'], val['enum'], optional=optional) - elif val['type'] in ('integer', 'string'): - result = ask(val['title'], type=val['type'], optional=optional) + if key == "appliance_id": + # generate an unique ID for the appliance + result = str(uuid.uuid4()) + else: + optional = not key in schema['required'] + result = None + + if 'enum' in val: + result = ask_multiple(val['title'], val['enum'], optional=optional) + elif val['type'] in ('integer', 'string'): + result = ask(val['title'], type=val['type'], optional=optional) if result: data[key] = result @@ -89,7 +95,7 @@ with open(os.path.join('schemas', 'appliance_v5.json')) as f: schema = json.load(f) -appliance_name = ask('Appliance id (example: cisco-asav)') +appliance_name = ask('Appliance filename (example: cisco-asav)') # TODO check if file exists with open(os.path.join('appliances', appliance_name + '.gns3a'), 'w+') as f: diff --git a/riverbed-steelhead-ng-vcx.gns3a b/riverbed-steelhead-ng-vcx.gns3a deleted file mode 100644 index c72bdfb..0000000 --- a/riverbed-steelhead-ng-vcx.gns3a +++ /dev/null @@ -1,67 +0,0 @@ -{ - "name": "SteelHead", - "category": "guest", - "description": "SteelHead is the Riverbed Accelerator", - "vendor_name": "Riverbed Technology", - "vendor_url": "http://www.riverbed.com", - "documentation_url": "https://github.com/riverbed/Riverbed-Community-Toolkit/tree/master/SteelHead/GNS3", - "product_name": "SteelHead", - "product_url": "https://support.riverbed.com/content/support/software/steelhead/cx-appliance.html", - "registry_version": 6, - "status": "stable", - "maintainer": "Riverbed Community", - "maintainer_email": "community@riverbed.com", - "usage": "Download the KVM image Next Generation Virtual SteelHead VCX Software Image (KVM) from https://support.riverbed.com/content/support/software/steelhead/cx-appliance.html\n Uncompress the .tgz archive using this command: tar xzSf \nDefault credentials: admin / password", - "symbol": "steelhead-vcx.png", - "first_port_name": "PRI", - "qemu": { - "arch": "x86_64", - "adapter_type": "virtio-net-pci", - "adapters": 4, - "custom_adapters": [ - { - "adapter_number": 1, - "port_name": "AUX" - }, - { - "adapter_number": 2, - "port_name": "LAN0_0" - }, - { - "adapter_number": 3, - "port_name": "WAN0_0" - } - ], - "ram": 2048, - "hda_disk_interface": "virtio", - "hdb_disk_interface": "virtio", - "console_type": "telnet", - "kvm": "require" - }, - "images": [ - { - "filename": "mgmt.qcow2", - "version": "9.12.0", - "md5sum": "0f45d7cfb75b5e7e915dd37136411580", - "filesize": 2381840384, - "download_url": "https://support.riverbed.com/content/support/software/steelhead/cx-appliance.html#software-alert" - }, - { - "filename": "empty100G.qcow2", - "version": "1.0", - "md5sum": "5d9fec18a980f13002028491259f158d", - "filesize": 198656, - "download_url": "https://github.com/riverbed/Riverbed-Community-Toolkit/raw/master/SteelHead/GNS3", - "direct_download_url": "https://github.com/riverbed/Riverbed-Community-Toolkit/raw/master/SteelHead/GNS3/empty100G.qcow2" - } - ], - "versions": [ - { - "name": "9.12.0", - "images": { - "hda_disk_image": "mgmt.qcow2", - "hdb_disk_image": "empty100G.qcow2" - } - } - ] -} diff --git a/schemas/appliance_v3.json b/schemas/appliance_v3.json index 2b5c9c2..296825e 100644 --- a/schemas/appliance_v3.json +++ b/schemas/appliance_v3.json @@ -15,6 +15,7 @@ "properties": { "appliance_id": { + "title": "Appliance ID", "type": "string", "minLength": 36, "maxLength": 36, @@ -438,6 +439,7 @@ }, "additionalProperties": false, "required": [ + "appliance_id", "name", "category", "description", diff --git a/schemas/appliance_v4.json b/schemas/appliance_v4.json index 4f27419..c7789d1 100644 --- a/schemas/appliance_v4.json +++ b/schemas/appliance_v4.json @@ -15,6 +15,7 @@ "properties": { "appliance_id": { + "title": "Appliance ID", "type": "string", "minLength": 36, "maxLength": 36, @@ -440,6 +441,7 @@ } }, "required": [ + "appliance_id", "name", "category", "description", diff --git a/schemas/appliance_v5.json b/schemas/appliance_v5.json index 790e3ec..bb1238b 100644 --- a/schemas/appliance_v5.json +++ b/schemas/appliance_v5.json @@ -15,6 +15,7 @@ "properties": { "appliance_id": { + "title": "Appliance ID", "type": "string", "minLength": 36, "maxLength": 36, @@ -440,6 +441,7 @@ } }, "required": [ + "appliance_id", "name", "category", "description", diff --git a/schemas/appliance_v6.json b/schemas/appliance_v6.json index 00f4164..a45353a 100644 --- a/schemas/appliance_v6.json +++ b/schemas/appliance_v6.json @@ -15,6 +15,7 @@ "properties": { "appliance_id": { + "title": "Appliance ID", "type": "string", "minLength": 36, "maxLength": 36, @@ -491,6 +492,7 @@ } }, "required": [ + "appliance_id", "name", "category", "description", diff --git a/ubuntu-server-18.04.3 (64bit) LTS.gns3a b/ubuntu-server-18.04.3 (64bit) LTS.gns3a deleted file mode 100644 index 1f99433..0000000 --- a/ubuntu-server-18.04.3 (64bit) LTS.gns3a +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "Ubuntu Server", - "category": "guest", - "description": "This is a custom Ubuntu server which comes with Canonical security updates, Xorg and Telnetd", - "vendor_name": "Canonical Inc.", - "vendor_url": "https://www.ubuntu.com", - "documentation_url": "https://help.ubuntu.com", - "product_name": "Ubuntu", - "product_url": "https://ubuntu.com/server", - "registry_version": 3, - "status": "stable", - "maintainer": "Mohamad Siblini", - "maintainer_email": "https://www.ictkin.com/contact", - "usage": "Username: gns3\nPassword: gns3 | MD5: 435f15a54f7f673e302ad26f05226e0e", - "port_name_format": "ens{0}", - "qemu": { - "adapter_type": "virtio-net-pci", - "adapters": 1, - "ram": 2048, - "hda_disk_interface": "virtio", - "arch": "x86_64", - "console_type": "vnc", - "boot_priority": "c", - "kvm": "require", - "options": "-vga virtio" - }, - "images": [ - { - "filename": "Ubuntu Server 18.04.3 LTS (64bit).vmdk", - "version": "18.04.3", - "md5sum": "435f15a54f7f673e302ad26f05226e0e", - "filesize": 2707814912, - "download_url": "https://www.ictkin.com/gns3-appliance/" - } - ], - "versions": [ - { - "name": "18.04.3 LTS Server", - "images": { - "hda_disk_image": "Ubuntu Server 18.04.3 LTS (64bit).vmdk" - } - } - ] -} -