diff --git a/gns3server/handlers/virtualbox_handler.py b/gns3server/handlers/virtualbox_handler.py index 78a0310a..209c68d3 100644 --- a/gns3server/handlers/virtualbox_handler.py +++ b/gns3server/handlers/virtualbox_handler.py @@ -62,10 +62,11 @@ class VirtualBoxHandler: 404: "VirtualBox VM instance doesn't exist" }, description="Start a VirtualBox VM instance") - def create(request, response): + def start(request, response): vbox_manager = VirtualBox.instance() - yield from vbox_manager.start_vm(request.match_info["uuid"]) + vm = vbox_manager.get_vm(request.match_info["uuid"]) + yield from vm.start() response.set_status(204) @classmethod @@ -80,8 +81,9 @@ class VirtualBoxHandler: 404: "VirtualBox VM instance doesn't exist" }, description="Stop a VirtualBox VM instance") - def create(request, response): + def stop(request, response): vbox_manager = VirtualBox.instance() - yield from vbox_manager.stop_vm(request.match_info["uuid"]) + vm = vbox_manager.get_vm(request.match_info["uuid"]) + yield from vm.stop() response.set_status(204) diff --git a/gns3server/handlers/vpcs_handler.py b/gns3server/handlers/vpcs_handler.py index 25fdcc2d..86ed9312 100644 --- a/gns3server/handlers/vpcs_handler.py +++ b/gns3server/handlers/vpcs_handler.py @@ -102,10 +102,11 @@ class VPCSHandler: 404: "VPCS instance doesn't exist" }, description="Start a VPCS instance") - def create(request, response): + def start(request, response): vpcs_manager = VPCS.instance() - yield from vpcs_manager.start_vm(request.match_info["uuid"]) + vm = vpcs_manager.get_vm(request.match_info["uuid"]) + yield from vm.start() response.set_status(204) @classmethod @@ -120,10 +121,11 @@ class VPCSHandler: 404: "VPCS instance doesn't exist" }, description="Stop a VPCS instance") - def create(request, response): + def stop(request, response): vpcs_manager = VPCS.instance() - yield from vpcs_manager.stop_vm(request.match_info["uuid"]) + vm = vpcs_manager.get_vm(request.match_info["uuid"]) + yield from vm.stop() response.set_status(204) @Route.post( diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 32423fba..402b9422 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -126,20 +126,9 @@ class BaseManager: uuid = str(uuid4()) vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs) - future = vm.create() - if isinstance(future, asyncio.Future): - yield from future + if asyncio.iscoroutinefunction(vm.create): + yield from vm.create() + else: + vm.create() self._vms[vm.uuid] = vm return vm - - @asyncio.coroutine - def start_vm(self, uuid): - - vm = self.get_vm(uuid) - yield from vm.start() - - @asyncio.coroutine - def stop_vm(self, uuid): - - vm = self.get_vm(uuid) - yield from vm.stop() diff --git a/gns3server/modules/base_vm.py b/gns3server/modules/base_vm.py index 3db4bb32..cd6a7aa4 100644 --- a/gns3server/modules/base_vm.py +++ b/gns3server/modules/base_vm.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - import logging log = logging.getLogger(__name__) @@ -29,9 +28,9 @@ class BaseVM: self._project = project self._manager = manager - log.info("{module}: {name} [{uuid}] has been created".format(module=self.manager.module_name, - name=self.name, - uuid=self.uuid)) + log.debug("{module}: {name} [{uuid}] initialized".format(module=self.manager.module_name, + name=self.name, + uuid=self.uuid)) # TODO: When delete release console ports @@ -63,10 +62,10 @@ class BaseVM: :param new_name: name """ - log.info("{module}: {name} [{uuid}]: renamed to {new_name}".format(module=self.manager.module_name, - name=self.name, - uuid=self.uuid, - new_name=new_name)) + log.info("{module}: {name} [{uuid}] renamed to {new_name}".format(module=self.manager.module_name, + name=self.name, + uuid=self.uuid, + new_name=new_name)) self._name = new_name @property @@ -102,7 +101,9 @@ class BaseVM: Creates the VM. """ - return + log.info("{module}: {name} [{uuid}] created".format(module=self.manager.module_name, + name=self.name, + uuid=self.uuid)) def start(self): """ diff --git a/gns3server/modules/project_manager.py b/gns3server/modules/project_manager.py index f44ab0fd..edcfe425 100644 --- a/gns3server/modules/project_manager.py +++ b/gns3server/modules/project_manager.py @@ -27,6 +27,7 @@ class ProjectManager: """ def __init__(self): + self._projects = {} @classmethod diff --git a/gns3server/web/logger.py b/gns3server/web/logger.py index d3b61dea..f2a51484 100644 --- a/gns3server/web/logger.py +++ b/gns3server/web/logger.py @@ -81,7 +81,7 @@ class ColouredStreamHandler(logging.StreamHandler): def init_logger(level, quiet=False): stream_handler = ColouredStreamHandler(sys.stdout) - stream_handler.formatter = ColouredFormatter("{asctime} {levelname:8} {filename}:{lineno}#RESET# {message}", "%Y-%m-%d %H:%M:%S", "{") + stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno}#RESET# {message}", "%Y-%m-%d %H:%M:%S", "{") if quiet: stream_handler.addFilter(logging.Filter(name="user_facing")) logging.getLogger('user_facing').propagate = False