1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +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",
"project_uuid": "a1e920ca-338a-4e9f-b363-aa607b09dd80",
"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 stat
import time
import aiohttp
import logging
log = logging.getLogger(__name__)

View File

@ -87,7 +87,7 @@ class BaseVM:
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):
"""

View File

@ -148,9 +148,9 @@ class PortManager:
continue
raise HTTPConflict(text="Could not find a free port between {} and {} on host {}, last exception: {}".format(start_port,
end_port,
host,
last_exception))
end_port,
host,
last_exception))
def get_free_console_port(self):
"""

View File

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

View File

@ -33,7 +33,6 @@ import shutil
from .virtualbox_error import VirtualBoxError
from ..adapters.ethernet_adapter import EthernetAdapter
from ..attic import find_unused_port
from .telnet_server import TelnetServer
from ..base_vm import BaseVM
@ -105,7 +104,6 @@ class VirtualBoxVM(BaseVM):
# create the device own working directory
self.working_dir = working_dir_path
if linked_clone:
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")

View File

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

View File

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

View File

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