Handle old projects.

This commit is contained in:
grossmj committed 2015-02-08 18:10:04 -07:00
1 parent 2a3b37a3bd
commit 0d7d0a05c3
6 files changed
+52 -11

No files matched your search

+15 -2
View File
@@ -22,12 +22,14 @@ import stat
import asyncio
import aiohttp
import socket
import shutil
import logging
log = logging.getLogger(__name__)
from uuid import UUID, uuid4
from ..config import Config
from ..utils.asyncio import wait_run_in_executor
from .project_manager import ProjectManager
from .nios.nio_udp import NIOUDP
@@ -157,9 +159,20 @@ class BaseManager:
project = ProjectManager.instance().get_project(project_id)
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)
# 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:
pass
+11
View File
@@ -127,3 +127,14 @@ class VirtualBox(BaseManager):
if not extra_data[0].strip() == "Value: yes":
vms.append(vmname)
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)
+11
View File
@@ -63,3 +63,14 @@ class VPCS(BaseManager):
"""
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)