mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
parent
0c3a2c660a
commit
45af721164
@ -17,10 +17,12 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import jsonschema
|
||||
import uuid
|
||||
import shutil
|
||||
import zipfile
|
||||
import aiohttp
|
||||
import jsonschema
|
||||
|
||||
|
||||
from ..version import __version__
|
||||
from ..schemas.topology import TOPOLOGY_SCHEMA
|
||||
@ -108,6 +110,8 @@ def _convert_1_3_later(topo, topo_path):
|
||||
"""
|
||||
topo_dir = os.path.dirname(topo_path)
|
||||
|
||||
_convert_snapshots(topo_dir)
|
||||
|
||||
new_topo = {
|
||||
"type": "topology",
|
||||
"revision": GNS3_FILE_FORMAT_REVISION,
|
||||
@ -448,3 +452,34 @@ def _create_cloud(node, old_node, icon):
|
||||
|
||||
node["properties"]["ports"] = ports
|
||||
node["properties"]["interfaces"] = []
|
||||
|
||||
|
||||
def _convert_snapshots(topo_dir):
|
||||
"""
|
||||
Convert 1.x snapshot to the new format
|
||||
"""
|
||||
old_snapshots_dir = os.path.join(topo_dir, "project-files", "snapshots")
|
||||
if os.path.exists(old_snapshots_dir):
|
||||
new_snapshots_dir = os.path.join(topo_dir, "snapshots")
|
||||
os.makedirs(new_snapshots_dir)
|
||||
|
||||
for snapshot in os.listdir(old_snapshots_dir):
|
||||
snapshot_dir = os.path.join(old_snapshots_dir, snapshot)
|
||||
if os.path.isdir(snapshot_dir):
|
||||
is_gns3_topo = False
|
||||
|
||||
# In .gns3project fileformat the .gns3 should be name project.gns3
|
||||
for file in os.listdir(snapshot_dir):
|
||||
if file.endswith(".gns3"):
|
||||
shutil.move(os.path.join(snapshot_dir, file), os.path.join(snapshot_dir, "project.gns3"))
|
||||
is_gns3_topo = True
|
||||
|
||||
if is_gns3_topo:
|
||||
snapshot_arc = os.path.join(new_snapshots_dir, snapshot + ".gns3project")
|
||||
with zipfile.ZipFile(snapshot_arc, 'w') as myzip:
|
||||
for root, dirs, files in os.walk(snapshot_dir):
|
||||
for file in files:
|
||||
myzip.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), snapshot_dir), compress_type=zipfile.ZIP_DEFLATED)
|
||||
shutil.copy(snapshot_arc, "/tmp/test.zip")
|
||||
|
||||
shutil.rmtree(old_snapshots_dir)
|
||||
|
@ -81,6 +81,15 @@ def test_convert(directory, tmpdir):
|
||||
if not file_path.endswith(".gns3"):
|
||||
assert os.stat(file_path).st_size == os.stat(os.path.join(os.path.join(root, file))).st_size, "File {} is different".format(os.path.join(directory, file))
|
||||
|
||||
# Check if we don't have unexpected file in work directory
|
||||
for root, dirs, files in os.walk(work_directory):
|
||||
for file in files:
|
||||
directory = os.path.relpath(root, work_directory)
|
||||
file_path = os.path.join(after_directory, directory, file)
|
||||
# .backup are created by the conversion process
|
||||
if not file.endswith(".backup"):
|
||||
assert os.path.exists(file_path), "{} should not be here".format(os.path.join(directory, file))
|
||||
|
||||
compare_dict("/", work_topology, after_topology)
|
||||
|
||||
|
||||
|
45
tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3
Normal file
45
tests/topologies/1_5_snapshot/after/1_5_snapshot.gns3
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"type" : "topology",
|
||||
"version" : "2.0.0dev1",
|
||||
"topology" : {
|
||||
"nodes" : [
|
||||
{
|
||||
"compute_id" : "local",
|
||||
"z" : 1,
|
||||
"y" : -51,
|
||||
"node_id" : "992c28fd-4bc3-4508-9300-48600148f64a",
|
||||
"x" : -128,
|
||||
"console" : 5000,
|
||||
"node_type" : "vpcs",
|
||||
"name" : "PC1",
|
||||
"symbol" : ":/symbols/vpcs_guest.svg",
|
||||
"console_type" : "telnet",
|
||||
"properties" : {
|
||||
"startup_script_path" : "startup.vpc"
|
||||
},
|
||||
"label" : {
|
||||
"y" : -25,
|
||||
"style" : "font-family: TypeWriter;font-size: 10;font-weight: bold;fill: #000000;fill-opacity: 1.0;",
|
||||
"x" : 18,
|
||||
"text" : "PC1",
|
||||
"rotation" : 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"links" : [],
|
||||
"drawings" : [],
|
||||
"computes" : [
|
||||
{
|
||||
"name" : "Local",
|
||||
"host" : "127.0.0.1",
|
||||
"compute_id" : "local",
|
||||
"protocol" : "http",
|
||||
"port" : 3080
|
||||
}
|
||||
]
|
||||
},
|
||||
"revision" : 5,
|
||||
"name" : "1_5_snapshot",
|
||||
"project_id" : "17912669-dd40-4843-b348-689b8f34f09d",
|
||||
"auto_start" : false
|
||||
}
|
@ -0,0 +1 @@
|
||||
set pcname PC1
|
Binary file not shown.
52
tests/topologies/1_5_snapshot/before/1_5_snapshot.gns3
Normal file
52
tests/topologies/1_5_snapshot/before/1_5_snapshot.gns3
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"auto_start": false,
|
||||
"name": "1_5_snapshot",
|
||||
"project_id": "17912669-dd40-4843-b348-689b8f34f09d",
|
||||
"revision": 4,
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"description": "VPCS device",
|
||||
"id": 1,
|
||||
"label": {
|
||||
"color": "#ff000000",
|
||||
"font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
|
||||
"text": "PC1",
|
||||
"x": 18.5859375,
|
||||
"y": -25.0
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 1,
|
||||
"name": "Ethernet0",
|
||||
"port_number": 0
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"console": 5000,
|
||||
"name": "PC1",
|
||||
"startup_script_path": "startup.vpc"
|
||||
},
|
||||
"server_id": 2,
|
||||
"symbol": ":/symbols/vpcs_guest.svg",
|
||||
"type": "VPCSDevice",
|
||||
"vm_id": "992c28fd-4bc3-4508-9300-48600148f64a",
|
||||
"x": -128.5,
|
||||
"y": -51.5
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
{
|
||||
"host": "127.0.0.1",
|
||||
"id": 2,
|
||||
"local": true,
|
||||
"port": 3080,
|
||||
"protocol": "http",
|
||||
"vm": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "topology",
|
||||
"version": "1.5.1"
|
||||
}
|
@ -0,0 +1 @@
|
||||
set pcname PC1
|
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
@ -0,0 +1,52 @@
|
||||
{
|
||||
"auto_start": false,
|
||||
"name": "testsnapshot",
|
||||
"project_id": "17912669-dd40-4843-b348-689b8f34f09d",
|
||||
"revision": 4,
|
||||
"topology": {
|
||||
"nodes": [
|
||||
{
|
||||
"description": "VPCS device",
|
||||
"id": 1,
|
||||
"label": {
|
||||
"color": "#ff000000",
|
||||
"font": "TypeWriter,10,-1,5,75,0,0,0,0,0",
|
||||
"text": "PC1",
|
||||
"x": 18.5859375,
|
||||
"y": -25.0
|
||||
},
|
||||
"ports": [
|
||||
{
|
||||
"adapter_number": 0,
|
||||
"id": 1,
|
||||
"name": "Ethernet0",
|
||||
"port_number": 0
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"console": 5000,
|
||||
"name": "PC1",
|
||||
"startup_script_path": "startup.vpc"
|
||||
},
|
||||
"server_id": 2,
|
||||
"symbol": ":/symbols/vpcs_guest.svg",
|
||||
"type": "VPCSDevice",
|
||||
"vm_id": "992c28fd-4bc3-4508-9300-48600148f64a",
|
||||
"x": -128.5,
|
||||
"y": -51.5
|
||||
}
|
||||
],
|
||||
"servers": [
|
||||
{
|
||||
"host": "127.0.0.1",
|
||||
"id": 2,
|
||||
"local": true,
|
||||
"port": 3080,
|
||||
"protocol": "http",
|
||||
"vm": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": "topology",
|
||||
"version": "1.5.1"
|
||||
}
|
@ -0,0 +1 @@
|
||||
set pcname PC1
|
Loading…
Reference in New Issue
Block a user