mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Drop Python 3.4 and switch to async / await syntax for asyncio. Fixes #1425
This commit is contained in:
1 parent
8baa480b79
commit
76af98404a
119 files changed
+2432
-3084
No files matched your search
@@ -34,9 +34,8 @@ import re
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from gns3server.utils.interfaces import interfaces, is_interface_up
|
||||
from gns3server.utils.asyncio import wait_run_in_executor, asyncio_ensure_future
|
||||
from gns3server.utils.asyncio import wait_run_in_executor
|
||||
from gns3server.utils import parse_version
|
||||
from gns3server.utils.asyncio import asyncio_ensure_future
|
||||
from uuid import uuid4
|
||||
from ..base_manager import BaseManager
|
||||
from ..port_manager import PortManager
|
||||
@@ -166,17 +165,16 @@ class Dynamips(BaseManager):
|
||||
if dynamips_id in self._dynamips_ids[project_id]:
|
||||
self._dynamips_ids[project_id].remove(dynamips_id)
|
||||
|
||||
@asyncio.coroutine
|
||||
def unload(self):
|
||||
async def unload(self):
|
||||
|
||||
yield from BaseManager.unload(self)
|
||||
await BaseManager.unload(self)
|
||||
|
||||
tasks = []
|
||||
for device in self._devices.values():
|
||||
tasks.append(asyncio_ensure_future(device.hypervisor.stop()))
|
||||
tasks.append(asyncio.ensure_future(device.hypervisor.stop()))
|
||||
|
||||
if tasks:
|
||||
done, _ = yield from asyncio.wait(tasks)
|
||||
done, _ = await asyncio.wait(tasks)
|
||||
for future in done:
|
||||
try:
|
||||
future.result()
|
||||
@@ -184,37 +182,35 @@ class Dynamips(BaseManager):
|
||||
log.error("Could not stop device hypervisor {}".format(e), exc_info=1)
|
||||
continue
|
||||
|
||||
@asyncio.coroutine
|
||||
def project_closing(self, project):
|
||||
async def project_closing(self, project):
|
||||
"""
|
||||
Called when a project is about to be closed.
|
||||
|
||||
:param project: Project instance
|
||||
"""
|
||||
|
||||
yield from super().project_closing(project)
|
||||
await super().project_closing(project)
|
||||
# delete the Dynamips devices corresponding to the project
|
||||
tasks = []
|
||||
for device in self._devices.values():
|
||||
if device.project.id == project.id:
|
||||
tasks.append(asyncio_ensure_future(device.delete()))
|
||||
tasks.append(asyncio.ensure_future(device.delete()))
|
||||
|
||||
if tasks:
|
||||
done, _ = yield from asyncio.wait(tasks)
|
||||
done, _ = await asyncio.wait(tasks)
|
||||
for future in done:
|
||||
try:
|
||||
future.result()
|
||||
except (Exception, GeneratorExit) as e:
|
||||
log.error("Could not delete device {}".format(e), exc_info=1)
|
||||
|
||||
@asyncio.coroutine
|
||||
def project_closed(self, project):
|
||||
async def project_closed(self, project):
|
||||
"""
|
||||
Called when a project is closed.
|
||||
|
||||
:param project: Project instance
|
||||
"""
|
||||
yield from super().project_closed(project)
|
||||
await super().project_closed(project)
|
||||
# delete useless Dynamips files
|
||||
project_dir = project.module_working_path(self.module_name.lower())
|
||||
|
||||
@@ -230,7 +226,7 @@ class Dynamips(BaseManager):
|
||||
log.debug("Deleting file {}".format(file))
|
||||
if file in self._ghost_files:
|
||||
self._ghost_files.remove(file)
|
||||
yield from wait_run_in_executor(os.remove, file)
|
||||
await wait_run_in_executor(os.remove, file)
|
||||
except OSError as e:
|
||||
log.warning("Could not delete file {}: {}".format(file, e))
|
||||
continue
|
||||
@@ -267,8 +263,7 @@ class Dynamips(BaseManager):
|
||||
self._dynamips_path = dynamips_path
|
||||
return dynamips_path
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_new_hypervisor(self, working_dir=None):
|
||||
async def start_new_hypervisor(self, working_dir=None):
|
||||
"""
|
||||
Creates a new Dynamips process and start it.
|
||||
|
||||
@@ -306,27 +301,25 @@ class Dynamips(BaseManager):
|
||||
hypervisor = Hypervisor(self._dynamips_path, working_dir, server_host, port, port_manager.console_host)
|
||||
|
||||
log.info("Creating new hypervisor {}:{} with working directory {}".format(hypervisor.host, hypervisor.port, working_dir))
|
||||
yield from hypervisor.start()
|
||||
await hypervisor.start()
|
||||
log.info("Hypervisor {}:{} has successfully started".format(hypervisor.host, hypervisor.port))
|
||||
yield from hypervisor.connect()
|
||||
await hypervisor.connect()
|
||||
if parse_version(hypervisor.version) < parse_version('0.2.11'):
|
||||
raise DynamipsError("Dynamips version must be >= 0.2.11, detected version is {}".format(hypervisor.version))
|
||||
|
||||
return hypervisor
|
||||
|
||||
@asyncio.coroutine
|
||||
def ghost_ios_support(self, vm):
|
||||
async def ghost_ios_support(self, vm):
|
||||
|
||||
ghost_ios_support = self.config.get_section_config("Dynamips").getboolean("ghost_ios_support", True)
|
||||
if ghost_ios_support:
|
||||
with (yield from Dynamips._ghost_ios_lock):
|
||||
async with Dynamips._ghost_ios_lock:
|
||||
try:
|
||||
yield from self._set_ghost_ios(vm)
|
||||
await self._set_ghost_ios(vm)
|
||||
except GeneratorExit:
|
||||
log.warning("Could not create ghost IOS image {} (GeneratorExit)".format(vm.name))
|
||||
|
||||
@asyncio.coroutine
|
||||
def create_nio(self, node, nio_settings):
|
||||
async def create_nio(self, node, nio_settings):
|
||||
"""
|
||||
Creates a new NIO.
|
||||
|
||||
@@ -394,11 +387,10 @@ class Dynamips(BaseManager):
|
||||
else:
|
||||
raise aiohttp.web.HTTPConflict(text="NIO of type {} is not supported".format(nio_settings["type"]))
|
||||
|
||||
yield from nio.create()
|
||||
await nio.create()
|
||||
return nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def _set_ghost_ios(self, vm):
|
||||
async def _set_ghost_ios(self, vm):
|
||||
"""
|
||||
Manages Ghost IOS support.
|
||||
|
||||
@@ -421,29 +413,28 @@ class Dynamips(BaseManager):
|
||||
ghost_id = str(uuid4())
|
||||
ghost = Router("ghost-" + ghost_file, ghost_id, vm.project, vm.manager, platform=vm.platform, hypervisor=vm.hypervisor, ghost_flag=True)
|
||||
try:
|
||||
yield from ghost.create()
|
||||
yield from ghost.set_image(vm.image)
|
||||
yield from ghost.set_ghost_status(1)
|
||||
yield from ghost.set_ghost_file(ghost_file_path)
|
||||
yield from ghost.set_ram(vm.ram)
|
||||
await ghost.create()
|
||||
await ghost.set_image(vm.image)
|
||||
await ghost.set_ghost_status(1)
|
||||
await ghost.set_ghost_file(ghost_file_path)
|
||||
await ghost.set_ram(vm.ram)
|
||||
try:
|
||||
yield from ghost.start()
|
||||
yield from ghost.stop()
|
||||
await ghost.start()
|
||||
await ghost.stop()
|
||||
self._ghost_files.add(ghost_file_path)
|
||||
except DynamipsError:
|
||||
raise
|
||||
finally:
|
||||
yield from ghost.clean_delete()
|
||||
await ghost.clean_delete()
|
||||
except DynamipsError as e:
|
||||
log.warning("Could not create ghost instance: {}".format(e))
|
||||
|
||||
if vm.ghost_file != ghost_file and os.path.isfile(ghost_file_path):
|
||||
# set the ghost file to the router
|
||||
yield from vm.set_ghost_status(2)
|
||||
yield from vm.set_ghost_file(ghost_file_path)
|
||||
await vm.set_ghost_status(2)
|
||||
await vm.set_ghost_file(ghost_file_path)
|
||||
|
||||
@asyncio.coroutine
|
||||
def update_vm_settings(self, vm, settings):
|
||||
async def update_vm_settings(self, vm, settings):
|
||||
"""
|
||||
Updates the VM settings.
|
||||
|
||||
@@ -455,23 +446,23 @@ class Dynamips(BaseManager):
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
if hasattr(vm, "set_{}".format(name)):
|
||||
setter = getattr(vm, "set_{}".format(name))
|
||||
yield from setter(value)
|
||||
await setter(value)
|
||||
elif name.startswith("slot") and value in ADAPTER_MATRIX:
|
||||
slot_id = int(name[-1])
|
||||
adapter_name = value
|
||||
adapter = ADAPTER_MATRIX[adapter_name]()
|
||||
try:
|
||||
if vm.slots[slot_id] and not isinstance(vm.slots[slot_id], type(adapter)):
|
||||
yield from vm.slot_remove_binding(slot_id)
|
||||
await vm.slot_remove_binding(slot_id)
|
||||
if not isinstance(vm.slots[slot_id], type(adapter)):
|
||||
yield from vm.slot_add_binding(slot_id, adapter)
|
||||
await vm.slot_add_binding(slot_id, adapter)
|
||||
except IndexError:
|
||||
raise DynamipsError("Slot {} doesn't exist on this router".format(slot_id))
|
||||
elif name.startswith("slot") and (value is None or value is ""):
|
||||
slot_id = int(name[-1])
|
||||
try:
|
||||
if vm.slots[slot_id]:
|
||||
yield from vm.slot_remove_binding(slot_id)
|
||||
await vm.slot_remove_binding(slot_id)
|
||||
except IndexError:
|
||||
raise DynamipsError("Slot {} doesn't exist on this router".format(slot_id))
|
||||
elif name.startswith("wic") and value in WIC_MATRIX:
|
||||
@@ -480,32 +471,31 @@ class Dynamips(BaseManager):
|
||||
wic = WIC_MATRIX[wic_name]()
|
||||
try:
|
||||
if vm.slots[0].wics[wic_slot_id] and not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
|
||||
yield from vm.uninstall_wic(wic_slot_id)
|
||||
await vm.uninstall_wic(wic_slot_id)
|
||||
if not isinstance(vm.slots[0].wics[wic_slot_id], type(wic)):
|
||||
yield from vm.install_wic(wic_slot_id, wic)
|
||||
await vm.install_wic(wic_slot_id, wic)
|
||||
except IndexError:
|
||||
raise DynamipsError("WIC slot {} doesn't exist on this router".format(wic_slot_id))
|
||||
elif name.startswith("wic") and (value is None or value is ""):
|
||||
wic_slot_id = int(name[-1])
|
||||
try:
|
||||
if vm.slots[0].wics and vm.slots[0].wics[wic_slot_id]:
|
||||
yield from vm.uninstall_wic(wic_slot_id)
|
||||
await vm.uninstall_wic(wic_slot_id)
|
||||
except IndexError:
|
||||
raise DynamipsError("WIC slot {} doesn't exist on this router".format(wic_slot_id))
|
||||
|
||||
mmap_support = self.config.get_section_config("Dynamips").getboolean("mmap_support", True)
|
||||
if mmap_support is False:
|
||||
yield from vm.set_mmap(False)
|
||||
await vm.set_mmap(False)
|
||||
|
||||
sparse_memory_support = self.config.get_section_config("Dynamips").getboolean("sparse_memory_support", True)
|
||||
if sparse_memory_support is False:
|
||||
yield from vm.set_sparsemem(False)
|
||||
await vm.set_sparsemem(False)
|
||||
|
||||
# update the configs if needed
|
||||
yield from self.set_vm_configs(vm, settings)
|
||||
await self.set_vm_configs(vm, settings)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_vm_configs(self, vm, settings):
|
||||
async def set_vm_configs(self, vm, settings):
|
||||
"""
|
||||
Set VM configs from pushed content or existing config files.
|
||||
|
||||
@@ -554,25 +544,24 @@ class Dynamips(BaseManager):
|
||||
|
||||
return os.path.join("configs", os.path.basename(path))
|
||||
|
||||
@asyncio.coroutine
|
||||
def auto_idlepc(self, vm):
|
||||
async def auto_idlepc(self, vm):
|
||||
"""
|
||||
Try to find the best possible idle-pc value.
|
||||
|
||||
:param vm: VM instance
|
||||
"""
|
||||
|
||||
yield from vm.set_idlepc("0x0")
|
||||
await vm.set_idlepc("0x0")
|
||||
was_auto_started = False
|
||||
old_priority = None
|
||||
try:
|
||||
status = yield from vm.get_status()
|
||||
status = await vm.get_status()
|
||||
if status != "running":
|
||||
yield from vm.start()
|
||||
await vm.start()
|
||||
was_auto_started = True
|
||||
yield from asyncio.sleep(20) # leave time to the router to boot
|
||||
await asyncio.sleep(20) # leave time to the router to boot
|
||||
validated_idlepc = None
|
||||
idlepcs = yield from vm.get_idle_pc_prop()
|
||||
idlepcs = await vm.get_idle_pc_prop()
|
||||
if not idlepcs:
|
||||
raise DynamipsError("No Idle-PC values found")
|
||||
|
||||
@@ -582,14 +571,14 @@ class Dynamips(BaseManager):
|
||||
match = re.search(r"^0x[0-9a-f]{8}$", idlepc.split()[0])
|
||||
if not match:
|
||||
continue
|
||||
yield from vm.set_idlepc(idlepc.split()[0])
|
||||
await vm.set_idlepc(idlepc.split()[0])
|
||||
log.debug("Auto Idle-PC: trying idle-PC value {}".format(vm.idlepc))
|
||||
start_time = time.time()
|
||||
initial_cpu_usage = yield from vm.get_cpu_usage()
|
||||
initial_cpu_usage = await vm.get_cpu_usage()
|
||||
log.debug("Auto Idle-PC: initial CPU usage is {}%".format(initial_cpu_usage))
|
||||
yield from asyncio.sleep(3) # wait 3 seconds to probe the cpu again
|
||||
await asyncio.sleep(3) # wait 3 seconds to probe the cpu again
|
||||
elapsed_time = time.time() - start_time
|
||||
cpu_usage = yield from vm.get_cpu_usage()
|
||||
cpu_usage = await vm.get_cpu_usage()
|
||||
cpu_elapsed_usage = cpu_usage - initial_cpu_usage
|
||||
cpu_usage = abs(cpu_elapsed_usage * 100.0 / elapsed_time)
|
||||
if cpu_usage > 100:
|
||||
@@ -609,11 +598,10 @@ class Dynamips(BaseManager):
|
||||
if old_priority is not None:
|
||||
vm.set_process_priority_windows(vm.hypervisor.process.pid, old_priority)
|
||||
if was_auto_started:
|
||||
yield from vm.stop()
|
||||
await vm.stop()
|
||||
return validated_idlepc
|
||||
|
||||
@asyncio.coroutine
|
||||
def duplicate_node(self, source_node_id, destination_node_id):
|
||||
async def duplicate_node(self, source_node_id, destination_node_id):
|
||||
"""
|
||||
Duplicate a node
|
||||
|
||||
@@ -626,7 +614,7 @@ class Dynamips(BaseManager):
|
||||
|
||||
# Not a Dynamips router
|
||||
if not hasattr(source_node, "startup_config_path"):
|
||||
return (yield from super().duplicate_node(source_node_id, destination_node_id))
|
||||
return (await super().duplicate_node(source_node_id, destination_node_id))
|
||||
|
||||
try:
|
||||
with open(source_node.startup_config_path) as f:
|
||||
@@ -638,13 +626,13 @@ class Dynamips(BaseManager):
|
||||
private_config = f.read()
|
||||
except OSError:
|
||||
private_config = None
|
||||
yield from self.set_vm_configs(destination_node, {
|
||||
await self.set_vm_configs(destination_node, {
|
||||
"startup_config_content": startup_config,
|
||||
"private_config_content": private_config
|
||||
})
|
||||
|
||||
# Force refresh of the name in configuration files
|
||||
new_name = destination_node.name
|
||||
yield from destination_node.set_name(source_node.name)
|
||||
yield from destination_node.set_name(new_name)
|
||||
await destination_node.set_name(source_node.name)
|
||||
await destination_node.set_name(new_name)
|
||||
return destination_node
|
||||
@@ -59,8 +59,7 @@ class DynamipsHypervisor:
|
||||
self._writer = None
|
||||
self._io_lock = asyncio.Lock()
|
||||
|
||||
@asyncio.coroutine
|
||||
def connect(self, timeout=10):
|
||||
async def connect(self, timeout=10):
|
||||
"""
|
||||
Connects to the hypervisor.
|
||||
"""
|
||||
@@ -78,9 +77,9 @@ class DynamipsHypervisor:
|
||||
connection_success = False
|
||||
last_exception = None
|
||||
while time.time() - begin < timeout:
|
||||
yield from asyncio.sleep(0.01)
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
self._reader, self._writer = yield from asyncio.wait_for(asyncio.open_connection(host, self._port), timeout=1)
|
||||
self._reader, self._writer = await asyncio.wait_for(asyncio.open_connection(host, self._port), timeout=1)
|
||||
except (asyncio.TimeoutError, OSError) as e:
|
||||
last_exception = e
|
||||
continue
|
||||
@@ -93,13 +92,13 @@ class DynamipsHypervisor:
|
||||
log.info("Connected to Dynamips hypervisor on {}:{} after {:.4f} seconds".format(host, self._port, time.time() - begin))
|
||||
|
||||
try:
|
||||
version = yield from self.send("hypervisor version")
|
||||
version = await self.send("hypervisor version")
|
||||
self._version = version[0].split("-", 1)[0]
|
||||
except IndexError:
|
||||
self._version = "Unknown"
|
||||
|
||||
# this forces to send the working dir to Dynamips
|
||||
yield from self.set_working_dir(self._working_dir)
|
||||
await self.set_working_dir(self._working_dir)
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
@@ -111,45 +110,41 @@ class DynamipsHypervisor:
|
||||
|
||||
return self._version
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
"""
|
||||
Closes the connection to this hypervisor (but leave it running).
|
||||
"""
|
||||
|
||||
yield from self.send("hypervisor close")
|
||||
await self.send("hypervisor close")
|
||||
self._writer.close()
|
||||
self._reader, self._writer = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self):
|
||||
async def stop(self):
|
||||
"""
|
||||
Stops this hypervisor (will no longer run).
|
||||
"""
|
||||
|
||||
try:
|
||||
# try to properly stop the hypervisor
|
||||
yield from self.send("hypervisor stop")
|
||||
await self.send("hypervisor stop")
|
||||
except DynamipsError:
|
||||
pass
|
||||
try:
|
||||
if self._writer is not None:
|
||||
yield from self._writer.drain()
|
||||
await self._writer.drain()
|
||||
self._writer.close()
|
||||
except OSError as e:
|
||||
log.debug("Stopping hypervisor {}:{} {}".format(self._host, self._port, e))
|
||||
self._reader = self._writer = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def reset(self):
|
||||
async def reset(self):
|
||||
"""
|
||||
Resets this hypervisor (used to get an empty configuration).
|
||||
"""
|
||||
|
||||
yield from self.send("hypervisor reset")
|
||||
await self.send("hypervisor reset")
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_working_dir(self, working_dir):
|
||||
async def set_working_dir(self, working_dir):
|
||||
"""
|
||||
Sets the working directory for this hypervisor.
|
||||
|
||||
@@ -157,7 +152,7 @@ class DynamipsHypervisor:
|
||||
"""
|
||||
|
||||
# encase working_dir in quotes to protect spaces in the path
|
||||
yield from self.send('hypervisor working_dir "{}"'.format(working_dir))
|
||||
await self.send('hypervisor working_dir "{}"'.format(working_dir))
|
||||
self._working_dir = working_dir
|
||||
log.debug("Working directory set to {}".format(self._working_dir))
|
||||
|
||||
@@ -221,8 +216,7 @@ class DynamipsHypervisor:
|
||||
|
||||
self._host = host
|
||||
|
||||
@asyncio.coroutine
|
||||
def send(self, command):
|
||||
async def send(self, command):
|
||||
"""
|
||||
Sends commands to this hypervisor.
|
||||
|
||||
@@ -244,7 +238,7 @@ class DynamipsHypervisor:
|
||||
# but still have more data. The only thing we know for sure is the last line
|
||||
# will begin with '100-' or a '2xx-' and end with '\r\n'
|
||||
|
||||
with (yield from self._io_lock):
|
||||
async with self._io_lock:
|
||||
if self._writer is None or self._reader is None:
|
||||
raise DynamipsError("Not connected")
|
||||
|
||||
@@ -252,7 +246,7 @@ class DynamipsHypervisor:
|
||||
command = command.strip() + '\n'
|
||||
log.debug("sending {}".format(command))
|
||||
self._writer.write(command.encode())
|
||||
yield from self._writer.drain()
|
||||
await self._writer.drain()
|
||||
except OSError as e:
|
||||
raise DynamipsError("Could not send Dynamips command '{command}' to {host}:{port}: {error}, process running: {run}"
|
||||
.format(command=command.strip(), host=self._host, port=self._port, error=e, run=self.is_running()))
|
||||
@@ -265,8 +259,8 @@ class DynamipsHypervisor:
|
||||
while True:
|
||||
try:
|
||||
try:
|
||||
# line = yield from self._reader.readline() # this can lead to ValueError: Line is too long
|
||||
chunk = yield from self._reader.read(1024) # match to Dynamips' buffer size
|
||||
# line = await self._reader.readline() # this can lead to ValueError: Line is too long
|
||||
chunk = await self._reader.read(1024) # match to Dynamips' buffer size
|
||||
except asyncio.CancelledError:
|
||||
# task has been canceled but continue to read
|
||||
# any remaining data sent by the hypervisor
|
||||
@@ -283,7 +277,7 @@ class DynamipsHypervisor:
|
||||
.format(host=self._host, port=self._port, run=self.is_running()))
|
||||
else:
|
||||
retries += 1
|
||||
yield from asyncio.sleep(0.1)
|
||||
await asyncio.sleep(0.1)
|
||||
continue
|
||||
retries = 0
|
||||
buf += chunk.decode("utf-8", errors="ignore")
|
||||
|
||||
@@ -111,8 +111,7 @@ class Hypervisor(DynamipsHypervisor):
|
||||
|
||||
self._path = path
|
||||
|
||||
@asyncio.coroutine
|
||||
def start(self):
|
||||
async def start(self):
|
||||
"""
|
||||
Starts the Dynamips hypervisor process.
|
||||
"""
|
||||
@@ -129,7 +128,7 @@ class Hypervisor(DynamipsHypervisor):
|
||||
self._stdout_file = os.path.join(self.working_dir, "dynamips_i{}_stdout.txt".format(self._id))
|
||||
log.info("Dynamips process logging to {}".format(self._stdout_file))
|
||||
with open(self._stdout_file, "w", encoding="utf-8") as fd:
|
||||
self._process = yield from asyncio.create_subprocess_exec(*self._command,
|
||||
self._process = await asyncio.create_subprocess_exec(*self._command,
|
||||
stdout=fd,
|
||||
stderr=subprocess.STDOUT,
|
||||
cwd=self._working_dir,
|
||||
@@ -140,20 +139,19 @@ class Hypervisor(DynamipsHypervisor):
|
||||
log.error("Could not start Dynamips: {}".format(e))
|
||||
raise DynamipsError("Could not start Dynamips: {}".format(e))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop(self):
|
||||
async def stop(self):
|
||||
"""
|
||||
Stops the Dynamips hypervisor process.
|
||||
"""
|
||||
|
||||
if self.is_running():
|
||||
log.info("Stopping Dynamips process PID={}".format(self._process.pid))
|
||||
yield from DynamipsHypervisor.stop(self)
|
||||
await 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)
|
||||
await asyncio.sleep(0.01)
|
||||
try:
|
||||
yield from wait_for_process_termination(self._process, timeout=3)
|
||||
await wait_for_process_termination(self._process, timeout=3)
|
||||
except asyncio.TimeoutError:
|
||||
if self._process.returncode is None:
|
||||
log.warning("Dynamips process {} is still running... killing it".format(self._process.pid))
|
||||
|
||||
@@ -48,53 +48,48 @@ class NIO:
|
||||
self._output_filter_options = None # no output filter options by default
|
||||
self._dynamips_direction = {"in": 0, "out": 1, "both": 2}
|
||||
|
||||
@asyncio.coroutine
|
||||
def list(self):
|
||||
async def list(self):
|
||||
"""
|
||||
Returns all NIOs.
|
||||
|
||||
:returns: NIO list
|
||||
"""
|
||||
|
||||
nio_list = yield from self._hypervisor.send("nio list")
|
||||
nio_list = await self._hypervisor.send("nio list")
|
||||
return nio_list
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
async def delete(self):
|
||||
"""
|
||||
Deletes this NIO.
|
||||
"""
|
||||
|
||||
if self._input_filter or self._output_filter:
|
||||
yield from self.unbind_filter("both")
|
||||
yield from self._hypervisor.send("nio delete {}".format(self._name))
|
||||
await self.unbind_filter("both")
|
||||
await self._hypervisor.send("nio delete {}".format(self._name))
|
||||
log.info("NIO {name} has been deleted".format(name=self._name))
|
||||
|
||||
@asyncio.coroutine
|
||||
def rename(self, new_name):
|
||||
async def rename(self, new_name):
|
||||
"""
|
||||
Renames this NIO
|
||||
|
||||
:param new_name: new NIO name
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send("nio rename {name} {new_name}".format(name=self._name, new_name=new_name))
|
||||
await self._hypervisor.send("nio rename {name} {new_name}".format(name=self._name, new_name=new_name))
|
||||
|
||||
log.info("NIO {name} renamed to {new_name}".format(name=self._name, new_name=new_name))
|
||||
self._name = new_name
|
||||
|
||||
@asyncio.coroutine
|
||||
def debug(self, debug):
|
||||
async def debug(self, debug):
|
||||
"""
|
||||
Enables/Disables debugging for this NIO.
|
||||
|
||||
:param debug: debug value (0 = disable, enable = 1)
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send("nio set_debug {name} {debug}".format(name=self._name, debug=debug))
|
||||
await self._hypervisor.send("nio set_debug {name} {debug}".format(name=self._name, debug=debug))
|
||||
|
||||
@asyncio.coroutine
|
||||
def bind_filter(self, direction, filter_name):
|
||||
async def bind_filter(self, direction, filter_name):
|
||||
"""
|
||||
Adds a packet filter to this NIO.
|
||||
Filter "freq_drop" drops packets.
|
||||
@@ -108,7 +103,7 @@ class NIO:
|
||||
raise DynamipsError("Unknown direction {} to bind filter {}:".format(direction, filter_name))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
yield from self._hypervisor.send("nio bind_filter {name} {direction} {filter}".format(name=self._name,
|
||||
await self._hypervisor.send("nio bind_filter {name} {direction} {filter}".format(name=self._name,
|
||||
direction=dynamips_direction,
|
||||
filter=filter_name))
|
||||
|
||||
@@ -120,8 +115,7 @@ class NIO:
|
||||
self._input_filter = filter_name
|
||||
self._output_filter = filter_name
|
||||
|
||||
@asyncio.coroutine
|
||||
def unbind_filter(self, direction):
|
||||
async def unbind_filter(self, direction):
|
||||
"""
|
||||
Removes packet filter for this NIO.
|
||||
|
||||
@@ -132,7 +126,7 @@ class NIO:
|
||||
raise DynamipsError("Unknown direction {} to unbind filter:".format(direction))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
yield from self._hypervisor.send("nio unbind_filter {name} {direction}".format(name=self._name,
|
||||
await self._hypervisor.send("nio unbind_filter {name} {direction}".format(name=self._name,
|
||||
direction=dynamips_direction))
|
||||
|
||||
if direction == "in":
|
||||
@@ -143,8 +137,7 @@ class NIO:
|
||||
self._input_filter = None
|
||||
self._output_filter = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def setup_filter(self, direction, options):
|
||||
async def setup_filter(self, direction, options):
|
||||
"""
|
||||
Setups a packet filter bound with this NIO.
|
||||
|
||||
@@ -166,7 +159,7 @@ class NIO:
|
||||
raise DynamipsError("Unknown direction {} to setup filter:".format(direction))
|
||||
dynamips_direction = self._dynamips_direction[direction]
|
||||
|
||||
yield from self._hypervisor.send("nio setup_filter {name} {direction} {options}".format(name=self._name,
|
||||
await self._hypervisor.send("nio setup_filter {name} {direction} {options}".format(name=self._name,
|
||||
direction=dynamips_direction,
|
||||
options=options))
|
||||
|
||||
@@ -198,24 +191,22 @@ class NIO:
|
||||
|
||||
return self._output_filter, self._output_filter_options
|
||||
|
||||
@asyncio.coroutine
|
||||
def get_stats(self):
|
||||
async def get_stats(self):
|
||||
"""
|
||||
Gets statistics for this NIO.
|
||||
|
||||
:returns: NIO statistics (string with packets in, packets out, bytes in, bytes out)
|
||||
"""
|
||||
|
||||
stats = yield from self._hypervisor.send("nio get_stats {}".format(self._name))
|
||||
stats = await self._hypervisor.send("nio get_stats {}".format(self._name))
|
||||
return stats[0]
|
||||
|
||||
@asyncio.coroutine
|
||||
def reset_stats(self):
|
||||
async def reset_stats(self):
|
||||
"""
|
||||
Resets statistics for this NIO.
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send("nio reset_stats {}".format(self._name))
|
||||
await self._hypervisor.send("nio reset_stats {}".format(self._name))
|
||||
|
||||
@property
|
||||
def bandwidth(self):
|
||||
@@ -227,15 +218,14 @@ class NIO:
|
||||
|
||||
return self._bandwidth
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_bandwidth(self, bandwidth):
|
||||
async def set_bandwidth(self, bandwidth):
|
||||
"""
|
||||
Sets bandwidth constraint.
|
||||
|
||||
:param bandwidth: bandwidth integer value (in Kb/s)
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send("nio set_bandwidth {name} {bandwidth}".format(name=self._name, bandwidth=bandwidth))
|
||||
await self._hypervisor.send("nio set_bandwidth {name} {bandwidth}".format(name=self._name, bandwidth=bandwidth))
|
||||
self._bandwidth = bandwidth
|
||||
|
||||
@property
|
||||
|
||||
@@ -43,10 +43,9 @@ class NIOGenericEthernet(NIO):
|
||||
self._ethernet_device = ethernet_device
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_gen_eth {name} {eth_device}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_gen_eth {name} {eth_device}".format(name=self._name,
|
||||
eth_device=self._ethernet_device))
|
||||
|
||||
log.info("NIO Generic Ethernet {name} created with device {device}".format(name=self._name,
|
||||
|
||||
@@ -42,10 +42,9 @@ class NIOLinuxEthernet(NIO):
|
||||
self._ethernet_device = ethernet_device
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_linux_eth {name} {eth_device}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_linux_eth {name} {eth_device}".format(name=self._name,
|
||||
eth_device=self._ethernet_device))
|
||||
|
||||
log.info("NIO Linux Ethernet {name} created with device {device}".format(name=self._name,
|
||||
|
||||
@@ -41,10 +41,9 @@ class NIONull(NIO):
|
||||
name = 'null-{}'.format(uuid.uuid4())
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_null {}".format(self._name))
|
||||
await self._hypervisor.send("nio create_null {}".format(self._name))
|
||||
log.info("NIO NULL {name} created.".format(name=self._name))
|
||||
|
||||
def __json__(self):
|
||||
|
||||
@@ -43,10 +43,9 @@ class NIOTAP(NIO):
|
||||
self._tap_device = tap_device
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_tap {name} {tap}".format(name=self._name, tap=self._tap_device))
|
||||
await self._hypervisor.send("nio create_tap {name} {tap}".format(name=self._name, tap=self._tap_device))
|
||||
log.info("NIO TAP {name} created with device {device}".format(name=self._name, device=self._tap_device))
|
||||
|
||||
@property
|
||||
|
||||
@@ -53,13 +53,12 @@ class NIOUDP(NIO):
|
||||
self._node = node
|
||||
super().__init__(name, node.hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
if not self._hypervisor:
|
||||
return
|
||||
# Ubridge is not supported
|
||||
if not hasattr(self._node, "add_ubridge_udp_connection"):
|
||||
yield from self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
|
||||
lport=self._lport,
|
||||
rhost=self._rhost,
|
||||
rport=self._rport))
|
||||
@@ -67,7 +66,7 @@ class NIOUDP(NIO):
|
||||
self._local_tunnel_lport = self._node.manager.port_manager.get_free_udp_port(self._node.project)
|
||||
self._local_tunnel_rport = self._node.manager.port_manager.get_free_udp_port(self._node.project)
|
||||
self._bridge_name = 'DYNAMIPS-{}-{}'.format(self._local_tunnel_lport, self._local_tunnel_rport)
|
||||
yield from self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
|
||||
lport=self._local_tunnel_lport,
|
||||
rhost='127.0.0.1',
|
||||
rport=self._local_tunnel_rport))
|
||||
@@ -84,24 +83,22 @@ class NIOUDP(NIO):
|
||||
self._rhost,
|
||||
self._rport)
|
||||
self._destination_nio.filters = self._filters
|
||||
yield from self._node.add_ubridge_udp_connection(
|
||||
await self._node.add_ubridge_udp_connection(
|
||||
self._bridge_name,
|
||||
self._source_nio,
|
||||
self._destination_nio
|
||||
)
|
||||
|
||||
@asyncio.coroutine
|
||||
def update(self):
|
||||
async def update(self):
|
||||
self._destination_nio.filters = self._filters
|
||||
yield from self._node.update_ubridge_udp_connection(
|
||||
await self._node.update_ubridge_udp_connection(
|
||||
self._bridge_name,
|
||||
self._source_nio,
|
||||
self._destination_nio)
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
if self._local_tunnel_lport:
|
||||
yield from self._node.ubridge_delete_bridge(self._bridge_name)
|
||||
await self._node.ubridge_delete_bridge(self._bridge_name)
|
||||
self._node.manager.port_manager.release_udp_port(self._local_tunnel_lport, self ._node.project)
|
||||
if self._local_tunnel_rport:
|
||||
self._node.manager.port_manager.release_udp_port(self._local_tunnel_rport, self._node.project)
|
||||
|
||||
@@ -45,10 +45,9 @@ class NIOUNIX(NIO):
|
||||
self._remote_file = remote_file
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_unix {name} {local} {remote}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_unix {name} {local} {remote}".format(name=self._name,
|
||||
local=self._local_file,
|
||||
remote=self._remote_file))
|
||||
|
||||
|
||||
@@ -45,10 +45,9 @@ class NIOVDE(NIO):
|
||||
self._local_file = local_file
|
||||
super().__init__(name, hypervisor)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from self._hypervisor.send("nio create_vde {name} {control} {local}".format(name=self._name,
|
||||
await self._hypervisor.send("nio create_vde {name} {control} {local}".format(name=self._name,
|
||||
control=self._control_file,
|
||||
local=self._local_file))
|
||||
|
||||
|
||||
@@ -64,26 +64,24 @@ class ATMSwitch(Device):
|
||||
"mappings": mappings,
|
||||
"status": "started"}
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
if self._hypervisor is None:
|
||||
module_workdir = self.project.module_working_directory(self.manager.module_name.lower())
|
||||
self._hypervisor = yield from self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
self._hypervisor = await self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
|
||||
yield from self._hypervisor.send('atmsw create "{}"'.format(self._name))
|
||||
await self._hypervisor.send('atmsw create "{}"'.format(self._name))
|
||||
log.info('ATM switch "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||
self._hypervisor.devices.append(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_name(self, new_name):
|
||||
async def set_name(self, new_name):
|
||||
"""
|
||||
Renames this ATM switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('atm rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
await self._hypervisor.send('atm rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
log.info('ATM switch "{name}" [{id}]: renamed to "{new_name}"'.format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
@@ -119,31 +117,29 @@ class ATMSwitch(Device):
|
||||
|
||||
self._mappings = mappings
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
for nio in self._nios.values():
|
||||
if nio:
|
||||
yield from nio.close()
|
||||
await nio.close()
|
||||
|
||||
if self._hypervisor:
|
||||
try:
|
||||
yield from self._hypervisor.send('atmsw delete "{}"'.format(self._name))
|
||||
await self._hypervisor.send('atmsw delete "{}"'.format(self._name))
|
||||
log.info('ATM switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
|
||||
except DynamipsError:
|
||||
log.debug("Could not properly delete ATM switch {}".format(self._name))
|
||||
if self._hypervisor and self in self._hypervisor.devices:
|
||||
self._hypervisor.devices.remove(self)
|
||||
if self._hypervisor and not self._hypervisor.devices:
|
||||
yield from self.hypervisor.stop()
|
||||
await self.hypervisor.stop()
|
||||
self._hypervisor = None
|
||||
return True
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
async def delete(self):
|
||||
"""
|
||||
Deletes this ATM switch.
|
||||
"""
|
||||
yield from self.close()
|
||||
await self.close()
|
||||
|
||||
def has_port(self, port):
|
||||
"""
|
||||
@@ -156,8 +152,7 @@ class ATMSwitch(Device):
|
||||
return True
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_nio(self, nio, port_number):
|
||||
async def add_nio(self, nio, port_number):
|
||||
"""
|
||||
Adds a NIO as new port on ATM switch.
|
||||
|
||||
@@ -174,10 +169,9 @@ class ATMSwitch(Device):
|
||||
port=port_number))
|
||||
|
||||
self._nios[port_number] = nio
|
||||
yield from self.set_mappings(self._mappings)
|
||||
await self.set_mappings(self._mappings)
|
||||
|
||||
@asyncio.coroutine
|
||||
def remove_nio(self, port_number):
|
||||
async def remove_nio(self, port_number):
|
||||
"""
|
||||
Removes the specified NIO as member of this ATM switch.
|
||||
|
||||
@@ -202,8 +196,8 @@ class ATMSwitch(Device):
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_vci))
|
||||
yield from self.unmap_pvc(source_port, source_vpi, source_vci, destination_port, destination_vpi, destination_vci)
|
||||
yield from self.unmap_pvc(destination_port, destination_vpi, destination_vci, source_port, source_vpi, source_vci)
|
||||
await self.unmap_pvc(source_port, source_vpi, source_vci, destination_port, destination_vpi, destination_vci)
|
||||
await self.unmap_pvc(destination_port, destination_vpi, destination_vci, source_port, source_vpi, source_vci)
|
||||
else:
|
||||
# remove the virtual paths mapped with this port/nio
|
||||
source_port, source_vpi = source
|
||||
@@ -215,8 +209,8 @@ class ATMSwitch(Device):
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi))
|
||||
yield from self.unmap_vp(source_port, source_vpi, destination_port, destination_vpi)
|
||||
yield from self.unmap_vp(destination_port, destination_vpi, source_port, source_vpi)
|
||||
await self.unmap_vp(source_port, source_vpi, destination_port, destination_vpi)
|
||||
await self.unmap_vp(destination_port, destination_vpi, source_port, source_vpi)
|
||||
|
||||
nio = self._nios[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
@@ -229,8 +223,7 @@ class ATMSwitch(Device):
|
||||
del self._nios[port_number]
|
||||
return nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_mappings(self, mappings):
|
||||
async def set_mappings(self, mappings):
|
||||
"""
|
||||
Applies VC mappings
|
||||
|
||||
@@ -258,8 +251,8 @@ class ATMSwitch(Device):
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_vci))
|
||||
yield from self.map_pvc(source_port, source_vpi, source_vci, destination_port, destination_vpi, destination_vci)
|
||||
yield from self.map_pvc(destination_port, destination_vpi, destination_vci, source_port, source_vpi, source_vci)
|
||||
await self.map_pvc(source_port, source_vpi, source_vci, destination_port, destination_vpi, destination_vci)
|
||||
await self.map_pvc(destination_port, destination_vpi, destination_vci, source_port, source_vpi, source_vci)
|
||||
else:
|
||||
# add the virtual paths
|
||||
source_port, source_vpi = map(int, source.split(':'))
|
||||
@@ -272,11 +265,10 @@ class ATMSwitch(Device):
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi))
|
||||
yield from self.map_vp(source_port, source_vpi, destination_port, destination_vpi)
|
||||
yield from self.map_vp(destination_port, destination_vpi, source_port, source_vpi)
|
||||
await self.map_vp(source_port, source_vpi, destination_port, destination_vpi)
|
||||
await self.map_vp(destination_port, destination_vpi, source_port, source_vpi)
|
||||
|
||||
@asyncio.coroutine
|
||||
def map_vp(self, port1, vpi1, port2, vpi2):
|
||||
async def map_vp(self, port1, vpi1, port2, vpi2):
|
||||
"""
|
||||
Creates a new Virtual Path connection.
|
||||
|
||||
@@ -295,7 +287,7 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('atmsw create_vpc "{name}" {input_nio} {input_vpi} {output_nio} {output_vpi}'.format(name=self._name,
|
||||
await self._hypervisor.send('atmsw create_vpc "{name}" {input_nio} {input_vpi} {output_nio} {output_vpi}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
output_nio=nio2,
|
||||
@@ -310,8 +302,7 @@ class ATMSwitch(Device):
|
||||
|
||||
self._active_mappings[(port1, vpi1)] = (port2, vpi2)
|
||||
|
||||
@asyncio.coroutine
|
||||
def unmap_vp(self, port1, vpi1, port2, vpi2):
|
||||
async def unmap_vp(self, port1, vpi1, port2, vpi2):
|
||||
"""
|
||||
Deletes a new Virtual Path connection.
|
||||
|
||||
@@ -330,7 +321,7 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('atmsw delete_vpc "{name}" {input_nio} {input_vpi} {output_nio} {output_vpi}'.format(name=self._name,
|
||||
await self._hypervisor.send('atmsw delete_vpc "{name}" {input_nio} {input_vpi} {output_nio} {output_vpi}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
output_nio=nio2,
|
||||
@@ -345,8 +336,7 @@ class ATMSwitch(Device):
|
||||
|
||||
del self._active_mappings[(port1, vpi1)]
|
||||
|
||||
@asyncio.coroutine
|
||||
def map_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
async def map_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
"""
|
||||
Creates a new Virtual Channel connection (unidirectional).
|
||||
|
||||
@@ -367,7 +357,7 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('atmsw create_vcc "{name}" {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}'.format(name=self._name,
|
||||
await self._hypervisor.send('atmsw create_vcc "{name}" {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
input_vci=vci1,
|
||||
@@ -386,8 +376,7 @@ class ATMSwitch(Device):
|
||||
|
||||
self._active_mappings[(port1, vpi1, vci1)] = (port2, vpi2, vci2)
|
||||
|
||||
@asyncio.coroutine
|
||||
def unmap_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
async def unmap_pvc(self, port1, vpi1, vci1, port2, vpi2, vci2):
|
||||
"""
|
||||
Deletes a new Virtual Channel connection (unidirectional).
|
||||
|
||||
@@ -408,7 +397,7 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('atmsw delete_vcc "{name}" {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}'.format(name=self._name,
|
||||
await self._hypervisor.send('atmsw delete_vcc "{name}" {input_nio} {input_vpi} {input_vci} {output_nio} {output_vpi} {output_vci}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_vpi=vpi1,
|
||||
input_vci=vci1,
|
||||
@@ -426,8 +415,7 @@ class ATMSwitch(Device):
|
||||
vci2=vci2))
|
||||
del self._active_mappings[(port1, vpi1, vci1)]
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_capture(self, port_number, output_file, data_link_type="DLT_ATM_RFC1483"):
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_ATM_RFC1483"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
@@ -448,15 +436,14 @@ class ATMSwitch(Device):
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port_number))
|
||||
|
||||
yield from nio.bind_filter("both", "capture")
|
||||
yield from nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
await nio.bind_filter("both", "capture")
|
||||
await nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
|
||||
log.info('ATM switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, port_number):
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
@@ -467,7 +454,7 @@ class ATMSwitch(Device):
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
nio = self._nios[port_number]
|
||||
yield from nio.unbind_filter("both")
|
||||
await nio.unbind_filter("both")
|
||||
log.info('ATM switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
@@ -41,25 +41,23 @@ class Bridge(Device):
|
||||
super().__init__(name, node_id, project, manager, hypervisor)
|
||||
self._nios = []
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
if self._hypervisor is None:
|
||||
module_workdir = self.project.module_working_directory(self.manager.module_name.lower())
|
||||
self._hypervisor = yield from self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
self._hypervisor = await self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
|
||||
yield from self._hypervisor.send('nio_bridge create "{}"'.format(self._name))
|
||||
await self._hypervisor.send('nio_bridge create "{}"'.format(self._name))
|
||||
self._hypervisor.devices.append(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_name(self, new_name):
|
||||
async def set_name(self, new_name):
|
||||
"""
|
||||
Renames this bridge.
|
||||
|
||||
:param new_name: New name for this bridge
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('nio_bridge rename "{name}" "{new_name}"'.format(name=self._name,
|
||||
await self._hypervisor.send('nio_bridge rename "{name}" "{new_name}"'.format(name=self._name,
|
||||
new_name=new_name))
|
||||
|
||||
self._name = new_name
|
||||
@@ -74,8 +72,7 @@ class Bridge(Device):
|
||||
|
||||
return self._nios
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
async def delete(self):
|
||||
"""
|
||||
Deletes this bridge.
|
||||
"""
|
||||
@@ -83,28 +80,26 @@ class Bridge(Device):
|
||||
if self._hypervisor and self in self._hypervisor.devices:
|
||||
self._hypervisor.devices.remove(self)
|
||||
if self._hypervisor and not self._hypervisor.devices:
|
||||
yield from self._hypervisor.send('nio_bridge delete "{}"'.format(self._name))
|
||||
await self._hypervisor.send('nio_bridge delete "{}"'.format(self._name))
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_nio(self, nio):
|
||||
async def add_nio(self, nio):
|
||||
"""
|
||||
Adds a NIO as new port on this bridge.
|
||||
|
||||
:param nio: NIO instance to add
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('nio_bridge add_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
await self._hypervisor.send('nio_bridge add_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
self._nios.append(nio)
|
||||
|
||||
@asyncio.coroutine
|
||||
def remove_nio(self, nio):
|
||||
async def remove_nio(self, nio):
|
||||
"""
|
||||
Removes the specified NIO as member of this bridge.
|
||||
|
||||
:param nio: NIO instance to remove
|
||||
"""
|
||||
if self._hypervisor:
|
||||
yield from self._hypervisor.send('nio_bridge remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
await self._hypervisor.send('nio_bridge remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
self._nios.remove(nio)
|
||||
|
||||
@property
|
||||
|
||||
@@ -70,12 +70,11 @@ class C1700(Router):
|
||||
router_info.update(c1700_router_info)
|
||||
return router_info
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from Router.create(self)
|
||||
await Router.create(self)
|
||||
if self._chassis != "1720":
|
||||
yield from self.set_chassis(self._chassis)
|
||||
await self.set_chassis(self._chassis)
|
||||
self._setup_chassis()
|
||||
|
||||
def _setup_chassis(self):
|
||||
@@ -103,8 +102,7 @@ class C1700(Router):
|
||||
|
||||
return self._chassis
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_chassis(self, chassis):
|
||||
async def set_chassis(self, chassis):
|
||||
"""
|
||||
Sets the chassis.
|
||||
|
||||
@@ -112,7 +110,7 @@ class C1700(Router):
|
||||
1720, 1721, 1750, 1751 or 1760
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c1700 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
await self._hypervisor.send('c1700 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -131,15 +129,14 @@ class C1700(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Sets I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c1700 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c1700 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -85,12 +85,11 @@ class C2600(Router):
|
||||
router_info.update(c2600_router_info)
|
||||
return router_info
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from Router.create(self)
|
||||
await Router.create(self)
|
||||
if self._chassis != "2610":
|
||||
yield from self.set_chassis(self._chassis)
|
||||
await self.set_chassis(self._chassis)
|
||||
self._setup_chassis()
|
||||
|
||||
def _setup_chassis(self):
|
||||
@@ -112,8 +111,7 @@ class C2600(Router):
|
||||
|
||||
return self._chassis
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_chassis(self, chassis):
|
||||
async def set_chassis(self, chassis):
|
||||
"""
|
||||
Sets the chassis.
|
||||
|
||||
@@ -122,7 +120,7 @@ class C2600(Router):
|
||||
2620XM, 2621XM, 2650XM or 2651XM
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c2600 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
await self._hypervisor.send('c2600 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -140,15 +138,14 @@ class C2600(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Sets I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c2600 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c2600 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -79,15 +79,14 @@ class C2691(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Sets I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c2691 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c2691 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -66,12 +66,11 @@ class C3600(Router):
|
||||
router_info.update(c3600_router_info)
|
||||
return router_info
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from Router.create(self)
|
||||
await Router.create(self)
|
||||
if self._chassis != "3640":
|
||||
yield from self.set_chassis(self._chassis)
|
||||
await self.set_chassis(self._chassis)
|
||||
self._setup_chassis()
|
||||
|
||||
def _setup_chassis(self):
|
||||
@@ -98,15 +97,14 @@ class C3600(Router):
|
||||
|
||||
return self._chassis
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_chassis(self, chassis):
|
||||
async def set_chassis(self, chassis):
|
||||
"""
|
||||
Sets the chassis.
|
||||
|
||||
:param: chassis string: 3620, 3640 or 3660
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c3600 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
await self._hypervisor.send('c3600 set_chassis "{name}" {chassis}'.format(name=self._name, chassis=chassis))
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -125,15 +123,14 @@ class C3600(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Set I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c3600 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c3600 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -79,15 +79,14 @@ class C3725(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Sets I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c3725 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c3725 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -79,15 +79,14 @@ class C3745(Router):
|
||||
|
||||
return self._iomem
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_iomem(self, iomem):
|
||||
async def set_iomem(self, iomem):
|
||||
"""
|
||||
Sets I/O memory size for this router.
|
||||
|
||||
:param iomem: I/O memory size
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c3745 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
await self._hypervisor.send('c3745 set_iomem "{name}" {size}'.format(name=self._name, size=iomem))
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -86,19 +86,18 @@ class C7200(Router):
|
||||
router_info.update(c7200_router_info)
|
||||
return router_info
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from Router.create(self)
|
||||
await Router.create(self)
|
||||
|
||||
if self._npe != "npe-400":
|
||||
yield from self.set_npe(self._npe)
|
||||
await self.set_npe(self._npe)
|
||||
|
||||
# first slot is a mandatory Input/Output controller (based on NPE type)
|
||||
if self.npe == "npe-g2":
|
||||
yield from self.slot_add_binding(0, C7200_IO_GE_E())
|
||||
await self.slot_add_binding(0, C7200_IO_GE_E())
|
||||
else:
|
||||
yield from self.slot_add_binding(0, C7200_IO_FE())
|
||||
await self.slot_add_binding(0, C7200_IO_FE())
|
||||
|
||||
@property
|
||||
def npe(self):
|
||||
@@ -110,8 +109,7 @@ class C7200(Router):
|
||||
|
||||
return self._npe
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_npe(self, npe):
|
||||
async def set_npe(self, npe):
|
||||
"""
|
||||
Sets the NPE model.
|
||||
|
||||
@@ -120,10 +118,10 @@ class C7200(Router):
|
||||
npe-225, npe-300, npe-400 and npe-g2 (PowerPC c7200 only)
|
||||
"""
|
||||
|
||||
if (yield from self.is_running()):
|
||||
if (await self.is_running()):
|
||||
raise DynamipsError("Cannot change NPE on running router")
|
||||
|
||||
yield from self._hypervisor.send('c7200 set_npe "{name}" {npe}'.format(name=self._name, npe=npe))
|
||||
await self._hypervisor.send('c7200 set_npe "{name}" {npe}'.format(name=self._name, npe=npe))
|
||||
|
||||
log.info('Router "{name}" [{id}]: NPE updated from {old_npe} to {new_npe}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -141,15 +139,14 @@ class C7200(Router):
|
||||
|
||||
return self._midplane
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_midplane(self, midplane):
|
||||
async def set_midplane(self, midplane):
|
||||
"""
|
||||
Sets the midplane model.
|
||||
|
||||
:returns: midplane model string (e.g. "vxr" or "std")
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('c7200 set_midplane "{name}" {midplane}'.format(name=self._name, midplane=midplane))
|
||||
await self._hypervisor.send('c7200 set_midplane "{name}" {midplane}'.format(name=self._name, midplane=midplane))
|
||||
|
||||
log.info('Router "{name}" [{id}]: midplane updated from {old_midplane} to {new_midplane}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -167,8 +164,7 @@ class C7200(Router):
|
||||
|
||||
return self._sensors
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_sensors(self, sensors):
|
||||
async def set_sensors(self, sensors):
|
||||
"""
|
||||
Sets the 4 sensors with temperature in degree Celcius.
|
||||
|
||||
@@ -182,7 +178,7 @@ class C7200(Router):
|
||||
|
||||
sensor_id = 0
|
||||
for sensor in sensors:
|
||||
yield from self._hypervisor.send('c7200 set_temp_sensor "{name}" {sensor_id} {temp}'.format(name=self._name,
|
||||
await self._hypervisor.send('c7200 set_temp_sensor "{name}" {sensor_id} {temp}'.format(name=self._name,
|
||||
sensor_id=sensor_id,
|
||||
temp=sensor))
|
||||
|
||||
@@ -205,8 +201,7 @@ class C7200(Router):
|
||||
|
||||
return self._power_supplies
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_power_supplies(self, power_supplies):
|
||||
async def set_power_supplies(self, power_supplies):
|
||||
"""
|
||||
Sets the 2 power supplies with 0 = off, 1 = on.
|
||||
|
||||
@@ -216,7 +211,7 @@ class C7200(Router):
|
||||
|
||||
power_supply_id = 0
|
||||
for power_supply in power_supplies:
|
||||
yield from self._hypervisor.send('c7200 set_power_supply "{name}" {power_supply_id} {powered_on}'.format(name=self._name,
|
||||
await self._hypervisor.send('c7200 set_power_supply "{name}" {power_supply_id} {powered_on}'.format(name=self._name,
|
||||
power_supply_id=power_supply_id,
|
||||
powered_on=power_supply))
|
||||
|
||||
@@ -228,8 +223,7 @@ class C7200(Router):
|
||||
|
||||
self._power_supplies = power_supplies
|
||||
|
||||
@asyncio.coroutine
|
||||
def start(self):
|
||||
async def start(self):
|
||||
"""
|
||||
Starts this router.
|
||||
At least the IOS image must be set before starting it.
|
||||
@@ -237,8 +231,8 @@ class C7200(Router):
|
||||
|
||||
# trick: we must send sensors and power supplies info after starting the router
|
||||
# otherwise they are not taken into account (Dynamips bug?)
|
||||
yield from Router.start(self)
|
||||
await Router.start(self)
|
||||
if self._sensors != [22, 22, 22, 22]:
|
||||
yield from self.set_sensors(self._sensors)
|
||||
await self.set_sensors(self._sensors)
|
||||
if self._power_supplies != [1, 1]:
|
||||
yield from self.set_power_supplies(self._power_supplies)
|
||||
await self.set_power_supplies(self._power_supplies)
|
||||
@@ -93,10 +93,9 @@ class EthernetHub(Bridge):
|
||||
|
||||
self._ports = ports
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
yield from Bridge.create(self)
|
||||
await Bridge.create(self)
|
||||
log.info('Ethernet hub "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||
|
||||
@property
|
||||
@@ -109,32 +108,29 @@ class EthernetHub(Bridge):
|
||||
|
||||
return self._mappings
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
return (yield from self.close())
|
||||
async def delete(self):
|
||||
return (await self.close())
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
"""
|
||||
Deletes this hub.
|
||||
"""
|
||||
|
||||
for nio in self._nios:
|
||||
if nio:
|
||||
yield from nio.close()
|
||||
await nio.close()
|
||||
|
||||
try:
|
||||
yield from Bridge.delete(self)
|
||||
await Bridge.delete(self)
|
||||
log.info('Ethernet hub "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
|
||||
except DynamipsError:
|
||||
log.debug("Could not properly delete Ethernet hub {}".format(self._name))
|
||||
if self._hypervisor and not self._hypervisor.devices:
|
||||
yield from self.hypervisor.stop()
|
||||
await self.hypervisor.stop()
|
||||
self._hypervisor = None
|
||||
return True
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_nio(self, nio, port_number):
|
||||
async def add_nio(self, nio, port_number):
|
||||
"""
|
||||
Adds a NIO as new port on this hub.
|
||||
|
||||
@@ -148,7 +144,7 @@ class EthernetHub(Bridge):
|
||||
if port_number in self._mappings:
|
||||
raise DynamipsError("Port {} isn't free".format(port_number))
|
||||
|
||||
yield from Bridge.add_nio(self, nio)
|
||||
await Bridge.add_nio(self, nio)
|
||||
|
||||
log.info('Ethernet hub "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -156,8 +152,7 @@ class EthernetHub(Bridge):
|
||||
port=port_number))
|
||||
self._mappings[port_number] = nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def remove_nio(self, port_number):
|
||||
async def remove_nio(self, port_number):
|
||||
"""
|
||||
Removes the specified NIO as member of this hub.
|
||||
|
||||
@@ -172,7 +167,7 @@ class EthernetHub(Bridge):
|
||||
nio = self._mappings[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
yield from Bridge.remove_nio(self, nio)
|
||||
await Bridge.remove_nio(self, nio)
|
||||
|
||||
log.info('Ethernet hub "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -182,8 +177,7 @@ class EthernetHub(Bridge):
|
||||
del self._mappings[port_number]
|
||||
return nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
@@ -204,15 +198,14 @@ class EthernetHub(Bridge):
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port_number))
|
||||
|
||||
yield from nio.bind_filter("both", "capture")
|
||||
yield from nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
await nio.bind_filter("both", "capture")
|
||||
await nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
|
||||
log.info('Ethernet hub "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, port_number):
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
@@ -223,7 +216,7 @@ class EthernetHub(Bridge):
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
nio = self._mappings[port_number]
|
||||
yield from nio.unbind_filter("both")
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
@@ -43,13 +43,12 @@ class EthernetSwitchConsole(EmbedShell):
|
||||
super().__init__(welcome_message="Welcome to GNS3 builtin Ethernet switch.\n\nType help for available commands\n")
|
||||
self._node = node
|
||||
|
||||
@asyncio.coroutine
|
||||
def mac(self):
|
||||
async def mac(self):
|
||||
"""
|
||||
Show MAC address table
|
||||
"""
|
||||
res = 'Port Mac VLAN\n'
|
||||
result = (yield from self._node._hypervisor.send('ethsw show_mac_addr_table {}'.format(self._node.name)))
|
||||
result = (await self._node._hypervisor.send('ethsw show_mac_addr_table {}'.format(self._node.name)))
|
||||
for line in result:
|
||||
mac, vlan, nio = line.replace(' ', ' ').split(' ')
|
||||
mac = mac.replace('.', '')
|
||||
@@ -163,41 +162,38 @@ class EthernetSwitch(Device):
|
||||
|
||||
self._ports = ports
|
||||
|
||||
@asyncio.coroutine
|
||||
def update_port_settings(self):
|
||||
async def update_port_settings(self):
|
||||
for port_settings in self._ports:
|
||||
port_number = port_settings["port_number"]
|
||||
if port_number in self._nios and self._nios[port_number] is not None:
|
||||
yield from self.set_port_settings(port_number, port_settings)
|
||||
await self.set_port_settings(port_number, port_settings)
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
if self._hypervisor is None:
|
||||
module_workdir = self.project.module_working_directory(self.manager.module_name.lower())
|
||||
self._hypervisor = yield from self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
self._hypervisor = await self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
|
||||
yield from self._hypervisor.send('ethsw create "{}"'.format(self._name))
|
||||
await self._hypervisor.send('ethsw create "{}"'.format(self._name))
|
||||
log.info('Ethernet switch "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||
|
||||
self._telnet_shell = EthernetSwitchConsole(self)
|
||||
self._telnet_shell.prompt = self._name + '> '
|
||||
self._telnet = create_telnet_shell(self._telnet_shell)
|
||||
try:
|
||||
self._telnet_server = (yield from asyncio.start_server(self._telnet.run, self._manager.port_manager.console_host, self.console))
|
||||
self._telnet_server = (await asyncio.start_server(self._telnet.run, self._manager.port_manager.console_host, self.console))
|
||||
except OSError as e:
|
||||
self.project.emit("log.warning", {"message": "Could not start Telnet server on socket {}:{}: {}".format(self._manager.port_manager.console_host, self.console, e)})
|
||||
self._hypervisor.devices.append(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_name(self, new_name):
|
||||
async def set_name(self, new_name):
|
||||
"""
|
||||
Renames this Ethernet switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('ethsw rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
await self._hypervisor.send('ethsw rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
log.info('Ethernet switch "{name}" [{id}]: renamed to "{new_name}"'.format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
@@ -223,39 +219,36 @@ class EthernetSwitch(Device):
|
||||
|
||||
return self._mappings
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
return (yield from self.close())
|
||||
async def delete(self):
|
||||
return (await self.close())
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
"""
|
||||
Deletes this Ethernet switch.
|
||||
"""
|
||||
|
||||
yield from self._telnet.close()
|
||||
await self._telnet.close()
|
||||
if self._telnet_server:
|
||||
self._telnet_server.close()
|
||||
|
||||
for nio in self._nios.values():
|
||||
if nio:
|
||||
yield from nio.close()
|
||||
await nio.close()
|
||||
self.manager.port_manager.release_tcp_port(self._console, self._project)
|
||||
if self._hypervisor:
|
||||
try:
|
||||
yield from self._hypervisor.send('ethsw delete "{}"'.format(self._name))
|
||||
await self._hypervisor.send('ethsw delete "{}"'.format(self._name))
|
||||
log.info('Ethernet switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
|
||||
except DynamipsError:
|
||||
log.debug("Could not properly delete Ethernet switch {}".format(self._name))
|
||||
if self._hypervisor and self in self._hypervisor.devices:
|
||||
self._hypervisor.devices.remove(self)
|
||||
if self._hypervisor and not self._hypervisor.devices:
|
||||
yield from self.hypervisor.stop()
|
||||
await self.hypervisor.stop()
|
||||
self._hypervisor = None
|
||||
return True
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_nio(self, nio, port_number):
|
||||
async def add_nio(self, nio, port_number):
|
||||
"""
|
||||
Adds a NIO as new port on Ethernet switch.
|
||||
|
||||
@@ -266,7 +259,7 @@ class EthernetSwitch(Device):
|
||||
if port_number in self._nios:
|
||||
raise DynamipsError("Port {} isn't free".format(port_number))
|
||||
|
||||
yield from self._hypervisor.send('ethsw add_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
await self._hypervisor.send('ethsw add_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -275,11 +268,10 @@ class EthernetSwitch(Device):
|
||||
self._nios[port_number] = nio
|
||||
for port_settings in self._ports:
|
||||
if port_settings["port_number"] == port_number:
|
||||
yield from self.set_port_settings(port_number, port_settings)
|
||||
await self.set_port_settings(port_number, port_settings)
|
||||
break
|
||||
|
||||
@asyncio.coroutine
|
||||
def remove_nio(self, port_number):
|
||||
async def remove_nio(self, port_number):
|
||||
"""
|
||||
Removes the specified NIO as member of this Ethernet switch.
|
||||
|
||||
@@ -295,7 +287,7 @@ class EthernetSwitch(Device):
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
if self._hypervisor:
|
||||
yield from self._hypervisor.send('ethsw remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
await self._hypervisor.send('ethsw remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
@@ -308,8 +300,7 @@ class EthernetSwitch(Device):
|
||||
|
||||
return nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_port_settings(self, port_number, settings):
|
||||
async def set_port_settings(self, port_number, settings):
|
||||
"""
|
||||
Applies port settings to a specific port.
|
||||
|
||||
@@ -318,14 +309,13 @@ class EthernetSwitch(Device):
|
||||
"""
|
||||
|
||||
if settings["type"] == "access":
|
||||
yield from self.set_access_port(port_number, settings["vlan"])
|
||||
await self.set_access_port(port_number, settings["vlan"])
|
||||
elif settings["type"] == "dot1q":
|
||||
yield from self.set_dot1q_port(port_number, settings["vlan"])
|
||||
await self.set_dot1q_port(port_number, settings["vlan"])
|
||||
elif settings["type"] == "qinq":
|
||||
yield from self.set_qinq_port(port_number, settings["vlan"], settings.get("ethertype"))
|
||||
await self.set_qinq_port(port_number, settings["vlan"], settings.get("ethertype"))
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_access_port(self, port_number, vlan_id):
|
||||
async def set_access_port(self, port_number, vlan_id):
|
||||
"""
|
||||
Sets the specified port as an ACCESS port.
|
||||
|
||||
@@ -337,7 +327,7 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
nio = self._nios[port_number]
|
||||
yield from self._hypervisor.send('ethsw set_access_port "{name}" {nio} {vlan_id}'.format(name=self._name,
|
||||
await self._hypervisor.send('ethsw set_access_port "{name}" {nio} {vlan_id}'.format(name=self._name,
|
||||
nio=nio,
|
||||
vlan_id=vlan_id))
|
||||
|
||||
@@ -347,8 +337,7 @@ class EthernetSwitch(Device):
|
||||
vlan_id=vlan_id))
|
||||
self._mappings[port_number] = ("access", vlan_id)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_dot1q_port(self, port_number, native_vlan):
|
||||
async def set_dot1q_port(self, port_number, native_vlan):
|
||||
"""
|
||||
Sets the specified port as a 802.1Q trunk port.
|
||||
|
||||
@@ -360,7 +349,7 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
nio = self._nios[port_number]
|
||||
yield from self._hypervisor.send('ethsw set_dot1q_port "{name}" {nio} {native_vlan}'.format(name=self._name,
|
||||
await self._hypervisor.send('ethsw set_dot1q_port "{name}" {nio} {native_vlan}'.format(name=self._name,
|
||||
nio=nio,
|
||||
native_vlan=native_vlan))
|
||||
|
||||
@@ -371,8 +360,7 @@ class EthernetSwitch(Device):
|
||||
|
||||
self._mappings[port_number] = ("dot1q", native_vlan)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_qinq_port(self, port_number, outer_vlan, ethertype):
|
||||
async def set_qinq_port(self, port_number, outer_vlan, ethertype):
|
||||
"""
|
||||
Sets the specified port as a trunk (QinQ) port.
|
||||
|
||||
@@ -387,7 +375,7 @@ class EthernetSwitch(Device):
|
||||
if ethertype != "0x8100" and parse_version(self.hypervisor.version) < parse_version('0.2.16'):
|
||||
raise DynamipsError("Dynamips version required is >= 0.2.16 to change the default QinQ Ethernet type, detected version is {}".format(self.hypervisor.version))
|
||||
|
||||
yield from self._hypervisor.send('ethsw set_qinq_port "{name}" {nio} {outer_vlan} {ethertype}'.format(name=self._name,
|
||||
await self._hypervisor.send('ethsw set_qinq_port "{name}" {nio} {outer_vlan} {ethertype}'.format(name=self._name,
|
||||
nio=nio,
|
||||
outer_vlan=outer_vlan,
|
||||
ethertype=ethertype if ethertype != "0x8100" else ""))
|
||||
@@ -399,27 +387,24 @@ class EthernetSwitch(Device):
|
||||
ethertype=ethertype))
|
||||
self._mappings[port_number] = ("qinq", outer_vlan, ethertype)
|
||||
|
||||
@asyncio.coroutine
|
||||
def get_mac_addr_table(self):
|
||||
async def get_mac_addr_table(self):
|
||||
"""
|
||||
Returns the MAC address table for this Ethernet switch.
|
||||
|
||||
:returns: list of entries (Ethernet address, VLAN, NIO)
|
||||
"""
|
||||
|
||||
mac_addr_table = yield from self._hypervisor.send('ethsw show_mac_addr_table "{}"'.format(self._name))
|
||||
mac_addr_table = await self._hypervisor.send('ethsw show_mac_addr_table "{}"'.format(self._name))
|
||||
return mac_addr_table
|
||||
|
||||
@asyncio.coroutine
|
||||
def clear_mac_addr_table(self):
|
||||
async def clear_mac_addr_table(self):
|
||||
"""
|
||||
Clears the MAC address table for this Ethernet switch.
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('ethsw clear_mac_addr_table "{}"'.format(self._name))
|
||||
await self._hypervisor.send('ethsw clear_mac_addr_table "{}"'.format(self._name))
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_EN10MB"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
@@ -443,15 +428,14 @@ class EthernetSwitch(Device):
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port_number))
|
||||
|
||||
yield from nio.bind_filter("both", "capture")
|
||||
yield from nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
await nio.bind_filter("both", "capture")
|
||||
await nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, port_number):
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
@@ -466,7 +450,7 @@ class EthernetSwitch(Device):
|
||||
if not nio:
|
||||
raise DynamipsError("Port {} is not connected".format(port_number))
|
||||
|
||||
yield from nio.unbind_filter("both")
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Ethernet switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
@@ -63,26 +63,24 @@ class FrameRelaySwitch(Device):
|
||||
"mappings": mappings,
|
||||
"status": "started"}
|
||||
|
||||
@asyncio.coroutine
|
||||
def create(self):
|
||||
async def create(self):
|
||||
|
||||
if self._hypervisor is None:
|
||||
module_workdir = self.project.module_working_directory(self.manager.module_name.lower())
|
||||
self._hypervisor = yield from self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
self._hypervisor = await self.manager.start_new_hypervisor(working_dir=module_workdir)
|
||||
|
||||
yield from self._hypervisor.send('frsw create "{}"'.format(self._name))
|
||||
await self._hypervisor.send('frsw create "{}"'.format(self._name))
|
||||
log.info('Frame Relay switch "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||
self._hypervisor.devices.append(self)
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_name(self, new_name):
|
||||
async def set_name(self, new_name):
|
||||
"""
|
||||
Renames this Frame Relay switch.
|
||||
|
||||
:param new_name: New name for this switch
|
||||
"""
|
||||
|
||||
yield from self._hypervisor.send('frsw rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
await self._hypervisor.send('frsw rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name))
|
||||
log.info('Frame Relay switch "{name}" [{id}]: renamed to "{new_name}"'.format(name=self._name,
|
||||
id=self._id,
|
||||
new_name=new_name))
|
||||
@@ -118,15 +116,14 @@ class FrameRelaySwitch(Device):
|
||||
|
||||
self._mappings = mappings
|
||||
|
||||
@asyncio.coroutine
|
||||
def close(self):
|
||||
async def close(self):
|
||||
for nio in self._nios.values():
|
||||
if nio:
|
||||
yield from nio.close()
|
||||
await nio.close()
|
||||
|
||||
if self._hypervisor:
|
||||
try:
|
||||
yield from self._hypervisor.send('frsw delete "{}"'.format(self._name))
|
||||
await self._hypervisor.send('frsw delete "{}"'.format(self._name))
|
||||
log.info('Frame Relay switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id))
|
||||
except DynamipsError:
|
||||
log.debug("Could not properly delete Frame relay switch {}".format(self._name))
|
||||
@@ -134,15 +131,14 @@ class FrameRelaySwitch(Device):
|
||||
if self._hypervisor and self in self._hypervisor.devices:
|
||||
self._hypervisor.devices.remove(self)
|
||||
if self._hypervisor and not self._hypervisor.devices:
|
||||
yield from self.hypervisor.stop()
|
||||
await self.hypervisor.stop()
|
||||
self._hypervisor = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete(self):
|
||||
async def delete(self):
|
||||
"""
|
||||
Deletes this Frame Relay switch.
|
||||
"""
|
||||
yield from self.close()
|
||||
await self.close()
|
||||
return True
|
||||
|
||||
def has_port(self, port):
|
||||
@@ -156,8 +152,7 @@ class FrameRelaySwitch(Device):
|
||||
return True
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_nio(self, nio, port_number):
|
||||
async def add_nio(self, nio, port_number):
|
||||
"""
|
||||
Adds a NIO as new port on Frame Relay switch.
|
||||
|
||||
@@ -174,10 +169,9 @@ class FrameRelaySwitch(Device):
|
||||
port=port_number))
|
||||
|
||||
self._nios[port_number] = nio
|
||||
yield from self.set_mappings(self._mappings)
|
||||
await self.set_mappings(self._mappings)
|
||||
|
||||
@asyncio.coroutine
|
||||
def remove_nio(self, port_number):
|
||||
async def remove_nio(self, port_number):
|
||||
"""
|
||||
Removes the specified NIO as member of this Frame Relay switch.
|
||||
|
||||
@@ -200,8 +194,8 @@ class FrameRelaySwitch(Device):
|
||||
source_dlci=source_dlci,
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_dlci))
|
||||
yield from self.unmap_vc(source_port, source_dlci, destination_port, destination_dlci)
|
||||
yield from self.unmap_vc(destination_port, destination_dlci, source_port, source_dlci)
|
||||
await self.unmap_vc(source_port, source_dlci, destination_port, destination_dlci)
|
||||
await self.unmap_vc(destination_port, destination_dlci, source_port, source_dlci)
|
||||
|
||||
nio = self._nios[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
@@ -215,8 +209,7 @@ class FrameRelaySwitch(Device):
|
||||
del self._nios[port_number]
|
||||
return nio
|
||||
|
||||
@asyncio.coroutine
|
||||
def set_mappings(self, mappings):
|
||||
async def set_mappings(self, mappings):
|
||||
"""
|
||||
Applies VC mappings
|
||||
|
||||
@@ -237,11 +230,10 @@ class FrameRelaySwitch(Device):
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_dlci))
|
||||
|
||||
yield from self.map_vc(source_port, source_dlci, destination_port, destination_dlci)
|
||||
yield from self.map_vc(destination_port, destination_dlci, source_port, source_dlci)
|
||||
await self.map_vc(source_port, source_dlci, destination_port, destination_dlci)
|
||||
await self.map_vc(destination_port, destination_dlci, source_port, source_dlci)
|
||||
|
||||
@asyncio.coroutine
|
||||
def map_vc(self, port1, dlci1, port2, dlci2):
|
||||
async def map_vc(self, port1, dlci1, port2, dlci2):
|
||||
"""
|
||||
Creates a new Virtual Circuit connection (unidirectional).
|
||||
|
||||
@@ -260,7 +252,7 @@ class FrameRelaySwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('frsw create_vc "{name}" {input_nio} {input_dlci} {output_nio} {output_dlci}'.format(name=self._name,
|
||||
await self._hypervisor.send('frsw create_vc "{name}" {input_nio} {input_dlci} {output_nio} {output_dlci}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_dlci=dlci1,
|
||||
output_nio=nio2,
|
||||
@@ -275,8 +267,7 @@ class FrameRelaySwitch(Device):
|
||||
|
||||
self._active_mappings[(port1, dlci1)] = (port2, dlci2)
|
||||
|
||||
@asyncio.coroutine
|
||||
def unmap_vc(self, port1, dlci1, port2, dlci2):
|
||||
async def unmap_vc(self, port1, dlci1, port2, dlci2):
|
||||
"""
|
||||
Deletes a Virtual Circuit connection (unidirectional).
|
||||
|
||||
@@ -295,7 +286,7 @@ class FrameRelaySwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
yield from self._hypervisor.send('frsw delete_vc "{name}" {input_nio} {input_dlci} {output_nio} {output_dlci}'.format(name=self._name,
|
||||
await self._hypervisor.send('frsw delete_vc "{name}" {input_nio} {input_dlci} {output_nio} {output_dlci}'.format(name=self._name,
|
||||
input_nio=nio1,
|
||||
input_dlci=dlci1,
|
||||
output_nio=nio2,
|
||||
@@ -309,8 +300,7 @@ class FrameRelaySwitch(Device):
|
||||
dlci2=dlci2))
|
||||
del self._active_mappings[(port1, dlci1)]
|
||||
|
||||
@asyncio.coroutine
|
||||
def start_capture(self, port_number, output_file, data_link_type="DLT_FRELAY"):
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_FRELAY"):
|
||||
"""
|
||||
Starts a packet capture.
|
||||
|
||||
@@ -331,15 +321,14 @@ class FrameRelaySwitch(Device):
|
||||
if nio.input_filter[0] is not None and nio.output_filter[0] is not None:
|
||||
raise DynamipsError("Port {} has already a filter applied".format(port_number))
|
||||
|
||||
yield from nio.bind_filter("both", "capture")
|
||||
yield from nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
await nio.bind_filter("both", "capture")
|
||||
await nio.setup_filter("both", '{} "{}"'.format(data_link_type, output_file))
|
||||
|
||||
log.info('Frame relay switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, port_number):
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
Stops a packet capture.
|
||||
|
||||
@@ -350,7 +339,7 @@ class FrameRelaySwitch(Device):
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
nio = self._nios[port_number]
|
||||
yield from nio.unbind_filter("both")
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Frame relay switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user