Skip to content

Commit

Permalink
"appliance_id" is now required and check for duplicate appliance UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Oct 22, 2021
1 parent aeed55a commit b34eb83
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 121 deletions.
9 changes: 8 additions & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import jsonschema
from picture import get_size


APPLIANCE_IDS = []
SCHEMA_VERSIONS = [3, 4, 5, 6]

warnings = 0
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 14 additions & 8 deletions new_appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import json
import os
import sys
import uuid


def ask_multiple(question, options, optional=False):
Expand Down Expand Up @@ -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
Expand All @@ -89,7 +95,7 @@ def ask_from_schema(schema):
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:
Expand Down
67 changes: 0 additions & 67 deletions riverbed-steelhead-ng-vcx.gns3a

This file was deleted.

2 changes: 2 additions & 0 deletions schemas/appliance_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

"properties": {
"appliance_id": {
"title": "Appliance ID",
"type": "string",
"minLength": 36,
"maxLength": 36,
Expand Down Expand Up @@ -438,6 +439,7 @@
},
"additionalProperties": false,
"required": [
"appliance_id",
"name",
"category",
"description",
Expand Down
2 changes: 2 additions & 0 deletions schemas/appliance_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

"properties": {
"appliance_id": {
"title": "Appliance ID",
"type": "string",
"minLength": 36,
"maxLength": 36,
Expand Down Expand Up @@ -440,6 +441,7 @@
}
},
"required": [
"appliance_id",
"name",
"category",
"description",
Expand Down
2 changes: 2 additions & 0 deletions schemas/appliance_v5.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

"properties": {
"appliance_id": {
"title": "Appliance ID",
"type": "string",
"minLength": 36,
"maxLength": 36,
Expand Down Expand Up @@ -440,6 +441,7 @@
}
},
"required": [
"appliance_id",
"name",
"category",
"description",
Expand Down
2 changes: 2 additions & 0 deletions schemas/appliance_v6.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

"properties": {
"appliance_id": {
"title": "Appliance ID",
"type": "string",
"minLength": 36,
"maxLength": 36,
Expand Down Expand Up @@ -491,6 +492,7 @@
}
},
"required": [
"appliance_id",
"name",
"category",
"description",
Expand Down
45 changes: 0 additions & 45 deletions ubuntu-server-18.04.3 (64bit) LTS.gns3a

This file was deleted.

0 comments on commit b34eb83

Please sign in to comment.