mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Use black with -l 120 param.
This commit is contained in:
1 parent
f928738bd5
commit
c021e21309
194 files changed
+6034
-4564
No files matched your search
@@ -27,6 +27,7 @@ from ..nios.nio_udp import NIOUDP
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -57,12 +58,14 @@ class ATMSwitch(Device):
|
||||
for source, destination in self._mappings.items():
|
||||
mappings[source] = destination
|
||||
|
||||
return {"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"mappings": mappings,
|
||||
"status": "started"}
|
||||
return {
|
||||
"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"mappings": mappings,
|
||||
"status": "started",
|
||||
}
|
||||
|
||||
async def create(self):
|
||||
|
||||
@@ -82,9 +85,11 @@ class ATMSwitch(Device):
|
||||
"""
|
||||
|
||||
await self._hypervisor.send(f'atmsw rename "{self._name}" "{new_name}"')
|
||||
log.info('ATM switch "{name}" [{id}]: renamed to "{new_name}"'.format(name=self._name,
|
||||
id=self._id,
|
||||
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
|
||||
)
|
||||
)
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
@@ -163,10 +168,11 @@ class ATMSwitch(Device):
|
||||
if port_number in self._nios:
|
||||
raise DynamipsError(f"Port {port_number} isn't free")
|
||||
|
||||
log.info('ATM switch "{name}" [id={id}]: NIO {nio} bound to port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'ATM switch "{name}" [id={id}]: NIO {nio} bound to port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
self._nios[port_number] = nio
|
||||
await self.set_mappings(self._mappings)
|
||||
@@ -189,37 +195,50 @@ class ATMSwitch(Device):
|
||||
source_port, source_vpi, source_vci = source
|
||||
destination_port, destination_vpi, destination_vci = destination
|
||||
if port_number == source_port:
|
||||
log.info('ATM switch "{name}" [{id}]: unmapping VCC between port {source_port} VPI {source_vpi} VCI {source_vci} and port {destination_port} VPI {destination_vpi} VCI {destination_vci}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
source_vci=source_vci,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_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)
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: unmapping VCC between port {source_port} VPI {source_vpi} VCI {source_vci} and port {destination_port} VPI {destination_vpi} VCI {destination_vci}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
source_vci=source_vci,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_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
|
||||
destination_port, destination_vpi = destination
|
||||
if port_number == source_port:
|
||||
log.info('ATM switch "{name}" [{id}]: unmapping VPC between port {source_port} VPI {source_vpi} and port {destination_port} VPI {destination_vpi}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: unmapping VPC between port {source_port} VPI {source_vpi} and port {destination_port} VPI {destination_vpi}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_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):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
log.info('ATM switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
del self._nios[port_number]
|
||||
return nio
|
||||
@@ -261,30 +280,48 @@ class ATMSwitch(Device):
|
||||
source_port, source_vpi, source_vci = map(int, match_source_pvc.group(1, 2, 3))
|
||||
destination_port, destination_vpi, destination_vci = map(int, match_destination_pvc.group(1, 2, 3))
|
||||
if self.has_port(destination_port):
|
||||
if (source_port, source_vpi, source_vci) not in self._active_mappings and \
|
||||
(destination_port, destination_vpi, destination_vci) not in self._active_mappings:
|
||||
log.info('ATM switch "{name}" [{id}]: mapping VCC between port {source_port} VPI {source_vpi} VCI {source_vci} and port {destination_port} VPI {destination_vpi} VCI {destination_vci}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
source_vci=source_vci,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_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)
|
||||
if (source_port, source_vpi, source_vci) not in self._active_mappings and (
|
||||
destination_port,
|
||||
destination_vpi,
|
||||
destination_vci,
|
||||
) not in self._active_mappings:
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: mapping VCC between port {source_port} VPI {source_vpi} VCI {source_vci} and port {destination_port} VPI {destination_vpi} VCI {destination_vci}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
source_vci=source_vci,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi,
|
||||
destination_vci=destination_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(':'))
|
||||
destination_port, destination_vpi = map(int, destination.split(':'))
|
||||
source_port, source_vpi = map(int, source.split(":"))
|
||||
destination_port, destination_vpi = map(int, destination.split(":"))
|
||||
if self.has_port(destination_port):
|
||||
if (source_port, source_vpi) not in self._active_mappings and (destination_port, destination_vpi) not in self._active_mappings:
|
||||
log.info('ATM switch "{name}" [{id}]: mapping VPC between port {source_port} VPI {source_vpi} and port {destination_port} VPI {destination_vpi}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_vpi))
|
||||
if (source_port, source_vpi) not in self._active_mappings and (
|
||||
destination_port,
|
||||
destination_vpi,
|
||||
) not in self._active_mappings:
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: mapping VPC between port {source_port} VPI {source_vpi} and port {destination_port} VPI {destination_vpi}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_vpi=source_vpi,
|
||||
destination_port=destination_port,
|
||||
destination_vpi=destination_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)
|
||||
|
||||
@@ -307,18 +344,17 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_vpi=vpi2))
|
||||
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, output_vpi=vpi2
|
||||
)
|
||||
)
|
||||
|
||||
log.info('ATM switch "{name}" [{id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} created'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
port2=port2,
|
||||
vpi2=vpi2))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} created'.format(
|
||||
name=self._name, id=self._id, port1=port1, vpi1=vpi1, port2=port2, vpi2=vpi2
|
||||
)
|
||||
)
|
||||
|
||||
self._active_mappings[(port1, vpi1)] = (port2, vpi2)
|
||||
|
||||
@@ -341,18 +377,17 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_vpi=vpi2))
|
||||
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, output_vpi=vpi2
|
||||
)
|
||||
)
|
||||
|
||||
log.info('ATM switch "{name}" [{id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} deleted'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
port2=port2,
|
||||
vpi2=vpi2))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: VPC from port {port1} VPI {vpi1} to port {port2} VPI {vpi2} deleted'.format(
|
||||
name=self._name, id=self._id, port1=port1, vpi1=vpi1, port2=port2, vpi2=vpi2
|
||||
)
|
||||
)
|
||||
|
||||
del self._active_mappings[(port1, vpi1)]
|
||||
|
||||
@@ -377,22 +412,23 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2))
|
||||
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,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2,
|
||||
)
|
||||
)
|
||||
|
||||
log.info('ATM switch "{name}" [{id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} created'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
vci1=vci1,
|
||||
port2=port2,
|
||||
vpi2=vpi2,
|
||||
vci2=vci2))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} created'.format(
|
||||
name=self._name, id=self._id, port1=port1, vpi1=vpi1, vci1=vci1, port2=port2, vpi2=vpi2, vci2=vci2
|
||||
)
|
||||
)
|
||||
|
||||
self._active_mappings[(port1, vpi1, vci1)] = (port2, vpi2, vci2)
|
||||
|
||||
@@ -417,22 +453,23 @@ class ATMSwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2))
|
||||
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,
|
||||
output_nio=nio2,
|
||||
output_vpi=vpi2,
|
||||
output_vci=vci2,
|
||||
)
|
||||
)
|
||||
|
||||
log.info('ATM switch "{name}" [{id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} deleted'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
vpi1=vpi1,
|
||||
vci1=vci1,
|
||||
port2=port2,
|
||||
vpi2=vpi2,
|
||||
vci2=vci2))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: VCC from port {port1} VPI {vpi1} VCI {vci1} to port {port2} VPI {vpi2} VCI {vci2} deleted'.format(
|
||||
name=self._name, id=self._id, port1=port1, vpi1=vpi1, vci1=vci1, port2=port2, vpi2=vpi2, vci2=vci2
|
||||
)
|
||||
)
|
||||
del self._active_mappings[(port1, vpi1, vci1)]
|
||||
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_ATM_RFC1483"):
|
||||
@@ -453,9 +490,11 @@ class ATMSwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} has already a filter applied")
|
||||
|
||||
await nio.start_packet_capture(output_file, data_link_type)
|
||||
log.info('ATM switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: starting packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
@@ -468,6 +507,8 @@ class ATMSwitch(Device):
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.stop_packet_capture()
|
||||
log.info('ATM switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'ATM switch "{name}" [{id}]: stopping packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
@@ -56,8 +56,9 @@ class Bridge(Device):
|
||||
:param new_name: New name for this bridge
|
||||
"""
|
||||
|
||||
await self._hypervisor.send('nio_bridge rename "{name}" "{new_name}"'.format(name=self._name,
|
||||
new_name=new_name))
|
||||
await self._hypervisor.send(
|
||||
'nio_bridge rename "{name}" "{new_name}"'.format(name=self._name, new_name=new_name)
|
||||
)
|
||||
|
||||
self._name = new_name
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from ..adapters.c1700_mb_1fe import C1700_MB_1FE
|
||||
from ..adapters.c1700_mb_wic1 import C1700_MB_WIC1
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -47,9 +48,23 @@ class C1700(Router):
|
||||
1710 is not supported.
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="1720"):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis="1720",
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c1700")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c1700"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 64
|
||||
@@ -63,9 +78,7 @@ class C1700(Router):
|
||||
|
||||
def __json__(self):
|
||||
|
||||
c1700_router_info = {"iomem": self._iomem,
|
||||
"chassis": self._chassis,
|
||||
"sparsemem": self._sparsemem}
|
||||
c1700_router_info = {"iomem": self._iomem, "chassis": self._chassis, "sparsemem": self._sparsemem}
|
||||
|
||||
router_info = Router.__json__(self)
|
||||
router_info.update(c1700_router_info)
|
||||
@@ -86,7 +99,7 @@ class C1700(Router):
|
||||
|
||||
# With 1751 and 1760, WICs in WIC slot 1 show up as in slot 1, not 0
|
||||
# e.g. s1/0 not s0/2
|
||||
if self._chassis in ['1751', '1760']:
|
||||
if self._chassis in ["1751", "1760"]:
|
||||
self._create_slots(2)
|
||||
self._slots[1] = C1700_MB_WIC1()
|
||||
else:
|
||||
@@ -113,9 +126,9 @@ class C1700(Router):
|
||||
|
||||
await self._hypervisor.send(f'c1700 set_chassis "{self._name}" {chassis}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
chassis=chassis))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name, id=self._id, chassis=chassis)
|
||||
)
|
||||
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
@@ -139,8 +152,9 @@ class C1700(Router):
|
||||
|
||||
await self._hypervisor.send(f'c1700 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -27,6 +27,7 @@ from ..adapters.c2600_mb_1fe import C2600_MB_1FE
|
||||
from ..adapters.c2600_mb_2fe import C2600_MB_2FE
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -51,20 +52,36 @@ class C2600(Router):
|
||||
|
||||
# adapters to insert by default corresponding the
|
||||
# chosen chassis.
|
||||
integrated_adapters = {"2610": C2600_MB_1E,
|
||||
"2611": C2600_MB_2E,
|
||||
"2620": C2600_MB_1FE,
|
||||
"2621": C2600_MB_2FE,
|
||||
"2610XM": C2600_MB_1FE,
|
||||
"2611XM": C2600_MB_2FE,
|
||||
"2620XM": C2600_MB_1FE,
|
||||
"2621XM": C2600_MB_2FE,
|
||||
"2650XM": C2600_MB_1FE,
|
||||
"2651XM": C2600_MB_2FE}
|
||||
integrated_adapters = {
|
||||
"2610": C2600_MB_1E,
|
||||
"2611": C2600_MB_2E,
|
||||
"2620": C2600_MB_1FE,
|
||||
"2621": C2600_MB_2FE,
|
||||
"2610XM": C2600_MB_1FE,
|
||||
"2611XM": C2600_MB_2FE,
|
||||
"2620XM": C2600_MB_1FE,
|
||||
"2621XM": C2600_MB_2FE,
|
||||
"2650XM": C2600_MB_1FE,
|
||||
"2651XM": C2600_MB_2FE,
|
||||
}
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="2610"):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis="2610",
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2600")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2600"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 64
|
||||
@@ -78,9 +95,7 @@ class C2600(Router):
|
||||
|
||||
def __json__(self):
|
||||
|
||||
c2600_router_info = {"iomem": self._iomem,
|
||||
"chassis": self._chassis,
|
||||
"sparsemem": self._sparsemem}
|
||||
c2600_router_info = {"iomem": self._iomem, "chassis": self._chassis, "sparsemem": self._sparsemem}
|
||||
|
||||
router_info = Router.__json__(self)
|
||||
router_info.update(c2600_router_info)
|
||||
@@ -123,9 +138,9 @@ class C2600(Router):
|
||||
|
||||
await self._hypervisor.send(f'c2600 set_chassis "{self._name}" {chassis}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
chassis=chassis))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name, id=self._id, chassis=chassis)
|
||||
)
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
|
||||
@@ -148,8 +163,9 @@ class C2600(Router):
|
||||
|
||||
await self._hypervisor.send(f'c2600 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -25,6 +25,7 @@ from ..adapters.gt96100_fe import GT96100_FE
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -44,9 +45,23 @@ class C2691(Router):
|
||||
:param aux_type: auxiliary console type
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis=None,
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2691")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2691"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 128
|
||||
@@ -89,8 +104,9 @@ class C2691(Router):
|
||||
|
||||
await self._hypervisor.send(f'c2691 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -24,6 +24,7 @@ from .router import Router
|
||||
from ..adapters.leopard_2fe import Leopard_2FE
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -45,9 +46,23 @@ class C3600(Router):
|
||||
3620, 3640 or 3660 (default = 3640).
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="3640"):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis="3640",
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3600")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3600"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 128
|
||||
@@ -60,8 +75,7 @@ class C3600(Router):
|
||||
|
||||
def __json__(self):
|
||||
|
||||
c3600_router_info = {"iomem": self._iomem,
|
||||
"chassis": self._chassis}
|
||||
c3600_router_info = {"iomem": self._iomem, "chassis": self._chassis}
|
||||
|
||||
router_info = Router.__json__(self)
|
||||
router_info.update(c3600_router_info)
|
||||
@@ -107,9 +121,9 @@ class C3600(Router):
|
||||
|
||||
await self._hypervisor.send(f'c3600 set_chassis "{self._name}" {chassis}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name,
|
||||
id=self._id,
|
||||
chassis=chassis))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: chassis set to {chassis}'.format(name=self._name, id=self._id, chassis=chassis)
|
||||
)
|
||||
|
||||
self._chassis = chassis
|
||||
self._setup_chassis()
|
||||
@@ -133,8 +147,9 @@ class C3600(Router):
|
||||
|
||||
await self._hypervisor.send(f'c3600 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -25,6 +25,7 @@ from ..adapters.gt96100_fe import GT96100_FE
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -44,9 +45,23 @@ class C3725(Router):
|
||||
:param aux_type: auxiliary console type
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis=None,
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3725")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3725"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 128
|
||||
@@ -89,8 +104,9 @@ class C3725(Router):
|
||||
|
||||
await self._hypervisor.send(f'c3725 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -25,6 +25,7 @@ from ..adapters.gt96100_fe import GT96100_FE
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -44,9 +45,23 @@ class C3745(Router):
|
||||
:param aux_type: auxiliary console type
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
chassis=None,
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3745")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3745"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 128
|
||||
@@ -89,8 +104,9 @@ class C3745(Router):
|
||||
|
||||
await self._hypervisor.send(f'c3745 set_iomem "{self._name}" {iomem}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_iomem=self._iomem,
|
||||
new_iomem=iomem))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: I/O memory updated from {old_iomem}% to {new_iomem}%'.format(
|
||||
name=self._name, id=self._id, old_iomem=self._iomem, new_iomem=iomem
|
||||
)
|
||||
)
|
||||
self._iomem = iomem
|
||||
@@ -27,6 +27,7 @@ from ..adapters.c7200_io_ge_e import C7200_IO_GE_E
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -47,9 +48,24 @@ class C7200(Router):
|
||||
:param npe: Default NPE
|
||||
"""
|
||||
|
||||
def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", npe="npe-400", chassis=None):
|
||||
def __init__(
|
||||
self,
|
||||
name,
|
||||
node_id,
|
||||
project,
|
||||
manager,
|
||||
dynamips_id,
|
||||
console=None,
|
||||
console_type="telnet",
|
||||
aux=None,
|
||||
aux_type="none",
|
||||
npe="npe-400",
|
||||
chassis=None,
|
||||
):
|
||||
|
||||
super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c7200")
|
||||
super().__init__(
|
||||
name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c7200"
|
||||
)
|
||||
|
||||
# Set default values for this platform (must be the same as Dynamips)
|
||||
self._ram = 256
|
||||
@@ -78,10 +94,12 @@ class C7200(Router):
|
||||
|
||||
def __json__(self):
|
||||
|
||||
c7200_router_info = {"npe": self._npe,
|
||||
"midplane": self._midplane,
|
||||
"sensors": self._sensors,
|
||||
"power_supplies": self._power_supplies}
|
||||
c7200_router_info = {
|
||||
"npe": self._npe,
|
||||
"midplane": self._midplane,
|
||||
"sensors": self._sensors,
|
||||
"power_supplies": self._power_supplies,
|
||||
}
|
||||
|
||||
router_info = Router.__json__(self)
|
||||
router_info.update(c7200_router_info)
|
||||
@@ -119,15 +137,16 @@ class C7200(Router):
|
||||
npe-225, npe-300, npe-400 and npe-g2 (PowerPC c7200 only)
|
||||
"""
|
||||
|
||||
if (await self.is_running()):
|
||||
if await self.is_running():
|
||||
raise DynamipsError("Cannot change NPE on running router")
|
||||
|
||||
await self._hypervisor.send(f'c7200 set_npe "{self._name}" {npe}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: NPE updated from {old_npe} to {new_npe}'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_npe=self._npe,
|
||||
new_npe=npe))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: NPE updated from {old_npe} to {new_npe}'.format(
|
||||
name=self._name, id=self._id, old_npe=self._npe, new_npe=npe
|
||||
)
|
||||
)
|
||||
self._npe = npe
|
||||
|
||||
@property
|
||||
@@ -149,10 +168,11 @@ class C7200(Router):
|
||||
|
||||
await self._hypervisor.send(f'c7200 set_midplane "{self._name}" {midplane}')
|
||||
|
||||
log.info('Router "{name}" [{id}]: midplane updated from {old_midplane} to {new_midplane}'.format(name=self._name,
|
||||
id=self._id,
|
||||
old_midplane=self._midplane,
|
||||
new_midplane=midplane))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: midplane updated from {old_midplane} to {new_midplane}'.format(
|
||||
name=self._name, id=self._id, old_midplane=self._midplane, new_midplane=midplane
|
||||
)
|
||||
)
|
||||
self._midplane = midplane
|
||||
|
||||
@property
|
||||
@@ -179,15 +199,21 @@ class C7200(Router):
|
||||
|
||||
sensor_id = 0
|
||||
for sensor in sensors:
|
||||
await self._hypervisor.send('c7200 set_temp_sensor "{name}" {sensor_id} {temp}'.format(name=self._name,
|
||||
sensor_id=sensor_id,
|
||||
temp=sensor))
|
||||
await self._hypervisor.send(
|
||||
'c7200 set_temp_sensor "{name}" {sensor_id} {temp}'.format(
|
||||
name=self._name, sensor_id=sensor_id, temp=sensor
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Router "{name}" [{id}]: sensor {sensor_id} temperature updated from {old_temp}C to {new_temp}C'.format(name=self._name,
|
||||
id=self._id,
|
||||
sensor_id=sensor_id,
|
||||
old_temp=self._sensors[sensor_id],
|
||||
new_temp=sensors[sensor_id]))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: sensor {sensor_id} temperature updated from {old_temp}C to {new_temp}C'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
sensor_id=sensor_id,
|
||||
old_temp=self._sensors[sensor_id],
|
||||
new_temp=sensors[sensor_id],
|
||||
)
|
||||
)
|
||||
|
||||
sensor_id += 1
|
||||
self._sensors = sensors
|
||||
@@ -212,14 +238,17 @@ class C7200(Router):
|
||||
|
||||
power_supply_id = 0
|
||||
for power_supply in power_supplies:
|
||||
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))
|
||||
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
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Router "{name}" [{id}]: power supply {power_supply_id} state updated to {powered_on}'.format(name=self._name,
|
||||
id=self._id,
|
||||
power_supply_id=power_supply_id,
|
||||
powered_on=power_supply))
|
||||
log.info(
|
||||
'Router "{name}" [{id}]: power supply {power_supply_id} state updated to {powered_on}'.format(
|
||||
name=self._name, id=self._id, power_supply_id=power_supply_id, powered_on=power_supply
|
||||
)
|
||||
)
|
||||
power_supply_id += 1
|
||||
|
||||
self._power_supplies = power_supplies
|
||||
|
||||
@@ -24,6 +24,7 @@ from ..dynamips_error import DynamipsError
|
||||
from ...error import NodeError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -48,19 +49,20 @@ class EthernetHub(Bridge):
|
||||
# create 8 ports by default
|
||||
self._ports = []
|
||||
for port_number in range(0, 8):
|
||||
self._ports.append({"port_number": port_number,
|
||||
"name": f"Ethernet{port_number}"})
|
||||
self._ports.append({"port_number": port_number, "name": f"Ethernet{port_number}"})
|
||||
else:
|
||||
self._ports = ports
|
||||
|
||||
def __json__(self):
|
||||
|
||||
return {"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"ports_mapping": self._ports,
|
||||
"status": "started"}
|
||||
return {
|
||||
"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"ports_mapping": self._ports,
|
||||
"status": "started",
|
||||
}
|
||||
|
||||
@property
|
||||
def ports_mapping(self):
|
||||
@@ -107,7 +109,7 @@ class EthernetHub(Bridge):
|
||||
return self._mappings
|
||||
|
||||
async def delete(self):
|
||||
return (await self.close())
|
||||
return await self.close()
|
||||
|
||||
async def close(self):
|
||||
"""
|
||||
@@ -144,10 +146,11 @@ class EthernetHub(Bridge):
|
||||
|
||||
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,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet hub "{name}" [{id}]: NIO {nio} bound to port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
self._mappings[port_number] = nio
|
||||
|
||||
async def remove_nio(self, port_number):
|
||||
@@ -168,10 +171,11 @@ class EthernetHub(Bridge):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
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,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet hub "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
del self._mappings[port_number]
|
||||
return nio
|
||||
@@ -213,9 +217,11 @@ class EthernetHub(Bridge):
|
||||
raise DynamipsError(f"Port {port_number} has already a filter applied")
|
||||
|
||||
await nio.start_packet_capture(output_file, data_link_type)
|
||||
log.info('Ethernet hub "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet hub "{name}" [{id}]: starting packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
@@ -228,6 +234,8 @@ class EthernetHub(Bridge):
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.stop_packet_capture()
|
||||
log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
@@ -21,7 +21,8 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L558
|
||||
|
||||
import asyncio
|
||||
from gns3server.utils import parse_version
|
||||
#from gns3server.utils.asyncio.embed_shell import EmbedShell, create_telnet_shell
|
||||
|
||||
# from gns3server.utils.asyncio.embed_shell import EmbedShell, create_telnet_shell
|
||||
|
||||
|
||||
from .device import Device
|
||||
@@ -30,6 +31,7 @@ from ..dynamips_error import DynamipsError
|
||||
from ...error import NodeError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -84,8 +86,8 @@ class EthernetSwitch(Device):
|
||||
self._nios = {}
|
||||
self._mappings = {}
|
||||
self._telnet_console = None
|
||||
#self._telnet_shell = None
|
||||
#self._telnet_server = None
|
||||
# self._telnet_shell = None
|
||||
# self._telnet_server = None
|
||||
self._console = console
|
||||
self._console_type = console_type
|
||||
|
||||
@@ -101,23 +103,24 @@ class EthernetSwitch(Device):
|
||||
# create 8 ports by default
|
||||
self._ports = []
|
||||
for port_number in range(0, 8):
|
||||
self._ports.append({"port_number": port_number,
|
||||
"name": f"Ethernet{port_number}",
|
||||
"type": "access",
|
||||
"vlan": 1})
|
||||
self._ports.append(
|
||||
{"port_number": port_number, "name": f"Ethernet{port_number}", "type": "access", "vlan": 1}
|
||||
)
|
||||
else:
|
||||
self._ports = ports
|
||||
|
||||
def __json__(self):
|
||||
|
||||
ethernet_switch_info = {"name": self.name,
|
||||
"usage": self.usage,
|
||||
"console": self.console,
|
||||
"console_type": self.console_type,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"ports_mapping": self._ports,
|
||||
"status": "started"}
|
||||
ethernet_switch_info = {
|
||||
"name": self.name,
|
||||
"usage": self.usage,
|
||||
"console": self.console,
|
||||
"console_type": self.console_type,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"ports_mapping": self._ports,
|
||||
"status": "started",
|
||||
}
|
||||
|
||||
return ethernet_switch_info
|
||||
|
||||
@@ -138,8 +141,10 @@ class EthernetSwitch(Device):
|
||||
|
||||
if self._console_type != console_type:
|
||||
if console_type == "telnet":
|
||||
self.project.emit("log.warning", {
|
||||
"message": f'"{self._name}": Telnet access for switches is not available in this version of GNS3'})
|
||||
self.project.emit(
|
||||
"log.warning",
|
||||
{"message": f'"{self._name}": Telnet access for switches is not available in this version of GNS3'},
|
||||
)
|
||||
self._console_type = console_type
|
||||
|
||||
@property
|
||||
@@ -186,15 +191,18 @@ class EthernetSwitch(Device):
|
||||
await self._hypervisor.send(f'ethsw create "{self._name}"')
|
||||
log.info(f'Ethernet switch "{self._name}" [{self._id}] has been created')
|
||||
|
||||
#self._telnet_shell = EthernetSwitchConsole(self)
|
||||
#self._telnet_shell.prompt = self._name + '> '
|
||||
#self._telnet = create_telnet_shell(self._telnet_shell)
|
||||
#try:
|
||||
# self._telnet_shell = EthernetSwitchConsole(self)
|
||||
# self._telnet_shell.prompt = self._name + '> '
|
||||
# self._telnet = create_telnet_shell(self._telnet_shell)
|
||||
# try:
|
||||
# self._telnet_server = (await asyncio.start_server(self._telnet.run, self._manager.port_manager.console_host, self.console))
|
||||
#except OSError as e:
|
||||
# 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)})
|
||||
if self._console_type == "telnet":
|
||||
self.project.emit("log.warning", {"message": f'"{self._name}": Telnet access for switches is not available in this version of GNS3'})
|
||||
self.project.emit(
|
||||
"log.warning",
|
||||
{"message": f'"{self._name}": Telnet access for switches is not available in this version of GNS3'},
|
||||
)
|
||||
self._hypervisor.devices.append(self)
|
||||
|
||||
async def set_name(self, new_name):
|
||||
@@ -205,9 +213,11 @@ class EthernetSwitch(Device):
|
||||
"""
|
||||
|
||||
await self._hypervisor.send(f'ethsw rename "{self._name}" "{new_name}"')
|
||||
log.info('Ethernet switch "{name}" [{id}]: renamed to "{new_name}"'.format(name=self._name,
|
||||
id=self._id,
|
||||
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
|
||||
)
|
||||
)
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
@@ -231,15 +241,15 @@ class EthernetSwitch(Device):
|
||||
return self._mappings
|
||||
|
||||
async def delete(self):
|
||||
return (await self.close())
|
||||
return await self.close()
|
||||
|
||||
async def close(self):
|
||||
"""
|
||||
Deletes this Ethernet switch.
|
||||
"""
|
||||
|
||||
#await self._telnet.close()
|
||||
#if self._telnet_server:
|
||||
# await self._telnet.close()
|
||||
# if self._telnet_server:
|
||||
# self._telnet_server.close()
|
||||
|
||||
for nio in self._nios.values():
|
||||
@@ -272,10 +282,11 @@ class EthernetSwitch(Device):
|
||||
|
||||
await self._hypervisor.send(f'ethsw add_nio "{self._name}" {nio}')
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: NIO {nio} bound to port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
self._nios[port_number] = nio
|
||||
for port_settings in self._ports:
|
||||
if port_settings["port_number"] == port_number:
|
||||
@@ -301,10 +312,11 @@ class EthernetSwitch(Device):
|
||||
if self._hypervisor:
|
||||
await self._hypervisor.send(f'ethsw remove_nio "{self._name}" {nio}')
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
del self._nios[port_number]
|
||||
if port_number in self._mappings:
|
||||
@@ -358,14 +370,15 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} is not allocated")
|
||||
|
||||
nio = self._nios[port_number]
|
||||
await self._hypervisor.send('ethsw set_access_port "{name}" {nio} {vlan_id}'.format(name=self._name,
|
||||
nio=nio,
|
||||
vlan_id=vlan_id))
|
||||
await self._hypervisor.send(
|
||||
'ethsw set_access_port "{name}" {nio} {vlan_id}'.format(name=self._name, nio=nio, vlan_id=vlan_id)
|
||||
)
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: port {port} set as an access port in VLAN {vlan_id}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number,
|
||||
vlan_id=vlan_id))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: port {port} set as an access port in VLAN {vlan_id}'.format(
|
||||
name=self._name, id=self._id, port=port_number, vlan_id=vlan_id
|
||||
)
|
||||
)
|
||||
self._mappings[port_number] = ("access", vlan_id)
|
||||
|
||||
async def set_dot1q_port(self, port_number, native_vlan):
|
||||
@@ -380,14 +393,17 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} is not allocated")
|
||||
|
||||
nio = self._nios[port_number]
|
||||
await self._hypervisor.send('ethsw set_dot1q_port "{name}" {nio} {native_vlan}'.format(name=self._name,
|
||||
nio=nio,
|
||||
native_vlan=native_vlan))
|
||||
await self._hypervisor.send(
|
||||
'ethsw set_dot1q_port "{name}" {nio} {native_vlan}'.format(
|
||||
name=self._name, nio=nio, native_vlan=native_vlan
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: port {port} set as a 802.1Q port with native VLAN {vlan_id}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number,
|
||||
vlan_id=native_vlan))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: port {port} set as a 802.1Q port with native VLAN {vlan_id}'.format(
|
||||
name=self._name, id=self._id, port=port_number, vlan_id=native_vlan
|
||||
)
|
||||
)
|
||||
|
||||
self._mappings[port_number] = ("dot1q", native_vlan)
|
||||
|
||||
@@ -403,19 +419,22 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} is not allocated")
|
||||
|
||||
nio = self._nios[port_number]
|
||||
if ethertype != "0x8100" and parse_version(self.hypervisor.version) < parse_version('0.2.16'):
|
||||
raise DynamipsError(f"Dynamips version required is >= 0.2.16 to change the default QinQ Ethernet type, detected version is {self.hypervisor.version}")
|
||||
if ethertype != "0x8100" and parse_version(self.hypervisor.version) < parse_version("0.2.16"):
|
||||
raise DynamipsError(
|
||||
f"Dynamips version required is >= 0.2.16 to change the default QinQ Ethernet type, detected version is {self.hypervisor.version}"
|
||||
)
|
||||
|
||||
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 ""))
|
||||
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 ""
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: port {port} set as a QinQ ({ethertype}) port with outer VLAN {vlan_id}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number,
|
||||
vlan_id=outer_vlan,
|
||||
ethertype=ethertype))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: port {port} set as a QinQ ({ethertype}) port with outer VLAN {vlan_id}'.format(
|
||||
name=self._name, id=self._id, port=port_number, vlan_id=outer_vlan, ethertype=ethertype
|
||||
)
|
||||
)
|
||||
self._mappings[port_number] = ("qinq", outer_vlan, ethertype)
|
||||
|
||||
async def get_mac_addr_table(self):
|
||||
@@ -453,9 +472,11 @@ class EthernetSwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} has already a filter applied")
|
||||
|
||||
await nio.start_packet_capture(output_file, data_link_type)
|
||||
log.info('Ethernet switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: starting packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
@@ -468,6 +489,8 @@ class EthernetSwitch(Device):
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.stop_packet_capture()
|
||||
log.info('Ethernet switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Ethernet switch "{name}" [{id}]: stopping packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
@@ -26,6 +26,7 @@ from ..nios.nio_udp import NIOUDP
|
||||
from ..dynamips_error import DynamipsError
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -56,12 +57,14 @@ class FrameRelaySwitch(Device):
|
||||
for source, destination in self._mappings.items():
|
||||
mappings[source] = destination
|
||||
|
||||
return {"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"mappings": mappings,
|
||||
"status": "started"}
|
||||
return {
|
||||
"name": self.name,
|
||||
"usage": self.usage,
|
||||
"node_id": self.id,
|
||||
"project_id": self.project.id,
|
||||
"mappings": mappings,
|
||||
"status": "started",
|
||||
}
|
||||
|
||||
async def create(self):
|
||||
|
||||
@@ -81,9 +84,11 @@ class FrameRelaySwitch(Device):
|
||||
"""
|
||||
|
||||
await self._hypervisor.send(f'frsw rename "{self._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))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: renamed to "{new_name}"'.format(
|
||||
name=self._name, id=self._id, new_name=new_name
|
||||
)
|
||||
)
|
||||
self._name = new_name
|
||||
|
||||
@property
|
||||
@@ -163,10 +168,11 @@ class FrameRelaySwitch(Device):
|
||||
if port_number in self._nios:
|
||||
raise DynamipsError(f"Port {port_number} isn't free")
|
||||
|
||||
log.info('Frame Relay switch "{name}" [{id}]: NIO {nio} bound to port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: NIO {nio} bound to port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
self._nios[port_number] = nio
|
||||
await self.set_mappings(self._mappings)
|
||||
@@ -189,12 +195,16 @@ class FrameRelaySwitch(Device):
|
||||
source_port, source_dlci = source
|
||||
destination_port, destination_dlci = destination
|
||||
if port_number == source_port:
|
||||
log.info('Frame Relay switch "{name}" [{id}]: unmapping VC between port {source_port} DLCI {source_dlci} and port {destination_port} DLCI {destination_dlci}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_dlci=source_dlci,
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_dlci))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: unmapping VC between port {source_port} DLCI {source_dlci} and port {destination_port} DLCI {destination_dlci}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_dlci=source_dlci,
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_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)
|
||||
|
||||
@@ -202,10 +212,11 @@ class FrameRelaySwitch(Device):
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
|
||||
log.info('Frame Relay switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
nio=nio,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(
|
||||
name=self._name, id=self._id, nio=nio, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
del self._nios[port_number]
|
||||
return nio
|
||||
@@ -239,16 +250,23 @@ class FrameRelaySwitch(Device):
|
||||
for source, destination in mappings.items():
|
||||
if not isinstance(source, str) or not isinstance(destination, str):
|
||||
raise DynamipsError("Invalid Frame-Relay mappings")
|
||||
source_port, source_dlci = map(int, source.split(':'))
|
||||
destination_port, destination_dlci = map(int, destination.split(':'))
|
||||
source_port, source_dlci = map(int, source.split(":"))
|
||||
destination_port, destination_dlci = map(int, destination.split(":"))
|
||||
if self.has_port(destination_port):
|
||||
if (source_port, source_dlci) not in self._active_mappings and (destination_port, destination_dlci) not in self._active_mappings:
|
||||
log.info('Frame Relay switch "{name}" [{id}]: mapping VC between port {source_port} DLCI {source_dlci} and port {destination_port} DLCI {destination_dlci}'.format(name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_dlci=source_dlci,
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_dlci))
|
||||
if (source_port, source_dlci) not in self._active_mappings and (
|
||||
destination_port,
|
||||
destination_dlci,
|
||||
) not in self._active_mappings:
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: mapping VC between port {source_port} DLCI {source_dlci} and port {destination_port} DLCI {destination_dlci}'.format(
|
||||
name=self._name,
|
||||
id=self._id,
|
||||
source_port=source_port,
|
||||
source_dlci=source_dlci,
|
||||
destination_port=destination_port,
|
||||
destination_dlci=destination_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)
|
||||
@@ -272,18 +290,17 @@ class FrameRelaySwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_dlci=dlci2))
|
||||
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, output_dlci=dlci2
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Frame Relay switch "{name}" [{id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} created'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
dlci1=dlci1,
|
||||
port2=port2,
|
||||
dlci2=dlci2))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} created'.format(
|
||||
name=self._name, id=self._id, port1=port1, dlci1=dlci1, port2=port2, dlci2=dlci2
|
||||
)
|
||||
)
|
||||
|
||||
self._active_mappings[(port1, dlci1)] = (port2, dlci2)
|
||||
|
||||
@@ -306,18 +323,17 @@ class FrameRelaySwitch(Device):
|
||||
nio1 = self._nios[port1]
|
||||
nio2 = self._nios[port2]
|
||||
|
||||
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,
|
||||
output_dlci=dlci2))
|
||||
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, output_dlci=dlci2
|
||||
)
|
||||
)
|
||||
|
||||
log.info('Frame Relay switch "{name}" [{id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} deleted'.format(name=self._name,
|
||||
id=self._id,
|
||||
port1=port1,
|
||||
dlci1=dlci1,
|
||||
port2=port2,
|
||||
dlci2=dlci2))
|
||||
log.info(
|
||||
'Frame Relay switch "{name}" [{id}]: VC from port {port1} DLCI {dlci1} to port {port2} DLCI {dlci2} deleted'.format(
|
||||
name=self._name, id=self._id, port1=port1, dlci1=dlci1, port2=port2, dlci2=dlci2
|
||||
)
|
||||
)
|
||||
del self._active_mappings[(port1, dlci1)]
|
||||
|
||||
async def start_capture(self, port_number, output_file, data_link_type="DLT_FRELAY"):
|
||||
@@ -339,9 +355,11 @@ class FrameRelaySwitch(Device):
|
||||
raise DynamipsError(f"Port {port_number} has already a filter applied")
|
||||
|
||||
await nio.start_packet_capture(output_file, data_link_type)
|
||||
log.info('Frame relay switch "{name}" [{id}]: starting packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
log.info(
|
||||
'Frame relay switch "{name}" [{id}]: starting packet capture on port {port}'.format(
|
||||
name=self._name, id=self._id, port=port_number
|
||||
)
|
||||
)
|
||||
|
||||
async def stop_capture(self, port_number):
|
||||
"""
|
||||
@@ -354,6 +372,8 @@ class FrameRelaySwitch(Device):
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.stop_packet_capture()
|
||||
log.info('Frame relay switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
port=port_number))
|
||||
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