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

Fixes a few problems in Dynamips implementation.

This commit is contained in:
grossmj 2015-02-12 19:15:35 -07:00
parent 79a57ca420
commit 8f089c45f5
5 changed files with 34 additions and 18 deletions

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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)

View File

@ -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