diff --git a/gns3server/handlers/dynamips_handler.py b/gns3server/handlers/dynamips_handler.py index 0b0be6a1..e3ed5d95 100644 --- a/gns3server/handlers/dynamips_handler.py +++ b/gns3server/handlers/dynamips_handler.py @@ -54,14 +54,15 @@ class DynamipsHandler: request.json.get("dynamips_id"), request.json.pop("platform")) - # set VM options + # set VM settings for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: - setter = getattr(vm, "set_{}".format(name)) - if asyncio.iscoroutinefunction(vm.close): - yield from setter(value) - else: - setter(value) + if hasattr(vm, "set_{}".format(name)): + setter = getattr(vm, "set_{}".format(name)) + if asyncio.iscoroutinefunction(vm.close): + yield from setter(value) + else: + setter(value) response.set_status(201) response.json(vm) @@ -107,10 +108,14 @@ class DynamipsHandler: dynamips_manager = Dynamips.instance() vm = dynamips_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"]) - # FIXME: set options - #for name, value in request.json.items(): - # if hasattr(vm, name) and getattr(vm, name) != value: - # setattr(vm, name, value) + # set VM settings + for name, value in request.json.items(): + if hasattr(vm, name) and getattr(vm, name) != value: + setter = getattr(vm, "set_{}".format(name)) + if asyncio.iscoroutinefunction(vm.close): + yield from setter(value) + else: + setter(value) response.json(vm) @classmethod diff --git a/gns3server/modules/dynamips/dynamips_error.py b/gns3server/modules/dynamips/dynamips_error.py index 58c306ee..0f64dff6 100644 --- a/gns3server/modules/dynamips/dynamips_error.py +++ b/gns3server/modules/dynamips/dynamips_error.py @@ -19,8 +19,10 @@ Custom exceptions for Dynamips module. """ +from ..vm_error import VMError -class DynamipsError(Exception): + +class DynamipsError(VMError): def __init__(self, message, original_exception=None): diff --git a/gns3server/modules/dynamips/dynamips_hypervisor.py b/gns3server/modules/dynamips/dynamips_hypervisor.py index 9a1fb6f4..01a92248 100644 --- a/gns3server/modules/dynamips/dynamips_hypervisor.py +++ b/gns3server/modules/dynamips/dynamips_hypervisor.py @@ -128,8 +128,9 @@ class DynamipsHypervisor: """ yield from self.send("hypervisor stop") + yield from self._writer.drain() self._writer.close() - self._reader, self._writer = None + self._reader = self._writer = None self._nio_udp_auto_instances.clear() @asyncio.coroutine diff --git a/gns3server/modules/dynamips/hypervisor.py b/gns3server/modules/dynamips/hypervisor.py index 87e05f75..57afb37a 100644 --- a/gns3server/modules/dynamips/hypervisor.py +++ b/gns3server/modules/dynamips/hypervisor.py @@ -128,7 +128,7 @@ class Hypervisor(DynamipsHypervisor): if self.is_running(): log.info("Stopping Dynamips process PID={}".format(self._process.pid)) - DynamipsHypervisor.stop(self) + yield from DynamipsHypervisor.stop(self) # give some time for the hypervisor to properly stop. # time to delete UNIX NIOs for instance. yield from asyncio.sleep(0.01) diff --git a/gns3server/modules/dynamips/nodes/router.py b/gns3server/modules/dynamips/nodes/router.py index a2ca1f4b..e8c05618 100644 --- a/gns3server/modules/dynamips/nodes/router.py +++ b/gns3server/modules/dynamips/nodes/router.py @@ -27,7 +27,6 @@ import asyncio import time import sys import os -import base64 import logging log = logging.getLogger(__name__) @@ -232,7 +231,7 @@ class Router(BaseVM): if elf_header_start != b'\x7fELF\x01\x02\x01': raise DynamipsError('"{}" is not a valid IOS image'.format(self._image)) - yield from self._hypervisor.send('vm start "{}"'.format(self._name)) + yield from self._hypervisor.send('vm start "{name}"'.format(name=self._name)) log.info('router "{name}" [{id}] has been started'.format(name=self._name, id=self._id)) @asyncio.coroutine @@ -243,9 +242,18 @@ class Router(BaseVM): status = yield from self.get_status() if status != "inactive": - yield from self._hypervisor.send('vm stop "{name}"'.format(self._name)) + yield from self._hypervisor.send('vm stop "{name}"'.format(name=self._name)) log.info('Router "{name}" [{id}] has been stopped'.format(name=self._name, id=self._id)) + @asyncio.coroutine + def reload(self): + """ + Reload this router. + """ + + yield from self.stop() + yield from self.start() + @asyncio.coroutine def suspend(self): """ @@ -254,7 +262,7 @@ class Router(BaseVM): status = yield from self.get_status() if status == "running": - yield from self._hypervisor.send('vm suspend "{}"'.format(self._name)) + yield from self._hypervisor.send('vm suspend "{name}"'.format(name=self._name)) log.info('Router "{name}" [{id}] has been suspended'.format(name=self._name, id=self._id)) @asyncio.coroutine @@ -263,7 +271,7 @@ class Router(BaseVM): Resumes this suspended router """ - yield from self._hypervisor.send('vm resume "{}"'.format(self._name)) + yield from self._hypervisor.send('vm resume "{name}"'.format(name=self._name)) log.info('Router "{name}" [{id}] has been resumed'.format(name=self._name, id=self._id)) @asyncio.coroutine