mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
PEP 8 clean thanks to auto pep8
This commit is contained in:
1 parent
7f185663d1
commit
f5ed9fbcf1
124 files changed
+340
-210
No files matched your search
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class Adapter(object):
|
||||
|
||||
"""
|
||||
Base class for adapters.
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class EthernetAdapter(Adapter):
|
||||
|
||||
"""
|
||||
VPCS Ethernet adapter.
|
||||
"""
|
||||
|
||||
@@ -24,6 +24,7 @@ from .project_manager import ProjectManager
|
||||
|
||||
|
||||
class BaseManager:
|
||||
|
||||
"""
|
||||
Base class for all Manager.
|
||||
Responsible of management of a VM pool
|
||||
|
||||
@@ -95,6 +95,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Dynamips(IModule):
|
||||
|
||||
"""
|
||||
Dynamips module.
|
||||
|
||||
@@ -140,7 +141,7 @@ class Dynamips(IModule):
|
||||
self._console_host = dynamips_config.get("console_host", kwargs["console_host"])
|
||||
|
||||
if not sys.platform.startswith("win32"):
|
||||
#FIXME: pickle issues Windows
|
||||
# FIXME: pickle issues Windows
|
||||
self._callback = self.add_periodic_callback(self._check_hypervisors, 5000)
|
||||
self._callback.start()
|
||||
|
||||
@@ -323,7 +324,7 @@ class Dynamips(IModule):
|
||||
|
||||
log.debug("received request {}".format(request))
|
||||
|
||||
#TODO: JSON schema validation
|
||||
# TODO: JSON schema validation
|
||||
if not self._hypervisor_manager:
|
||||
|
||||
if "path" in request:
|
||||
@@ -407,7 +408,7 @@ class Dynamips(IModule):
|
||||
rhost = request["nio"]["rhost"]
|
||||
rport = request["nio"]["rport"]
|
||||
try:
|
||||
#TODO: handle IPv6
|
||||
# TODO: handle IPv6
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
sock.connect((rhost, rport))
|
||||
except OSError as e:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class Adapter(object):
|
||||
|
||||
"""
|
||||
Base class for adapters.
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C1700_MB_1FE(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 1 port FastEthernet adapter for c1700 platform.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C1700_MB_WIC1(Adapter):
|
||||
|
||||
"""
|
||||
Fake module to provide a placeholder for slot 1 interfaces when WICs
|
||||
are inserted into WIC slot 1.
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_1E(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 1 port Ethernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_1FE(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 1 port FastEthernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_2E(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 2 port Ethernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C2600_MB_2FE(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 2 port FastEthernet adapter for the c2600 platform.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_2FE(Adapter):
|
||||
|
||||
"""
|
||||
C7200-IO-2FE FastEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_FE(Adapter):
|
||||
|
||||
"""
|
||||
C7200-IO-FE FastEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class C7200_IO_GE_E(Adapter):
|
||||
|
||||
"""
|
||||
C7200-IO-GE-E GigabitEthernet Input/Ouput controller.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class Leopard_2FE(Adapter):
|
||||
|
||||
"""
|
||||
Integrated 2 port FastEthernet adapter for c3660 router.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class NM_16ESW(Adapter):
|
||||
|
||||
"""
|
||||
NM-16ESW FastEthernet network module.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class NM_1E(Adapter):
|
||||
|
||||
"""
|
||||
NM-1E Ethernet network module.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class NM_1FE_TX(Adapter):
|
||||
|
||||
"""
|
||||
NM-1FE-TX FastEthernet network module.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class NM_4E(Adapter):
|
||||
|
||||
"""
|
||||
NM-4E Ethernet network module.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class NM_4T(Adapter):
|
||||
|
||||
"""
|
||||
NM-4T Serial network module.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_2FE_TX(Adapter):
|
||||
|
||||
"""
|
||||
PA-2FE-TX FastEthernet port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_4E(Adapter):
|
||||
|
||||
"""
|
||||
PA-4E Ethernet port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_4T(Adapter):
|
||||
|
||||
"""
|
||||
PA-4T+ Serial port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_8E(Adapter):
|
||||
|
||||
"""
|
||||
PA-8E Ethernet port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_8T(Adapter):
|
||||
|
||||
"""
|
||||
PA-8T Serial port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_A1(Adapter):
|
||||
|
||||
"""
|
||||
PA-A1 ATM port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_FE_TX(Adapter):
|
||||
|
||||
"""
|
||||
PA-FE-TX FastEthernet port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_GE(Adapter):
|
||||
|
||||
"""
|
||||
PA-GE GigabitEthernet port adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class PA_POS_OC3(Adapter):
|
||||
|
||||
"""
|
||||
PA-POS-OC3 port adapter.
|
||||
"""
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class WIC_1ENET(object):
|
||||
|
||||
"""
|
||||
WIC-1ENET Ethernet
|
||||
"""
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class WIC_1T(object):
|
||||
|
||||
"""
|
||||
WIC-1T Serial
|
||||
"""
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class WIC_2T(object):
|
||||
|
||||
"""
|
||||
WIC-2T Serial
|
||||
"""
|
||||
|
||||
@@ -466,7 +466,7 @@ class VM(object):
|
||||
adapter_name = value
|
||||
adapter = ADAPTER_MATRIX[adapter_name]()
|
||||
try:
|
||||
if router.slots[slot_id] and type(router.slots[slot_id]) != type(adapter):
|
||||
if router.slots[slot_id] and not isinstance(router.slots[slot_id], type(adapter)):
|
||||
router.slot_remove_binding(slot_id)
|
||||
router.slot_add_binding(slot_id, adapter)
|
||||
response[name] = value
|
||||
@@ -487,14 +487,14 @@ class VM(object):
|
||||
wic_name = value
|
||||
wic = WIC_MATRIX[wic_name]()
|
||||
try:
|
||||
if router.slots[0].wics[wic_slot_id] and type(router.slots[0].wics[wic_slot_id]) != type(wic):
|
||||
if router.slots[0].wics[wic_slot_id] and not isinstance(router.slots[0].wics[wic_slot_id], type(wic)):
|
||||
router.uninstall_wic(wic_slot_id)
|
||||
router.install_wic(wic_slot_id, wic)
|
||||
response[name] = value
|
||||
except DynamipsError as e:
|
||||
self.send_custom_error(str(e))
|
||||
return
|
||||
elif name.startswith("wic") and value == None:
|
||||
elif name.startswith("wic") and value is None:
|
||||
wic_slot_id = int(name[-1])
|
||||
if router.slots[0].wics and router.slots[0].wics[wic_slot_id]:
|
||||
try:
|
||||
|
||||
@@ -30,6 +30,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DynamipsHypervisor(object):
|
||||
|
||||
"""
|
||||
Creates a new connection to a Dynamips server (also called hypervisor)
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Hypervisor(DynamipsHypervisor):
|
||||
|
||||
"""
|
||||
Hypervisor.
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HypervisorManager(object):
|
||||
|
||||
"""
|
||||
Manages Dynamips hypervisors.
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO(object):
|
||||
|
||||
"""
|
||||
Base NIO class
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_FIFO(NIO):
|
||||
|
||||
"""
|
||||
Dynamips FIFO NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_GenericEthernet(NIO):
|
||||
|
||||
"""
|
||||
Dynamips generic Ethernet NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_LinuxEthernet(NIO):
|
||||
|
||||
"""
|
||||
Dynamips Linux Ethernet NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_Mcast(NIO):
|
||||
|
||||
"""
|
||||
Dynamips Linux Ethernet NIO.
|
||||
|
||||
@@ -103,5 +104,5 @@ class NIO_Mcast(NIO):
|
||||
"""
|
||||
|
||||
self._hypervisor.send("nio set_mcast_ttl {name} {ttl}".format(name=self._name,
|
||||
ttl=ttl))
|
||||
ttl=ttl))
|
||||
self._ttl = ttl
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_Null(NIO):
|
||||
|
||||
"""
|
||||
Dynamips NULL NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_TAP(NIO):
|
||||
|
||||
"""
|
||||
Dynamips TAP NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_UDP(NIO):
|
||||
|
||||
"""
|
||||
Dynamips UDP NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_UDP_auto(NIO):
|
||||
|
||||
"""
|
||||
Dynamips auto UDP NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_UNIX(NIO):
|
||||
|
||||
"""
|
||||
Dynamips UNIX NIO.
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NIO_VDE(NIO):
|
||||
|
||||
"""
|
||||
Dynamips VDE NIO.
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from ..dynamips_error import DynamipsError
|
||||
|
||||
|
||||
class ATMBridge(object):
|
||||
|
||||
"""
|
||||
Dynamips bridge switch.
|
||||
|
||||
@@ -33,7 +34,7 @@ class ATMBridge(object):
|
||||
|
||||
def __init__(self, hypervisor, name):
|
||||
|
||||
#FIXME: instance tracking
|
||||
# FIXME: instance tracking
|
||||
self._hypervisor = hypervisor
|
||||
self._name = '"' + name + '"' # put name into quotes to protect spaces
|
||||
self._hypervisor.send("atm_bridge create {}".format(self._name))
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ATMSwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips ATM switch.
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L538
|
||||
|
||||
|
||||
class Bridge(object):
|
||||
|
||||
"""
|
||||
Dynamips bridge.
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C1700(Router):
|
||||
|
||||
"""
|
||||
Dynamips c1700 router.
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C2600(Router):
|
||||
|
||||
"""
|
||||
Dynamips c2600 router.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C2691(Router):
|
||||
|
||||
"""
|
||||
Dynamips c2691 router.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3600(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3600 router.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3725(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3725 router.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C3745(Router):
|
||||
|
||||
"""
|
||||
Dynamips c3745 router.
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class C7200(Router):
|
||||
|
||||
"""
|
||||
Dynamips c7200 router (model is 7206).
|
||||
|
||||
@@ -227,9 +228,9 @@ class C7200(Router):
|
||||
powered_on=power_supply))
|
||||
|
||||
log.info("router {name} [id={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))
|
||||
id=self._id,
|
||||
power_supply_id=power_supply_id,
|
||||
powered_on=power_supply))
|
||||
power_supply_id += 1
|
||||
|
||||
self._power_supplies = power_supplies
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EthernetSwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips Ethernet switch.
|
||||
|
||||
@@ -268,9 +269,9 @@ class EthernetSwitch(object):
|
||||
outer_vlan=outer_vlan))
|
||||
|
||||
log.info("Ethernet switch {name} [id={id}]: port {port} set as a QinQ port with outer VLAN {vlan_id}".format(name=self._name,
|
||||
id=self._id,
|
||||
port=port,
|
||||
vlan_id=outer_vlan))
|
||||
id=self._id,
|
||||
port=port,
|
||||
vlan_id=outer_vlan))
|
||||
self._mapping[port] = ("qinq", outer_vlan)
|
||||
|
||||
def get_mac_addr_table(self):
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FrameRelaySwitch(object):
|
||||
|
||||
"""
|
||||
Dynamips Frame Relay switch.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Hub(Bridge):
|
||||
|
||||
"""
|
||||
Dynamips hub (based on Bridge)
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Router(object):
|
||||
|
||||
"""
|
||||
Dynamips router implementation.
|
||||
|
||||
@@ -575,7 +576,7 @@ class Router(object):
|
||||
try:
|
||||
reply = self._hypervisor.send("vm extract_config {}".format(self._name))[0].rsplit(' ', 2)[-2:]
|
||||
except IOError:
|
||||
#for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file.
|
||||
# for some reason Dynamips gets frozen when it does not find the magic number in the NVRAM file.
|
||||
return None, None
|
||||
startup_config = reply[0][1:-1] # get statup-config and remove single quotes
|
||||
private_config = reply[1][1:-1] # get private-config and remove single quotes
|
||||
|
||||
@@ -44,7 +44,7 @@ ETHSW_DELETE_SCHEMA = {
|
||||
"required": ["id"]
|
||||
}
|
||||
|
||||
#TODO: ports {'1': {'vlan': 1, 'type': 'qinq'}
|
||||
# TODO: ports {'1': {'vlan': 1, 'type': 'qinq'}
|
||||
ETHSW_UPDATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to update an Ethernet switch instance",
|
||||
@@ -59,20 +59,20 @@ ETHSW_UPDATE_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
# "ports": {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "type": {
|
||||
# "description": "Port type",
|
||||
# "enum": ["access", "dot1q", "qinq"],
|
||||
# },
|
||||
# "vlan": {
|
||||
# "description": "VLAN number",
|
||||
# "type": "integer",
|
||||
# "minimum": 1
|
||||
# },
|
||||
# },
|
||||
# },
|
||||
# "ports": {
|
||||
# "type": "object",
|
||||
# "properties": {
|
||||
# "type": {
|
||||
# "description": "Port type",
|
||||
# "enum": ["access", "dot1q", "qinq"],
|
||||
# },
|
||||
# "vlan": {
|
||||
# "description": "VLAN number",
|
||||
# "type": "integer",
|
||||
# "minimum": 1
|
||||
# },
|
||||
# },
|
||||
# },
|
||||
},
|
||||
#"additionalProperties": False,
|
||||
"required": ["id"]
|
||||
|
||||
@@ -147,7 +147,7 @@ VM_RELOAD_SCHEMA = {
|
||||
"required": ["id"]
|
||||
}
|
||||
|
||||
#TODO: improve platform specific properties (dependencies?)
|
||||
# TODO: improve platform specific properties (dependencies?)
|
||||
VM_UPDATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"description": "Request validation to update a VM instance",
|
||||
|
||||
@@ -56,6 +56,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IOU(IModule):
|
||||
|
||||
"""
|
||||
IOU module.
|
||||
|
||||
@@ -635,7 +636,7 @@ class IOU(IModule):
|
||||
rhost = request["nio"]["rhost"]
|
||||
rport = request["nio"]["rport"]
|
||||
try:
|
||||
#TODO: handle IPv6
|
||||
# TODO: handle IPv6
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
sock.connect((rhost, rport))
|
||||
except OSError as e:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class Adapter(object):
|
||||
|
||||
"""
|
||||
Base class for adapters.
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class EthernetAdapter(Adapter):
|
||||
|
||||
"""
|
||||
IOU Ethernet adapter.
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class SerialAdapter(Adapter):
|
||||
|
||||
"""
|
||||
IOU Serial adapter.
|
||||
"""
|
||||
|
||||
@@ -43,6 +43,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IOUDevice(object):
|
||||
|
||||
"""
|
||||
IOU device implementation.
|
||||
|
||||
|
||||
@@ -56,22 +56,22 @@ EXIT_ABORT = 2
|
||||
# Mostly from:
|
||||
# https://code.google.com/p/miniboa/source/browse/trunk/miniboa/telnet.py
|
||||
#--[ Telnet Commands ]---------------------------------------------------------
|
||||
SE = 240 # End of sub-negotiation parameters
|
||||
NOP = 241 # No operation
|
||||
DATMK = 242 # Data stream portion of a sync.
|
||||
BREAK = 243 # NVT Character BRK
|
||||
IP = 244 # Interrupt Process
|
||||
AO = 245 # Abort Output
|
||||
AYT = 246 # Are you there
|
||||
EC = 247 # Erase Character
|
||||
EL = 248 # Erase Line
|
||||
GA = 249 # The Go Ahead Signal
|
||||
SB = 250 # Sub-option to follow
|
||||
WILL = 251 # Will; request or confirm option begin
|
||||
WONT = 252 # Wont; deny option request
|
||||
DO = 253 # Do = Request or confirm remote option
|
||||
DONT = 254 # Don't = Demand or confirm option halt
|
||||
IAC = 255 # Interpret as Command
|
||||
SE = 240 # End of sub-negotiation parameters
|
||||
NOP = 241 # No operation
|
||||
DATMK = 242 # Data stream portion of a sync.
|
||||
BREAK = 243 # NVT Character BRK
|
||||
IP = 244 # Interrupt Process
|
||||
AO = 245 # Abort Output
|
||||
AYT = 246 # Are you there
|
||||
EC = 247 # Erase Character
|
||||
EL = 248 # Erase Line
|
||||
GA = 249 # The Go Ahead Signal
|
||||
SB = 250 # Sub-option to follow
|
||||
WILL = 251 # Will; request or confirm option begin
|
||||
WONT = 252 # Wont; deny option request
|
||||
DO = 253 # Do = Request or confirm remote option
|
||||
DONT = 254 # Don't = Demand or confirm option halt
|
||||
IAC = 255 # Interpret as Command
|
||||
SEND = 1 # Sub-process negotiation SEND command
|
||||
IS = 0 # Sub-process negotiation IS command
|
||||
#--[ Telnet Options ]----------------------------------------------------------
|
||||
@@ -154,6 +154,7 @@ class FileLock:
|
||||
|
||||
|
||||
class Console:
|
||||
|
||||
def fileno(self):
|
||||
raise NotImplementedError("Only routers have fileno()")
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Base interface for NIOs.
|
||||
|
||||
|
||||
class NIO(object):
|
||||
|
||||
"""
|
||||
Network Input/Output.
|
||||
"""
|
||||
|
||||
@@ -23,6 +23,7 @@ from .nio import NIO
|
||||
|
||||
|
||||
class NIO_GenericEthernet(NIO):
|
||||
|
||||
"""
|
||||
Generic Ethernet NIO.
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from .nio import NIO
|
||||
|
||||
|
||||
class NIO_TAP(NIO):
|
||||
|
||||
"""
|
||||
TAP NIO.
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from .nio import NIO
|
||||
|
||||
|
||||
class NIO_UDP(NIO):
|
||||
|
||||
"""
|
||||
UDP NIO.
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Interface for TAP NIOs (UNIX based OSes only).
|
||||
|
||||
|
||||
class NIO_TAP(object):
|
||||
|
||||
"""
|
||||
TAP NIO.
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Interface for UDP NIOs.
|
||||
|
||||
|
||||
class NIO_UDP(object):
|
||||
|
||||
"""
|
||||
UDP NIO.
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import asyncio
|
||||
|
||||
|
||||
class PortManager:
|
||||
|
||||
"""
|
||||
:param host: IP address to bind for console connections
|
||||
"""
|
||||
|
||||
@@ -21,6 +21,7 @@ from uuid import uuid4
|
||||
|
||||
|
||||
class Project:
|
||||
|
||||
"""
|
||||
A project contains a list of VM.
|
||||
In theory VM are isolated project/project.
|
||||
|
||||
@@ -20,6 +20,7 @@ from .project import Project
|
||||
|
||||
|
||||
class ProjectManager:
|
||||
|
||||
"""
|
||||
This singleton keeps track of available projects.
|
||||
"""
|
||||
|
||||
@@ -49,6 +49,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Qemu(IModule):
|
||||
|
||||
"""
|
||||
QEMU module.
|
||||
|
||||
@@ -551,7 +552,7 @@ class Qemu(IModule):
|
||||
rhost = request["nio"]["rhost"]
|
||||
rport = request["nio"]["rport"]
|
||||
try:
|
||||
#TODO: handle IPv6
|
||||
# TODO: handle IPv6
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
sock.connect((rhost, rport))
|
||||
except OSError as e:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
class Adapter(object):
|
||||
|
||||
"""
|
||||
Base class for adapters.
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ from .adapter import Adapter
|
||||
|
||||
|
||||
class EthernetAdapter(Adapter):
|
||||
|
||||
"""
|
||||
QEMU Ethernet adapter.
|
||||
"""
|
||||
|
||||
@@ -21,6 +21,7 @@ Base interface for NIOs.
|
||||
|
||||
|
||||
class NIO(object):
|
||||
|
||||
"""
|
||||
Network Input/Output.
|
||||
"""
|
||||
|
||||
@@ -23,6 +23,7 @@ from .nio import NIO
|
||||
|
||||
|
||||
class NIO_UDP(NIO):
|
||||
|
||||
"""
|
||||
UDP NIO.
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class QemuVM(object):
|
||||
|
||||
"""
|
||||
QEMU VM implementation.
|
||||
|
||||
@@ -462,7 +463,6 @@ class QemuVM(object):
|
||||
disk_image=hdb_disk_image))
|
||||
self._hdb_disk_image = hdb_disk_image
|
||||
|
||||
|
||||
@property
|
||||
def adapters(self):
|
||||
"""
|
||||
@@ -586,7 +586,6 @@ class QemuVM(object):
|
||||
priority=process_priority))
|
||||
self._process_priority = process_priority
|
||||
|
||||
|
||||
@property
|
||||
def ram(self):
|
||||
"""
|
||||
@@ -999,18 +998,18 @@ class QemuVM(object):
|
||||
if self._legacy_networking:
|
||||
self._control_vm("host_net_remove {} gns3-{}".format(adapter_id, adapter_id))
|
||||
self._control_vm("host_net_add udp vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_id,
|
||||
adapter_id,
|
||||
nio.lport,
|
||||
nio.rport,
|
||||
nio.rhost))
|
||||
adapter_id,
|
||||
nio.lport,
|
||||
nio.rport,
|
||||
nio.rhost))
|
||||
else:
|
||||
self._control_vm("host_net_remove {} gns3-{}".format(adapter_id, adapter_id))
|
||||
self._control_vm("host_net_add socket vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_id,
|
||||
adapter_id,
|
||||
nio.rhost,
|
||||
nio.rport,
|
||||
self._host,
|
||||
nio.lport))
|
||||
adapter_id,
|
||||
nio.rhost,
|
||||
nio.rport,
|
||||
self._host,
|
||||
nio.lport))
|
||||
|
||||
adapter.add_nio(0, nio)
|
||||
log.info("QEMU VM {name} [id={id}]: {nio} added to adapter {adapter_id}".format(name=self._name,
|
||||
@@ -1154,8 +1153,8 @@ class QemuVM(object):
|
||||
if not os.path.exists(hdb_disk):
|
||||
try:
|
||||
retcode = subprocess.call([qemu_img_path, "create", "-o",
|
||||
"backing_file={}".format(self._hdb_disk_image),
|
||||
"-f", "qcow2", hdb_disk])
|
||||
"backing_file={}".format(self._hdb_disk_image),
|
||||
"-f", "qcow2", hdb_disk])
|
||||
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
raise QemuError("Could not create disk image {}".format(e))
|
||||
@@ -1190,24 +1189,24 @@ class QemuVM(object):
|
||||
network_options = []
|
||||
adapter_id = 0
|
||||
for adapter in self._ethernet_adapters:
|
||||
#TODO: let users specify a base mac address
|
||||
# TODO: let users specify a base mac address
|
||||
mac = "00:00:ab:%02x:%02x:%02d" % (random.randint(0x00, 0xff), random.randint(0x00, 0xff), adapter_id)
|
||||
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_id, mac, self._adapter_type)])
|
||||
nio = adapter.get_nio(0)
|
||||
if nio and isinstance(nio, NIO_UDP):
|
||||
if self._legacy_networking:
|
||||
network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_id,
|
||||
adapter_id,
|
||||
nio.lport,
|
||||
nio.rport,
|
||||
nio.rhost)])
|
||||
adapter_id,
|
||||
nio.lport,
|
||||
nio.rport,
|
||||
nio.rhost)])
|
||||
else:
|
||||
network_options.extend(["-net", "socket,vlan={},name=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_id,
|
||||
adapter_id,
|
||||
nio.rhost,
|
||||
nio.rport,
|
||||
self._host,
|
||||
nio.lport)])
|
||||
adapter_id,
|
||||
nio.rhost,
|
||||
nio.rport,
|
||||
self._host,
|
||||
nio.lport)])
|
||||
else:
|
||||
network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_id, adapter_id)])
|
||||
adapter_id += 1
|
||||
|
||||
@@ -31,6 +31,7 @@ if sys.platform.startswith("win"):
|
||||
|
||||
|
||||
class TelnetServer(threading.Thread):
|
||||
|
||||
"""
|
||||
Mini Telnet Server.
|
||||
|
||||
@@ -226,37 +227,38 @@ class TelnetServer(threading.Thread):
|
||||
# Mostly from https://code.google.com/p/miniboa/source/browse/trunk/miniboa/telnet.py
|
||||
|
||||
# Telnet Commands
|
||||
SE = 240 # End of sub-negotiation parameters
|
||||
NOP = 241 # No operation
|
||||
DATMK = 242 # Data stream portion of a sync.
|
||||
BREAK = 243 # NVT Character BRK
|
||||
IP = 244 # Interrupt Process
|
||||
AO = 245 # Abort Output
|
||||
AYT = 246 # Are you there
|
||||
EC = 247 # Erase Character
|
||||
EL = 248 # Erase Line
|
||||
GA = 249 # The Go Ahead Signal
|
||||
SB = 250 # Sub-option to follow
|
||||
WILL = 251 # Will; request or confirm option begin
|
||||
WONT = 252 # Wont; deny option request
|
||||
DO = 253 # Do = Request or confirm remote option
|
||||
DONT = 254 # Don't = Demand or confirm option halt
|
||||
IAC = 255 # Interpret as Command
|
||||
SEND = 1 # Sub-process negotiation SEND command
|
||||
IS = 0 # Sub-process negotiation IS command
|
||||
SE = 240 # End of sub-negotiation parameters
|
||||
NOP = 241 # No operation
|
||||
DATMK = 242 # Data stream portion of a sync.
|
||||
BREAK = 243 # NVT Character BRK
|
||||
IP = 244 # Interrupt Process
|
||||
AO = 245 # Abort Output
|
||||
AYT = 246 # Are you there
|
||||
EC = 247 # Erase Character
|
||||
EL = 248 # Erase Line
|
||||
GA = 249 # The Go Ahead Signal
|
||||
SB = 250 # Sub-option to follow
|
||||
WILL = 251 # Will; request or confirm option begin
|
||||
WONT = 252 # Wont; deny option request
|
||||
DO = 253 # Do = Request or confirm remote option
|
||||
DONT = 254 # Don't = Demand or confirm option halt
|
||||
IAC = 255 # Interpret as Command
|
||||
SEND = 1 # Sub-process negotiation SEND command
|
||||
IS = 0 # Sub-process negotiation IS command
|
||||
|
||||
# Telnet Options
|
||||
BINARY = 0 # Transmit Binary
|
||||
ECHO = 1 # Echo characters back to sender
|
||||
RECON = 2 # Reconnection
|
||||
SGA = 3 # Suppress Go-Ahead
|
||||
TMARK = 6 # Timing Mark
|
||||
TTYPE = 24 # Terminal Type
|
||||
NAWS = 31 # Negotiate About Window Size
|
||||
LINEMO = 34 # Line Mode
|
||||
BINARY = 0 # Transmit Binary
|
||||
ECHO = 1 # Echo characters back to sender
|
||||
RECON = 2 # Reconnection
|
||||
SGA = 3 # Suppress Go-Ahead
|
||||
TMARK = 6 # Timing Mark
|
||||
TTYPE = 24 # Terminal Type
|
||||
NAWS = 31 # Negotiate About Window Size
|
||||
LINEMO = 34 # Line Mode
|
||||
|
||||
|
||||
class TelnetClient(object):
|
||||
|
||||
"""
|
||||
Represents a Telnet client connection.
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class VirtualBoxVM(BaseVM):
|
||||
|
||||
"""
|
||||
VirtualBox VM implementation.
|
||||
"""
|
||||
@@ -58,7 +59,7 @@ class VirtualBoxVM(BaseVM):
|
||||
|
||||
self._system_properties = {}
|
||||
|
||||
#FIXME: harcoded values
|
||||
# FIXME: harcoded values
|
||||
if sys.platform.startswith("win"):
|
||||
self._vboxmanage_path = r"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
|
||||
else:
|
||||
@@ -367,7 +368,6 @@ class VirtualBoxVM(BaseVM):
|
||||
except OSError as e:
|
||||
raise VirtualBoxError("Could not write HDD info file: {}".format(e))
|
||||
|
||||
|
||||
log.info("VirtualBox VM {name} [id={id}] has been deleted".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
@@ -386,9 +386,9 @@ class VirtualBoxVM(BaseVM):
|
||||
if self._linked_clone:
|
||||
self._execute("unregistervm", [self._vmname, "--delete"])
|
||||
|
||||
#try:
|
||||
# try:
|
||||
# shutil.rmtree(self._working_dir)
|
||||
#except OSError as e:
|
||||
# except OSError as e:
|
||||
# log.error("could not delete VirtualBox VM {name} [id={id}]: {error}".format(name=self._name,
|
||||
# id=self._id,
|
||||
# error=e))
|
||||
|
||||
@@ -43,6 +43,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class VPCSVM(BaseVM):
|
||||
|
||||
"""
|
||||
VPCS vm implementation.
|
||||
|
||||
@@ -53,6 +54,7 @@ class VPCSVM(BaseVM):
|
||||
:param working_dir: path to a working directory
|
||||
:param console: TCP console port
|
||||
"""
|
||||
|
||||
def __init__(self, name, uuid, project, manager, working_dir=None, console=None):
|
||||
|
||||
super().__init__(name, uuid, project, manager)
|
||||
|
||||
Reference in new issue
Block a user