1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Fix project path

This commit is contained in:
Julien Duponchelle 2015-01-21 11:33:24 +01:00
parent ba91cbaac0
commit df31b2ad5a
9 changed files with 18 additions and 18 deletions

View File

@ -20,5 +20,5 @@ X-ROUTE: /vpcs
"name": "PC TEST 1", "name": "PC TEST 1",
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80", "project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
"script_file": null, "script_file": null,
"uuid": "934f0745-0824-451e-8ad6-db0877dbf387" "uuid": "21e9a130-450e-41e4-8864-e5c83ba7aa80"
} }

View File

@ -25,6 +25,7 @@ import struct
import socket import socket
import stat import stat
import time import time
import aiohttp
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -87,7 +87,7 @@ class BaseVM:
Return VM working directory Return VM working directory
""" """
return self._project.vm_working_directory(self._uuid) return self._project.vm_working_directory(self.module_name, self._uuid)
def create(self): def create(self):
""" """

View File

@ -45,11 +45,9 @@ class Project:
if location is None: if location is None:
self._location = tempfile.mkdtemp() self._location = tempfile.mkdtemp()
self._path = os.path.join(self._location, self._uuid, "vms") self._path = os.path.join(self._location, self._uuid)
try: try:
os.makedirs(self._path) os.makedirs(os.path.join(self._path, 'vms'), exist_ok=True)
except FileExistsError:
pass
except OSError as e: except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e)) raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
@ -68,22 +66,23 @@ class Project:
return self._path return self._path
def vm_working_directory(self, vm_uuid): def vm_working_directory(self, module, vm_uuid):
""" """
Return a working directory for a specific VM. Return a working directory for a specific VM.
If the directory doesn't exist, the directory is created. If the directory doesn't exist, the directory is created.
:param module: The module name (vpcs, dynamips...)
:param vm_uuid: VM UUID :param vm_uuid: VM UUID
""" """
path = os.path.join(self._path, "vms", vm_uuid) p = os.path.join(self._path, "vms", module, vm_uuid)
try: try:
os.makedirs(self._path) os.makedirs(p, exist_ok=True)
except FileExistsError: except FileExistsError:
pass pass
except OSError as e: except OSError as e:
raise aiohttp.web.HTTPInternalServerError(text="Could not create VM working directory: {}".format(e)) raise aiohttp.web.HTTPInternalServerError(text="Could not create VM working directory: {}".format(e))
return path return p
def __json__(self): def __json__(self):

View File

@ -33,7 +33,6 @@ import shutil
from .virtualbox_error import VirtualBoxError from .virtualbox_error import VirtualBoxError
from ..adapters.ethernet_adapter import EthernetAdapter from ..adapters.ethernet_adapter import EthernetAdapter
from ..attic import find_unused_port
from .telnet_server import TelnetServer from .telnet_server import TelnetServer
from ..base_vm import BaseVM from ..base_vm import BaseVM
@ -105,7 +104,6 @@ class VirtualBoxVM(BaseVM):
# create the device own working directory # create the device own working directory
self.working_dir = working_dir_path self.working_dir = working_dir_path
if linked_clone: if linked_clone:
if vbox_id and os.path.isdir(os.path.join(self.working_dir, self._vmname)): if vbox_id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox") vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")

View File

@ -43,6 +43,7 @@ log = logging.getLogger(__name__)
class VPCSVM(BaseVM): class VPCSVM(BaseVM):
module_name = 'vpcs'
""" """
VPCS vm implementation. VPCS vm implementation.

View File

@ -151,11 +151,12 @@ def server(request, loop):
port = _get_unused_port() port = _get_unused_port()
host = "localhost" host = "localhost"
app = web.Application() app = web.Application()
port_manager = PortManager("127.0.0.1", False)
for method, route, handler in Route.get_routes(): for method, route, handler in Route.get_routes():
app.router.add_route(method, route, handler) app.router.add_route(method, route, handler)
for module in MODULES: for module in MODULES:
instance = module.instance() instance = module.instance()
instance.port_manager = PortManager("127.0.0.1", False) instance.port_manager = port_manager
srv = loop.create_server(app.make_handler(), host, port) srv = loop.create_server(app.make_handler(), host, port)
srv = loop.run_until_complete(srv) srv = loop.run_until_complete(srv)

View File

@ -47,5 +47,5 @@ def test_json(tmpdir):
def test_vm_working_directory(tmpdir): def test_vm_working_directory(tmpdir):
p = Project(location=str(tmpdir)) p = Project(location=str(tmpdir))
assert os.path.exists(p.vm_working_directory('00010203-0405-0607-0809-0a0b0c0d0e0f')) assert os.path.exists(p.vm_working_directory('vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms', '00010203-0405-0607-0809-0a0b0c0d0e0f')) assert os.path.exists(os.path.join(str(tmpdir), p.uuid, 'vms', 'vpcs', '00010203-0405-0607-0809-0a0b0c0d0e0f'))