mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-29 08:54:34 +02:00
18 files changed
+183
-58
No files matched your search
@@ -16,13 +16,30 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import jsonschema
|
||||
import aiohttp
|
||||
|
||||
from ..version import __version__
|
||||
from ..schemas.topology import TOPOLOGY_SCHEMA
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
GNS3_FILE_FORMAT_REVISION = 5
|
||||
|
||||
|
||||
def _check_topology_schema(topo):
|
||||
try:
|
||||
jsonschema.validate(topo, TOPOLOGY_SCHEMA)
|
||||
except jsonschema.ValidationError as e:
|
||||
error = "Invalid data in topology file: {} in schema: {}".format(
|
||||
e.message,
|
||||
json.dumps(e.schema))
|
||||
log.critical(error)
|
||||
raise aiohttp.web.HTTPConflict(text=error)
|
||||
|
||||
|
||||
def project_to_topology(project):
|
||||
"""
|
||||
:return: A dictionnary with the topology ready to dump to a .gns3
|
||||
@@ -52,7 +69,7 @@ def project_to_topology(project):
|
||||
for compute in computes:
|
||||
if hasattr(compute, "__json__"):
|
||||
data["topology"]["computes"].append(compute.__json__(topology_dump=True))
|
||||
#TODO: check JSON schema
|
||||
_check_topology_schema(data)
|
||||
return data
|
||||
|
||||
|
||||
@@ -65,7 +82,7 @@ def load_topology(path):
|
||||
topo = json.load(f)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Could not load topology {}: {}".format(path, str(e)))
|
||||
#TODO: Check JSON schema
|
||||
if topo["revision"] < GNS3_FILE_FORMAT_REVISION:
|
||||
raise aiohttp.web.HTTPConflict(text="Old GNS3 project are not yet supported")
|
||||
_check_topology_schema(topo)
|
||||
return topo
|
||||
Reference in new issue
Block a user