mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 06:41:13 +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
@@ -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