1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Some quick cleaning.

This commit is contained in:
Jeremy 2015-01-19 14:43:35 -07:00
parent 345b471c47
commit fe22576ae2
6 changed files with 35 additions and 26 deletions

View File

@ -24,7 +24,6 @@ import os
import struct import struct
import socket import socket
import stat import stat
import errno
import time import time
import logging import logging

View File

@ -29,14 +29,16 @@ class BaseManager:
""" """
def __init__(self): def __init__(self):
self._vms = {} self._vms = {}
self._port_manager = None
@classmethod @classmethod
def instance(cls): def instance(cls):
""" """
Singleton to return only one instance of BaseManager. Singleton to return only one instance of BaseManager.
:returns: instance of Manager :returns: instance of BaseManager
""" """
if not hasattr(cls, "_instance") or cls._instance is None: if not hasattr(cls, "_instance") or cls._instance is None:
@ -55,11 +57,11 @@ class BaseManager:
@port_manager.setter @port_manager.setter
def port_manager(self, new_port_manager): def port_manager(self, new_port_manager):
self._port_manager = new_port_manager self._port_manager = new_port_manager
@classmethod @classmethod
@asyncio.coroutine @asyncio.coroutine # FIXME: why coroutine?
def destroy(cls): def destroy(cls):
cls._instance = None cls._instance = None

View File

@ -19,6 +19,7 @@ import socket
import ipaddress import ipaddress
import asyncio import asyncio
class PortManager: class PortManager:
""" """
:param host: IP address to bind for console connections :param host: IP address to bind for console connections
@ -55,8 +56,9 @@ class PortManager:
return cls._instance return cls._instance
@classmethod @classmethod
@asyncio.coroutine @asyncio.coroutine # FIXME: why coroutine?
def destroy(cls): def destroy(cls):
cls._instance = None cls._instance = None
@property @property

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2015 GNS3 Technologies Inc. # Copyright (C) 2015 GNS3 Technologies Inc.
@ -25,29 +24,35 @@ class Project:
""" """
A project contains a list of VM. A project contains a list of VM.
In theory VM are isolated project/project. In theory VM are isolated project/project.
"""
"""
:param uuid: Force project uuid (None by default auto generate an UUID) :param uuid: Force project uuid (None by default auto generate an UUID)
:param location: Parent path of the project. (None should create a tmp directory) :param location: Parent path of the project. (None should create a tmp directory)
""" """
def __init__(self, uuid = None, location = None):
def __init__(self, uuid=None, location=None):
if uuid is None: if uuid is None:
self.uuid = str(uuid4()) self._uuid = str(uuid4())
else: else:
self.uuid = uuid self._uuid = uuid
self.location = location self._location = location
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) self._path = os.path.join(self._location, self._uuid)
if os.path.exists(self.path) is False: if os.path.exists(self._path) is False:
os.mkdir(self.path) os.mkdir(self._path)
os.mkdir(os.path.join(self.path, 'files')) os.mkdir(os.path.join(self._path, 'files'))
@property
def uuid(self):
return self._uuid
def __json__(self): def __json__(self):
return { return {
"uuid": self.uuid, "uuid": self._uuid,
"location": self.location "location": self._location
} }

View File

@ -21,7 +21,7 @@ from .project import Project
class ProjectManager: class ProjectManager:
""" """
This singleton, keep track of available projects. This singleton keeps track of available projects.
""" """
def __init__(self): def __init__(self):
@ -30,9 +30,9 @@ class ProjectManager:
@classmethod @classmethod
def instance(cls): def instance(cls):
""" """
Singleton to return only one instance of BaseManager. Singleton to return only one instance of ProjectManager.
:returns: instance of Manager :returns: instance of ProjectManager
""" """
if not hasattr(cls, "_instance"): if not hasattr(cls, "_instance"):
@ -58,6 +58,7 @@ class ProjectManager:
See documentation of Project for arguments See documentation of Project for arguments
""" """
project = Project(**kwargs) project = Project(**kwargs)
self._projects[project.uuid] = project self._projects[project.uuid] = project
return project return project

View File

@ -193,10 +193,10 @@ class VPCSDevice(BaseVM):
flags = subprocess.CREATE_NEW_PROCESS_GROUP flags = subprocess.CREATE_NEW_PROCESS_GROUP
with open(self._vpcs_stdout_file, "w") as fd: with open(self._vpcs_stdout_file, "w") as fd:
self._process = yield from asyncio.create_subprocess_exec(*self._command, self._process = yield from asyncio.create_subprocess_exec(*self._command,
stdout=fd, stdout=fd,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
cwd=self._working_dir, cwd=self._working_dir,
creationflags=flags) creationflags=flags)
log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid)) log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid))
self._started = True self._started = True
except (OSError, subprocess.SubprocessError) as e: except (OSError, subprocess.SubprocessError) as e: