mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-30 09:38:53 +00:00
Handle old projects.
This commit is contained in:
parent
2a3b37a3bd
commit
0d7d0a05c3
@ -22,12 +22,14 @@ import stat
|
|||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import socket
|
import socket
|
||||||
|
import shutil
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
|
from ..utils.asyncio import wait_run_in_executor
|
||||||
from .project_manager import ProjectManager
|
from .project_manager import ProjectManager
|
||||||
|
|
||||||
from .nios.nio_udp import NIOUDP
|
from .nios.nio_udp import NIOUDP
|
||||||
@ -157,9 +159,20 @@ class BaseManager:
|
|||||||
project = ProjectManager.instance().get_project(project_id)
|
project = ProjectManager.instance().get_project(project_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if vm_id:
|
if vm_id and hasattr(self, "get_legacy_vm_workdir_name"):
|
||||||
|
# move old project VM files to a new location
|
||||||
legacy_id = int(vm_id)
|
legacy_id = int(vm_id)
|
||||||
# TODO: support for old projects VM with normal IDs.
|
project_dir = os.path.dirname(project.path)
|
||||||
|
project_name = os.path.basename(project_dir)
|
||||||
|
project_files_dir = os.path.join(project_dir, "{}-files".format(project_name))
|
||||||
|
module_path = os.path.join(project_files_dir, self.module_name.lower())
|
||||||
|
vm_working_dir = os.path.join(module_path, self.get_legacy_vm_workdir_name(legacy_id))
|
||||||
|
vm_id = str(uuid4())
|
||||||
|
new_vm_working_dir = os.path.join(project.path, self.module_name.lower(), vm_id)
|
||||||
|
try:
|
||||||
|
yield from wait_run_in_executor(shutil.move, vm_working_dir, new_vm_working_dir)
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPInternalServerError(text="Could not move VM working directory: {}".format(e))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -127,3 +127,14 @@ class VirtualBox(BaseManager):
|
|||||||
if not extra_data[0].strip() == "Value: yes":
|
if not extra_data[0].strip() == "Value: yes":
|
||||||
vms.append(vmname)
|
vms.append(vmname)
|
||||||
return vms
|
return vms
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_legacy_vm_workdir_name(legacy_vm_id):
|
||||||
|
"""
|
||||||
|
Returns the name of the legacy working directory name for a VM.
|
||||||
|
|
||||||
|
:param legacy_vm_id: legacy VM identifier (integer)
|
||||||
|
:returns: working directory name
|
||||||
|
"""
|
||||||
|
|
||||||
|
return "vm-{}".format(legacy_vm_id)
|
||||||
|
@ -63,3 +63,14 @@ class VPCS(BaseManager):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return self._used_mac_ids.get(vm_id, 1)
|
return self._used_mac_ids.get(vm_id, 1)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_legacy_vm_workdir_name(legacy_vm_id):
|
||||||
|
"""
|
||||||
|
Returns the name of the legacy working directory name for a VM.
|
||||||
|
|
||||||
|
:param legacy_vm_id: legacy VM identifier (integer)
|
||||||
|
:returns: working directory name
|
||||||
|
"""
|
||||||
|
|
||||||
|
return "pc-{}".format(legacy_vm_id)
|
||||||
|
@ -23,10 +23,13 @@ VBOX_CREATE_SCHEMA = {
|
|||||||
"properties": {
|
"properties": {
|
||||||
"vm_id": {
|
"vm_id": {
|
||||||
"description": "VirtualBox VM instance identifier",
|
"description": "VirtualBox VM instance identifier",
|
||||||
"type": "string",
|
"oneOf": [
|
||||||
|
{"type": "string",
|
||||||
"minLength": 36,
|
"minLength": 36,
|
||||||
"maxLength": 36,
|
"maxLength": 36,
|
||||||
"pattern": "(^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}|\d+)$"
|
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"},
|
||||||
|
{"type": "integer"} # for legacy projects
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"linked_clone": {
|
"linked_clone": {
|
||||||
"description": "either the VM is a linked clone or not",
|
"description": "either the VM is a linked clone or not",
|
||||||
|
@ -28,10 +28,13 @@ VPCS_CREATE_SCHEMA = {
|
|||||||
},
|
},
|
||||||
"vm_id": {
|
"vm_id": {
|
||||||
"description": "VPCS VM identifier",
|
"description": "VPCS VM identifier",
|
||||||
"type": "string",
|
"oneOf": [
|
||||||
|
{"type": "string",
|
||||||
"minLength": 36,
|
"minLength": 36,
|
||||||
"maxLength": 36,
|
"maxLength": 36,
|
||||||
"pattern": "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}|\d+)$"
|
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"},
|
||||||
|
{"type": "integer"} # for legacy projects
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"console": {
|
"console": {
|
||||||
"description": "console TCP port",
|
"description": "console TCP port",
|
||||||
|
@ -23,7 +23,7 @@ import asyncio
|
|||||||
def wait_run_in_executor(func, *args):
|
def wait_run_in_executor(func, *args):
|
||||||
"""
|
"""
|
||||||
Run blocking code in a different thread and wait
|
Run blocking code in a different thread and wait
|
||||||
the result.
|
for the result.
|
||||||
|
|
||||||
:param func: Run this function in a different thread
|
:param func: Run this function in a different thread
|
||||||
:param args: Parameters of the function
|
:param args: Parameters of the function
|
||||||
|
Loading…
Reference in New Issue
Block a user