Some quick cleaning.

pull/100/head
Jeremy 10 years ago
parent 345b471c47
commit fe22576ae2

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

@ -29,14 +29,16 @@ class BaseManager:
"""
def __init__(self):
self._vms = {}
self._port_manager = None
@classmethod
def instance(cls):
"""
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:
@ -55,11 +57,11 @@ class BaseManager:
@port_manager.setter
def port_manager(self, new_port_manager):
self._port_manager = new_port_manager
self._port_manager = new_port_manager
@classmethod
@asyncio.coroutine
@asyncio.coroutine # FIXME: why coroutine?
def destroy(cls):
cls._instance = None

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

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

@ -21,7 +21,7 @@ from .project import Project
class ProjectManager:
"""
This singleton, keep track of available projects.
This singleton keeps track of available projects.
"""
def __init__(self):
@ -30,9 +30,9 @@ class ProjectManager:
@classmethod
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"):
@ -58,6 +58,7 @@ class ProjectManager:
See documentation of Project for arguments
"""
project = Project(**kwargs)
self._projects[project.uuid] = project
return project

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

Loading…
Cancel
Save