mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Check for valid IP address and prevent to run on non-Windows platforms.
This commit is contained in:
parent
05ec14e888
commit
b7780ba7cc
@ -24,8 +24,9 @@ from .virtualbox import VirtualBox
|
|||||||
from .dynamips import Dynamips
|
from .dynamips import Dynamips
|
||||||
from .qemu import Qemu
|
from .qemu import Qemu
|
||||||
from .vmware import VMware
|
from .vmware import VMware
|
||||||
|
from .traceng import TraceNG
|
||||||
|
|
||||||
MODULES = [Builtin, VPCS, VirtualBox, Dynamips, Qemu, VMware]
|
MODULES = [Builtin, VPCS, VirtualBox, Dynamips, Qemu, VMware, TraceNG]
|
||||||
|
|
||||||
if sys.platform.startswith("linux") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
if sys.platform.startswith("linux") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
||||||
# IOU & Docker only runs on Linux but test suite works on UNIX platform
|
# IOU & Docker only runs on Linux but test suite works on UNIX platform
|
||||||
@ -34,8 +35,3 @@ if sys.platform.startswith("linux") or hasattr(sys, "_called_from_test") or os.e
|
|||||||
MODULES.append(Docker)
|
MODULES.append(Docker)
|
||||||
from .iou import IOU
|
from .iou import IOU
|
||||||
MODULES.append(IOU)
|
MODULES.append(IOU)
|
||||||
|
|
||||||
#if sys.platform.startswith("win") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
|
||||||
# FIXME: TraceNG only runs on Windows but test suite works on UNIX platform
|
|
||||||
from .traceng import TraceNG
|
|
||||||
MODULES.append(TraceNG)
|
|
||||||
|
@ -19,11 +19,13 @@
|
|||||||
TraceNG VM management in order to run a TraceNG VM.
|
TraceNG VM management in order to run a TraceNG VM.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import asyncio
|
import asyncio
|
||||||
import shutil
|
import shutil
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
from gns3server.utils.asyncio import wait_for_process_termination
|
from gns3server.utils.asyncio import wait_for_process_termination
|
||||||
from gns3server.utils.asyncio import monitor_process
|
from gns3server.utils.asyncio import monitor_process
|
||||||
@ -152,11 +154,17 @@ class TraceNGVM(BaseNode):
|
|||||||
:param ip_address: IP address
|
:param ip_address: IP address
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
if ip_address:
|
||||||
|
ipaddress.IPv4Address(ip_address)
|
||||||
|
except ipaddress.AddressValueError:
|
||||||
|
raise TraceNGError("Invalid IP address: {}\n".format(ip_address))
|
||||||
|
|
||||||
|
self._ip_address = ip_address
|
||||||
log.info("{module}: {name} [{id}] set IP address to {ip_address}".format(module=self.manager.module_name,
|
log.info("{module}: {name} [{id}] set IP address to {ip_address}".format(module=self.manager.module_name,
|
||||||
name=self.name,
|
name=self.name,
|
||||||
id=self.id,
|
id=self.id,
|
||||||
ip_address=ip_address))
|
ip_address=ip_address))
|
||||||
self._ip_address = ip_address
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def start(self, destination=None):
|
def start(self, destination=None):
|
||||||
@ -164,6 +172,8 @@ class TraceNGVM(BaseNode):
|
|||||||
Starts the TraceNG process.
|
Starts the TraceNG process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not sys.platform.startswith("win"):
|
||||||
|
raise TraceNGError("Sorry, TraceNG can only run on Windows")
|
||||||
yield from self._check_requirements()
|
yield from self._check_requirements()
|
||||||
if not self.is_running():
|
if not self.is_running():
|
||||||
nio = self._ethernet_adapter.get_nio(0)
|
nio = self._ethernet_adapter.get_nio(0)
|
||||||
@ -382,11 +392,10 @@ class TraceNGVM(BaseNode):
|
|||||||
(to be passed to subprocess.Popen())
|
(to be passed to subprocess.Popen())
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: better validation
|
|
||||||
if not destination:
|
if not destination:
|
||||||
raise TraceNGError("Please provide a destination to trace")
|
raise TraceNGError("Please provide a host or IP address to trace")
|
||||||
if not self._ip_address:
|
if not self._ip_address:
|
||||||
raise TraceNGError("Please provide an IP address for this TraceNG node")
|
raise TraceNGError("Please configure an IP address for this TraceNG node")
|
||||||
|
|
||||||
command = [self._traceng_path()]
|
command = [self._traceng_path()]
|
||||||
# use the local UDP tunnel to uBridge instead
|
# use the local UDP tunnel to uBridge instead
|
||||||
|
@ -154,11 +154,12 @@ class Controller:
|
|||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "cloud"), {"node_type": "cloud", "name": "Cloud", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "cloud"), {"node_type": "cloud", "name": "Cloud", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "nat"), {"node_type": "nat", "name": "NAT", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "nat"), {"node_type": "nat", "name": "NAT", "category": 2, "symbol": ":/symbols/cloud.svg"}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "vpcs"), {"node_type": "vpcs", "name": "VPCS", "default_name_format": "PC-{0}", "category": 2, "symbol": ":/symbols/vpcs_guest.svg", "properties": {"base_script_file": "vpcs_base_config.txt"}}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "vpcs"), {"node_type": "vpcs", "name": "VPCS", "default_name_format": "PC-{0}", "category": 2, "symbol": ":/symbols/vpcs_guest.svg", "properties": {"base_script_file": "vpcs_base_config.txt"}}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "traceng"), {"node_type": "traceng", "name": "TraceNG", "default_name_format": "TraceNG-{0}", "category": 2, "symbol": ":/symbols/traceng.svg", "properties": {}}, builtin=True))
|
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_switch"), {"node_type": "ethernet_switch", "name": "Ethernet switch", "category": 1, "symbol": ":/symbols/ethernet_switch.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_switch"), {"node_type": "ethernet_switch", "name": "Ethernet switch", "category": 1, "symbol": ":/symbols/ethernet_switch.svg"}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_hub"), {"node_type": "ethernet_hub", "name": "Ethernet hub", "category": 1, "symbol": ":/symbols/hub.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "ethernet_hub"), {"node_type": "ethernet_hub", "name": "Ethernet hub", "category": 1, "symbol": ":/symbols/hub.svg"}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "frame_relay_switch"), {"node_type": "frame_relay_switch", "name": "Frame Relay switch", "category": 1, "symbol": ":/symbols/frame_relay_switch.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "frame_relay_switch"), {"node_type": "frame_relay_switch", "name": "Frame Relay switch", "category": 1, "symbol": ":/symbols/frame_relay_switch.svg"}, builtin=True))
|
||||||
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "atm_switch"), {"node_type": "atm_switch", "name": "ATM switch", "category": 1, "symbol": ":/symbols/atm_switch.svg"}, builtin=True))
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "atm_switch"), {"node_type": "atm_switch", "name": "ATM switch", "category": 1, "symbol": ":/symbols/atm_switch.svg"}, builtin=True))
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
builtins.append(Appliance(uuid.uuid3(uuid.NAMESPACE_DNS, "traceng"), {"node_type": "traceng", "name": "TraceNG", "default_name_format": "TraceNG-{0}", "category": 2, "symbol": ":/symbols/traceng.svg", "properties": {}}, builtin=True))
|
||||||
for b in builtins:
|
for b in builtins:
|
||||||
self._appliances[b.id] = b
|
self._appliances[b.id] = b
|
||||||
|
|
||||||
|
@ -906,7 +906,7 @@ class Project:
|
|||||||
pool = Pool(concurrency=3)
|
pool = Pool(concurrency=3)
|
||||||
for node in self.nodes.values():
|
for node in self.nodes.values():
|
||||||
if node.node_type == "traceng":
|
if node.node_type == "traceng":
|
||||||
#FIXME: maybe not the right place to do this...
|
self.controller.notification.emit("log.warning", "TraceNG nodes must be started one by one")
|
||||||
continue
|
continue
|
||||||
pool.append(node.start)
|
pool.append(node.start)
|
||||||
yield from pool.join()
|
yield from pool.join()
|
||||||
|
@ -34,13 +34,10 @@ from .ethernet_hub_handler import EthernetHubHandler
|
|||||||
from .ethernet_switch_handler import EthernetSwitchHandler
|
from .ethernet_switch_handler import EthernetSwitchHandler
|
||||||
from .frame_relay_switch_handler import FrameRelaySwitchHandler
|
from .frame_relay_switch_handler import FrameRelaySwitchHandler
|
||||||
from .atm_switch_handler import ATMSwitchHandler
|
from .atm_switch_handler import ATMSwitchHandler
|
||||||
|
from .traceng_handler import TraceNGHandler
|
||||||
|
|
||||||
if sys.platform.startswith("linux") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
if sys.platform.startswith("linux") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
||||||
# IOU & Docker only runs on Linux but test suite works on UNIX platform
|
# IOU & Docker only runs on Linux but test suite works on UNIX platform
|
||||||
if not sys.platform.startswith("win"):
|
if not sys.platform.startswith("win"):
|
||||||
from .iou_handler import IOUHandler
|
from .iou_handler import IOUHandler
|
||||||
from .docker_handler import DockerHandler
|
from .docker_handler import DockerHandler
|
||||||
|
|
||||||
#if sys.platform.startswith("win") or hasattr(sys, "_called_from_test") or os.environ.get("PYTEST_BUILD_DOCUMENTATION") == "1":
|
|
||||||
# FIXME: TraceNG only runs on Windows but test suite works on UNIX platform
|
|
||||||
from .traceng_handler import TraceNGHandler
|
|
||||||
|
Loading…
Reference in New Issue
Block a user