mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Fix Error when converting some dynamips topologies from 1.3 => 2.0
Fix #718
This commit is contained in:
parent
b6fa14454e
commit
241c9b0c11
@ -100,6 +100,15 @@ WIC_MATRIX = {"WIC-1ENET": WIC_1ENET,
|
||||
"WIC-2T": WIC_2T}
|
||||
|
||||
|
||||
PLATFORMS_DEFAULT_RAM = {"c1700": 160,
|
||||
"c2600": 160,
|
||||
"c2691": 192,
|
||||
"c3600": 192,
|
||||
"c3725": 128,
|
||||
"c3745": 256,
|
||||
"c7200": 512}
|
||||
|
||||
|
||||
class Dynamips(BaseManager):
|
||||
|
||||
_NODE_CLASS = DynamipsVMFactory
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import copy
|
||||
import uuid
|
||||
import shutil
|
||||
import zipfile
|
||||
@ -26,8 +27,9 @@ import jsonschema
|
||||
|
||||
from ..version import __version__
|
||||
from ..schemas.topology import TOPOLOGY_SCHEMA
|
||||
from ..schemas import dynamips_vm
|
||||
from ..utils.qt import qt_font_to_style
|
||||
|
||||
from ..compute.dynamips import PLATFORMS_DEFAULT_RAM
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
@ -39,6 +41,22 @@ GNS3_FILE_FORMAT_REVISION = 5
|
||||
def _check_topology_schema(topo):
|
||||
try:
|
||||
jsonschema.validate(topo, TOPOLOGY_SCHEMA)
|
||||
|
||||
# Check the nodes property against compute schemas
|
||||
for node in topo["topology"].get("nodes", []):
|
||||
schema = None
|
||||
if node["node_type"] == "dynamips":
|
||||
schema = copy.deepcopy(dynamips_vm.VM_CREATE_SCHEMA)
|
||||
|
||||
if schema:
|
||||
# Properties send to compute but in an other place in topology
|
||||
delete_properties = ["name", "node_id"]
|
||||
for prop in delete_properties:
|
||||
del schema["properties"][prop]
|
||||
schema["required"] = [p for p in schema["required"] if p not in delete_properties]
|
||||
|
||||
jsonschema.validate(node.get("properties", {}), schema)
|
||||
|
||||
except jsonschema.ValidationError as e:
|
||||
error = "Invalid data in topology file: {} in schema: {}".format(
|
||||
e.message,
|
||||
@ -102,7 +120,7 @@ def load_topology(path):
|
||||
topo = _convert_1_3_later(topo, path)
|
||||
_check_topology_schema(topo)
|
||||
with open(path, "w+", encoding="utf-8") as f:
|
||||
json.dump(topo, f)
|
||||
json.dump(topo, f, indent=4, sort_keys=True)
|
||||
elif topo["revision"] > GNS3_FILE_FORMAT_REVISION:
|
||||
raise aiohttp.web.HTTPConflict(text="This project is designed for a more recent version of GNS3 please update GNS3 to version {} or later".format(topo["version"]))
|
||||
_check_topology_schema(topo)
|
||||
@ -231,6 +249,10 @@ def _convert_1_3_later(topo, topo_path):
|
||||
node["symbol"] = ":/symbols/router.svg"
|
||||
node["node_type"] = "dynamips"
|
||||
node["properties"]["dynamips_id"] = old_node["dynamips_id"]
|
||||
if "platform" not in node["properties"] and old_node["type"].startswith("C"):
|
||||
node["properties"]["platform"] = old_node["type"].lower()
|
||||
if "ram" not in node["properties"] and old_node["type"].startswith("C"):
|
||||
node["properties"]["ram"] = PLATFORMS_DEFAULT_RAM[old_node["type"].lower()]
|
||||
elif old_node["type"] == "VMwareVM":
|
||||
node["node_type"] = "vmware"
|
||||
if node["symbol"] is None:
|
||||
|
@ -57,8 +57,6 @@ def test_convert(directory, tmpdir):
|
||||
|
||||
with open(os.path.join(before_directory, gns3_file)) as f:
|
||||
before_topology = json.load(f)
|
||||
with open(os.path.join(after_directory, gns3_file)) as f:
|
||||
after_topology = json.load(f)
|
||||
|
||||
# We use a temporary directory for conversion operation to not corrupt our files
|
||||
work_directory = str(tmpdir / "work")
|
||||
@ -95,6 +93,8 @@ def test_convert(directory, tmpdir):
|
||||
if ".backup" not in file_path:
|
||||
assert os.path.exists(file_path), "{} should not be here".format(os.path.join(directory, file))
|
||||
|
||||
with open(os.path.join(after_directory, gns3_file)) as f:
|
||||
after_topology = json.load(f)
|
||||
compare_dict("/", work_topology, after_topology)
|
||||
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
{
|
||||
"revision": 5,
|
||||
"auto_start": false,
|
||||
"topology": {
|
||||
"drawings": [],
|
||||
"links": [],
|
||||
"nodes": [
|
||||
{
|
||||
"port_segment_size": 0,
|
||||
"name": "ASW1",
|
||||
"node_type": "dynamips",
|
||||
"label": {
|
||||
"x": -16,
|
||||
"y": -26,
|
||||
"style": "font-family: TypeWriter;font-size: 10;font-weight: bold;fill: #000000;fill-opacity: 1.0;",
|
||||
"text": "ASW1",
|
||||
"rotation": 0
|
||||
},
|
||||
"port_name_format": "Ethernet{0}",
|
||||
"node_id": "02e4a9e8-a897-4b5b-94ba-968d8a0dc5b3",
|
||||
"y": 25,
|
||||
"x": -722,
|
||||
"console": 2012,
|
||||
"compute_id": "local",
|
||||
"symbol": ":/symbols/router.svg",
|
||||
"properties": {
|
||||
"slot0": "Leopard-2FE",
|
||||
"idlepc": "0x6057efc8",
|
||||
"chassis": "3660",
|
||||
"startup_config": "configs/i1_startup-config.cfg",
|
||||
"image": "c3660-a3jk9s-mz.124-25c.bin",
|
||||
"mac_addr": "cc01.20b8.0000",
|
||||
"aux": 2103,
|
||||
"ram": 192,
|
||||
"platform": "c3600",
|
||||
"dynamips_id": 1,
|
||||
"slot1": "NM-16ESW"
|
||||
},
|
||||
"first_port_name": null,
|
||||
"console_type": "telnet",
|
||||
"z": 1
|
||||
}
|
||||
],
|
||||
"computes": [
|
||||
{
|
||||
"name": "Local",
|
||||
"port": 8000,
|
||||
"compute_id": "local",
|
||||
"protocol": "http",
|
||||
"host": "127.0.0.1"
|
||||
}
|
||||
]
|
||||
},
|
||||
"project_id": "6e8b7940-a855-4e0c-8854-82577ba08eb1",
|
||||
"type": "topology",
|
||||
"name": "1_3_dynamips_missing_platform",
|
||||
"version": "ANYSTR"
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
{
|
||||
"auto_start": false,
|
||||
"name": "1_3_dynamips_missing_platform",
|
||||
"project_id": "6e8b7940-a855-4e0c-8854-82577ba08eb1",
|
||||
"resources_type": "local",
|
||||
"revision": 3,
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"description": "Router c3600",
|
||||
"dynamips_id": 1,
|
||||
"id": 1,
|
||||
"label": {
|
||||
"color": "#000000",
|
||||
"font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
|
||||
"text": "ASW1",
|
||||
"x": -16.924486139,
|
||||
"y": -26.2599194157
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 1,
|
||||
"name": "FastEthernet0/0",
|
||||
"port_number": 0
|
||||
},
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 2,
|
||||
"name": "FastEthernet0/1",
|
||||
"port_number": 1
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to Client1 on port FastEthernet0/0",
|
||||
"id": 3,
|
||||
"link_id": 15,
|
||||
"name": "FastEthernet1/0",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 0
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 4,
|
||||
"name": "FastEthernet1/1",
|
||||
"port_number": 1
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 5,
|
||||
"name": "FastEthernet1/2",
|
||||
"port_number": 2
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 6,
|
||||
"name": "FastEthernet1/3",
|
||||
"port_number": 3
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 7,
|
||||
"name": "FastEthernet1/4",
|
||||
"port_number": 4
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 8,
|
||||
"name": "FastEthernet1/5",
|
||||
"port_number": 5
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 9,
|
||||
"name": "FastEthernet1/6",
|
||||
"port_number": 6
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 10,
|
||||
"name": "FastEthernet1/7",
|
||||
"port_number": 7
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 11,
|
||||
"name": "FastEthernet1/8",
|
||||
"port_number": 8
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW1 on port FastEthernet1/9",
|
||||
"id": 12,
|
||||
"link_id": 8,
|
||||
"name": "FastEthernet1/9",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 9
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW1 on port FastEthernet1/10",
|
||||
"id": 13,
|
||||
"link_id": 5,
|
||||
"name": "FastEthernet1/10",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 10
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW2 on port FastEthernet1/11",
|
||||
"id": 14,
|
||||
"link_id": 6,
|
||||
"name": "FastEthernet1/11",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 11
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW2 on port FastEthernet1/12",
|
||||
"id": 15,
|
||||
"link_id": 7,
|
||||
"name": "FastEthernet1/12",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 12
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 16,
|
||||
"name": "FastEthernet1/13",
|
||||
"port_number": 13
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 17,
|
||||
"name": "FastEthernet1/14",
|
||||
"port_number": 14
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 18,
|
||||
"name": "FastEthernet1/15",
|
||||
"port_number": 15
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"aux": 2103,
|
||||
"chassis": "3660",
|
||||
"console": 2012,
|
||||
"idlepc": "0x6057efc8",
|
||||
"image": "c3660-a3jk9s-mz.124-25c.bin",
|
||||
"mac_addr": "cc01.20b8.0000",
|
||||
"name": "ASW1",
|
||||
"slot0": "Leopard-2FE",
|
||||
"slot1": "NM-16ESW",
|
||||
"startup_config": "configs/i1_startup-config.cfg"
|
||||
},
|
||||
"server_id": 1,
|
||||
"type": "C3600",
|
||||
"vm_id": "02e4a9e8-a897-4b5b-94ba-968d8a0dc5b3",
|
||||
"x": -722.7235717864439,
|
||||
"y": 25.4496381690538
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
{
|
||||
"cloud": false,
|
||||
"host": "127.0.0.1",
|
||||
"id": 1,
|
||||
"local": true,
|
||||
"port": 8000
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "topology",
|
||||
"version": "1.3.0"
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
{
|
||||
"auto_start": false,
|
||||
"name": "1_3_dynamips_missing_platform",
|
||||
"project_id": "6e8b7940-a855-4e0c-8854-82577ba08eb1",
|
||||
"resources_type": "local",
|
||||
"revision": 3,
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"description": "Router c3600",
|
||||
"dynamips_id": 1,
|
||||
"id": 1,
|
||||
"label": {
|
||||
"color": "#000000",
|
||||
"font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
|
||||
"text": "ASW1",
|
||||
"x": -16.924486139,
|
||||
"y": -26.2599194157
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 1,
|
||||
"name": "FastEthernet0/0",
|
||||
"port_number": 0
|
||||
},
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 2,
|
||||
"name": "FastEthernet0/1",
|
||||
"port_number": 1
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to Client1 on port FastEthernet0/0",
|
||||
"id": 3,
|
||||
"link_id": 15,
|
||||
"name": "FastEthernet1/0",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 0
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 4,
|
||||
"name": "FastEthernet1/1",
|
||||
"port_number": 1
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 5,
|
||||
"name": "FastEthernet1/2",
|
||||
"port_number": 2
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 6,
|
||||
"name": "FastEthernet1/3",
|
||||
"port_number": 3
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 7,
|
||||
"name": "FastEthernet1/4",
|
||||
"port_number": 4
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 8,
|
||||
"name": "FastEthernet1/5",
|
||||
"port_number": 5
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 9,
|
||||
"name": "FastEthernet1/6",
|
||||
"port_number": 6
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 10,
|
||||
"name": "FastEthernet1/7",
|
||||
"port_number": 7
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 11,
|
||||
"name": "FastEthernet1/8",
|
||||
"port_number": 8
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW1 on port FastEthernet1/9",
|
||||
"id": 12,
|
||||
"link_id": 8,
|
||||
"name": "FastEthernet1/9",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 9
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW1 on port FastEthernet1/10",
|
||||
"id": 13,
|
||||
"link_id": 5,
|
||||
"name": "FastEthernet1/10",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 10
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW2 on port FastEthernet1/11",
|
||||
"id": 14,
|
||||
"link_id": 6,
|
||||
"name": "FastEthernet1/11",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 11
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"description": "connected to DSW2 on port FastEthernet1/12",
|
||||
"id": 15,
|
||||
"link_id": 7,
|
||||
"name": "FastEthernet1/12",
|
||||
"nio": "NIO_UDP",
|
||||
"port_number": 12
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 16,
|
||||
"name": "FastEthernet1/13",
|
||||
"port_number": 13
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 17,
|
||||
"name": "FastEthernet1/14",
|
||||
"port_number": 14
|
||||
},
|
||||
{
|
||||
"adapter_number": 1,
|
||||
"id": 18,
|
||||
"name": "FastEthernet1/15",
|
||||
"port_number": 15
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"aux": 2103,
|
||||
"chassis": "3660",
|
||||
"console": 2012,
|
||||
"idlepc": "0x6057efc8",
|
||||
"image": "c3660-a3jk9s-mz.124-25c.bin",
|
||||
"mac_addr": "cc01.20b8.0000",
|
||||
"name": "ASW1",
|
||||
"slot0": "Leopard-2FE",
|
||||
"slot1": "NM-16ESW",
|
||||
"startup_config": "configs/i1_startup-config.cfg"
|
||||
},
|
||||
"server_id": 1,
|
||||
"type": "C3600",
|
||||
"vm_id": "02e4a9e8-a897-4b5b-94ba-968d8a0dc5b3",
|
||||
"x": -722.7235717864439,
|
||||
"y": 25.4496381690538
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
{
|
||||
"cloud": false,
|
||||
"host": "127.0.0.1",
|
||||
"id": 1,
|
||||
"local": true,
|
||||
"port": 8000
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "topology",
|
||||
"version": "1.3.0"
|
||||
}
|
Loading…
Reference in New Issue
Block a user