1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Merge branch '2.1' into 2.2

# Conflicts:
#	gns3server/schemas/node.py
This commit is contained in:
grossmj 2018-03-30 12:14:09 +07:00
commit 669d2ec038
18 changed files with 1952 additions and 15 deletions

View File

@ -24,15 +24,14 @@ 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
from .docker import Docker
MODULES.append(Docker)
# IOU runs only on Linux but testsuite work on UNIX platform
if not sys.platform.startswith("win"): if not sys.platform.startswith("win"):
from .docker import Docker
MODULES.append(Docker)
from .iou import IOU from .iou import IOU
MODULES.append(IOU) MODULES.append(IOU)

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
TraceNG server module.
"""
import asyncio
from ..base_manager import BaseManager
from .traceng_error import TraceNGError
from .traceng_vm import TraceNGVM
class TraceNG(BaseManager):
_NODE_CLASS = TraceNGVM
def __init__(self):
super().__init__()
@asyncio.coroutine
def create_node(self, *args, **kwargs):
"""
Creates a new TraceNG VM.
:returns: TraceNGVM instance
"""
return (yield from super().create_node(*args, **kwargs))

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Custom exceptions for the TraceNG module.
"""
from ..error import NodeError
class TraceNGError(NodeError):
pass

View File

@ -0,0 +1,427 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
TraceNG VM management in order to run a TraceNG VM.
"""
import sys
import os
import socket
import subprocess
import asyncio
import shutil
import ipaddress
from gns3server.utils.asyncio import wait_for_process_termination
from gns3server.utils.asyncio import monitor_process
from .traceng_error import TraceNGError
from ..adapters.ethernet_adapter import EthernetAdapter
from ..nios.nio_udp import NIOUDP
from ..base_node import BaseNode
import logging
log = logging.getLogger(__name__)
class TraceNGVM(BaseNode):
module_name = 'traceng'
"""
TraceNG VM implementation.
:param name: TraceNG VM name
:param node_id: Node identifier
:param project: Project instance
:param manager: Manager instance
:param console: TCP console port
"""
def __init__(self, name, node_id, project, manager, console=None, console_type="none"):
super().__init__(name, node_id, project, manager, console=console, console_type=console_type)
self._process = None
self._started = False
self._ip_address = None
self._destination = None
self._local_udp_tunnel = None
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
@property
def ethernet_adapter(self):
return self._ethernet_adapter
@asyncio.coroutine
def close(self):
"""
Closes this TraceNG VM.
"""
if not (yield from super().close()):
return False
nio = self._ethernet_adapter.get_nio(0)
if isinstance(nio, NIOUDP):
self.manager.port_manager.release_udp_port(nio.lport, self._project)
if self._local_udp_tunnel:
self.manager.port_manager.release_udp_port(self._local_udp_tunnel[0].lport, self._project)
self.manager.port_manager.release_udp_port(self._local_udp_tunnel[1].lport, self._project)
self._local_udp_tunnel = None
yield from self._stop_ubridge()
if self.is_running():
self._terminate_process()
return True
@asyncio.coroutine
def _check_requirements(self):
"""
Check if TraceNG is available.
"""
path = self._traceng_path()
if not path:
raise TraceNGError("No path to a TraceNG executable has been set")
# This raise an error if ubridge is not available
self.ubridge_path
if not os.path.isfile(path):
raise TraceNGError("TraceNG program '{}' is not accessible".format(path))
if not os.access(path, os.X_OK):
raise TraceNGError("TraceNG program '{}' is not executable".format(path))
def __json__(self):
return {"name": self.name,
"ip_address": self.ip_address,
"node_id": self.id,
"node_directory": self.working_path,
"status": self.status,
"console": self._console,
"console_type": "none",
"project_id": self.project.id,
"command_line": self.command_line}
def _traceng_path(self):
"""
Returns the TraceNG executable path.
:returns: path to TraceNG
"""
search_path = self._manager.config.get_section_config("TraceNG").get("traceng_path", "traceng")
path = shutil.which(search_path)
# shutil.which return None if the path doesn't exists
if not path:
return search_path
return path
@property
def ip_address(self):
"""
Returns the IP address for this node.
:returns: IP address
"""
return self._ip_address
@ip_address.setter
def ip_address(self, ip_address):
"""
Sets the IP address of this node.
: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,
name=self.name,
id=self.id,
ip_address=ip_address))
@asyncio.coroutine
def start(self, destination=None):
"""
Starts the TraceNG process.
"""
if not sys.platform.startswith("win"):
raise TraceNGError("Sorry, TraceNG can only run on Windows")
yield from self._check_requirements()
if not self.is_running():
nio = self._ethernet_adapter.get_nio(0)
command = self._build_command(destination)
yield from self._stop_ubridge() # make use we start with a fresh uBridge instance
try:
log.info("Starting TraceNG: {}".format(command))
flags = 0
if hasattr(subprocess, "CREATE_NEW_CONSOLE"):
flags = subprocess.CREATE_NEW_CONSOLE
self.command_line = ' '.join(command)
self._process = yield from asyncio.create_subprocess_exec(*command,
cwd=self.working_dir,
creationflags=flags)
monitor_process(self._process, self._termination_callback)
yield from self._start_ubridge()
if nio:
yield from self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
log.info("TraceNG instance {} started PID={}".format(self.name, self._process.pid))
self._started = True
self.status = "started"
except (OSError, subprocess.SubprocessError) as e:
log.error("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
raise TraceNGError("Could not start TraceNG {}: {}\n".format(self._traceng_path(), e))
def _termination_callback(self, returncode):
"""
Called when the process has stopped.
:param returncode: Process returncode
"""
if self._started:
log.info("TraceNG process has stopped, return code: %d", returncode)
self._started = False
self.status = "stopped"
self._process = None
if returncode != 0:
self.project.emit("log.error", {"message": "TraceNG process has stopped, return code: {}\n".format(returncode)})
@asyncio.coroutine
def stop(self):
"""
Stops the TraceNG process.
"""
yield from self._stop_ubridge()
if self.is_running():
self._terminate_process()
if self._process.returncode is None:
try:
yield from wait_for_process_termination(self._process, timeout=3)
except asyncio.TimeoutError:
if self._process.returncode is None:
try:
self._process.kill()
except OSError as e:
log.error("Cannot stop the TraceNG process: {}".format(e))
if self._process.returncode is None:
log.warning('TraceNG VM "{}" with PID={} is still running'.format(self._name, self._process.pid))
self._process = None
self._started = False
yield from super().stop()
@asyncio.coroutine
def reload(self):
"""
Reloads the TraceNG process (stop & start).
"""
yield from self.stop()
yield from self.start(self._destination)
def _terminate_process(self):
"""
Terminate the process if running
"""
log.info("Stopping TraceNG instance {} PID={}".format(self.name, self._process.pid))
#if sys.platform.startswith("win32"):
# self._process.send_signal(signal.CTRL_BREAK_EVENT)
#else:
try:
self._process.terminate()
# Sometime the process may already be dead when we garbage collect
except ProcessLookupError:
pass
def is_running(self):
"""
Checks if the TraceNG process is running
:returns: True or False
"""
if self._process and self._process.returncode is None:
return True
return False
@asyncio.coroutine
def port_add_nio_binding(self, port_number, nio):
"""
Adds a port NIO binding.
:param port_number: port number
:param nio: NIO instance to add to the slot/port
"""
if not self._ethernet_adapter.port_exists(port_number):
raise TraceNGError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
port_number=port_number))
if self.is_running():
yield from self.add_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
self._ethernet_adapter.add_nio(port_number, nio)
log.info('TraceNG "{name}" [{id}]: {nio} added to port {port_number}'.format(name=self._name,
id=self.id,
nio=nio,
port_number=port_number))
return nio
@asyncio.coroutine
def port_update_nio_binding(self, port_number, nio):
if not self._ethernet_adapter.port_exists(port_number):
raise TraceNGError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
port_number=port_number))
if self.is_running():
yield from self.update_ubridge_udp_connection("TraceNG-{}".format(self._id), self._local_udp_tunnel[1], nio)
@asyncio.coroutine
def port_remove_nio_binding(self, port_number):
"""
Removes a port NIO binding.
:param port_number: port number
:returns: NIO instance
"""
if not self._ethernet_adapter.port_exists(port_number):
raise TraceNGError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
port_number=port_number))
if self.is_running():
yield from self._ubridge_send("bridge delete {name}".format(name="TraceNG-{}".format(self._id)))
nio = self._ethernet_adapter.get_nio(port_number)
if isinstance(nio, NIOUDP):
self.manager.port_manager.release_udp_port(nio.lport, self._project)
self._ethernet_adapter.remove_nio(port_number)
log.info('TraceNG "{name}" [{id}]: {nio} removed from port {port_number}'.format(name=self._name,
id=self.id,
nio=nio,
port_number=port_number))
return nio
@asyncio.coroutine
def start_capture(self, port_number, output_file):
"""
Starts a packet capture.
:param port_number: port number
:param output_file: PCAP destination file for the capture
"""
if not self._ethernet_adapter.port_exists(port_number):
raise TraceNGError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
port_number=port_number))
nio = self._ethernet_adapter.get_nio(0)
if not nio:
raise TraceNGError("Port {} is not connected".format(port_number))
if nio.capturing:
raise TraceNGError("Packet capture is already activated on port {port_number}".format(port_number=port_number))
nio.startPacketCapture(output_file)
if self.ubridge:
yield from self._ubridge_send('bridge start_capture {name} "{output_file}"'.format(name="TraceNG-{}".format(self._id),
output_file=output_file))
log.info("TraceNG '{name}' [{id}]: starting packet capture on port {port_number}".format(name=self.name,
id=self.id,
port_number=port_number))
@asyncio.coroutine
def stop_capture(self, port_number):
"""
Stops a packet capture.
:param port_number: port number
"""
if not self._ethernet_adapter.port_exists(port_number):
raise TraceNGError("Port {port_number} doesn't exist in adapter {adapter}".format(adapter=self._ethernet_adapter,
port_number=port_number))
nio = self._ethernet_adapter.get_nio(0)
if not nio:
raise TraceNGError("Port {} is not connected".format(port_number))
nio.stopPacketCapture()
if self.ubridge:
yield from self._ubridge_send('bridge stop_capture {name}'.format(name="TraceNG-{}".format(self._id)))
log.info("TraceNG '{name}' [{id}]: stopping packet capture on port {port_number}".format(name=self.name,
id=self.id,
port_number=port_number))
def _build_command(self, destination):
"""
Command to start the TraceNG process.
(to be passed to subprocess.Popen())
"""
if not destination:
raise TraceNGError("Please provide a host or IP address to trace")
if not self._ip_address:
raise TraceNGError("Please configure an IP address for this TraceNG node")
self._destination = destination
command = [self._traceng_path()]
# use the local UDP tunnel to uBridge instead
if not self._local_udp_tunnel:
self._local_udp_tunnel = self._create_local_udp_tunnel()
nio = self._local_udp_tunnel[0]
if nio and isinstance(nio, NIOUDP):
# UDP tunnel
command.extend(["-u"]) # enable UDP tunnel
command.extend(["-c", str(nio.lport)]) # source UDP port
command.extend(["-v", str(nio.rport)]) # destination UDP port
try:
command.extend(["-b", socket.gethostbyname(nio.rhost)]) # destination host, we need to resolve the hostname because TraceNG doesn't support it
except socket.gaierror as e:
raise TraceNGError("Can't resolve hostname {}: {}".format(nio.rhost, e))
command.extend(["-s", "ICMP"]) # Use ICMP probe type by default
command.extend(["-f", self._ip_address]) # source IP address to trace from
command.extend([destination]) # host or IP to trace
return command

View File

@ -116,6 +116,9 @@ class Controller:
for vm in self._settings.get("VPCS", {}).get("nodes", []): for vm in self._settings.get("VPCS", {}).get("nodes", []):
vm["node_type"] = "vpcs" vm["node_type"] = "vpcs"
vms.append(vm) vms.append(vm)
for vm in self._settings.get("TraceNG", {}).get("nodes", []):
vm["node_type"] = "traceng"
vms.append(vm)
for vm in vms: for vm in vms:
# remove deprecated properties # remove deprecated properties
@ -154,6 +157,8 @@ class Controller:
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

View File

@ -417,6 +417,7 @@ class Link:
""" """
for node in self._nodes: for node in self._nodes:
if node["node"].node_type in ('vpcs', if node["node"].node_type in ('vpcs',
'traceng',
'vmware', 'vmware',
'dynamips', 'dynamips',
'qemu', 'qemu',

View File

@ -120,7 +120,7 @@ class Node:
return self.node_type not in ( return self.node_type not in (
"qemu", "docker", "dynamips", "qemu", "docker", "dynamips",
"vpcs", "vmware", "virtualbox", "vpcs", "vmware", "virtualbox",
"iou") "iou", "traceng")
@property @property
def id(self): def id(self):
@ -454,7 +454,7 @@ class Node:
yield from self.delete() yield from self.delete()
@asyncio.coroutine @asyncio.coroutine
def start(self): def start(self, data=None):
""" """
Start a node Start a node
""" """
@ -467,7 +467,7 @@ class Node:
raise aiohttp.web.HTTPConflict(text="IOU licence is not configured") raise aiohttp.web.HTTPConflict(text="IOU licence is not configured")
yield from self.post("/start", timeout=240, data={"iourc_content": licence}) yield from self.post("/start", timeout=240, data={"iourc_content": licence})
else: else:
yield from self.post("/start", timeout=240) yield from self.post("/start", data=data, timeout=240)
except asyncio.TimeoutError: except asyncio.TimeoutError:
raise aiohttp.web.HTTPRequestTimeout(text="Timeout when starting {}".format(self._name)) raise aiohttp.web.HTTPRequestTimeout(text="Timeout when starting {}".format(self._name))
@ -622,7 +622,7 @@ class Node:
for port in self._properties["ports_mapping"]: for port in self._properties["ports_mapping"]:
self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet", short_name="e{}".format(port_number))) self._ports.append(PortFactory(port["name"], 0, 0, port_number, "ethernet", short_name="e{}".format(port_number)))
port_number += 1 port_number += 1
elif self._node_type in ("vpcs"): elif self._node_type in ("vpcs", "traceng"):
self._ports.append(PortFactory("Ethernet0", 0, 0, 0, "ethernet", short_name="e0")) self._ports.append(PortFactory("Ethernet0", 0, 0, 0, "ethernet", short_name="e0"))
elif self._node_type in ("cloud", "nat"): elif self._node_type in ("cloud", "nat"):
port_number = 0 port_number = 0

View File

@ -939,7 +939,12 @@ class Project:
Start all nodes Start all nodes
""" """
pool = Pool(concurrency=3) pool = Pool(concurrency=3)
emit_warning = True
for node in self.nodes.values(): for node in self.nodes.values():
if node.node_type == "traceng" and emit_warning:
self.controller.notification.emit("log.warning", {"message": "TraceNG nodes must be started one by one"})
emit_warning = False
continue
pool.append(node.start) pool.append(node.start)
yield from pool.join() yield from pool.join()

View File

@ -34,9 +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 runs only 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

View File

@ -0,0 +1,339 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from aiohttp.web import HTTPConflict
from gns3server.web.route import Route
from gns3server.schemas.nio import NIO_SCHEMA
from gns3server.schemas.node import NODE_CAPTURE_SCHEMA
from gns3server.compute.traceng import TraceNG
from gns3server.schemas.traceng import (
TRACENG_CREATE_SCHEMA,
TRACENG_UPDATE_SCHEMA,
TRACENG_START_SCHEMA,
TRACENG_OBJECT_SCHEMA
)
class TraceNGHandler:
"""
API entry points for TraceNG.
"""
@Route.post(
r"/projects/{project_id}/traceng/nodes",
parameters={
"project_id": "Project UUID"
},
status_codes={
201: "Instance created",
400: "Invalid request",
409: "Conflict"
},
description="Create a new TraceNG instance",
input=TRACENG_CREATE_SCHEMA,
output=TRACENG_OBJECT_SCHEMA)
def create(request, response):
traceng = TraceNG.instance()
vm = yield from traceng.create_node(request.json["name"],
request.match_info["project_id"],
request.json.get("node_id"),
console=request.json.get("console"))
vm.ip_address = request.json.get("ip_address", "") # FIXME, required IP address to create node?
response.set_status(201)
response.json(vm)
@Route.get(
r"/projects/{project_id}/traceng/nodes/{node_id}",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
200: "Success",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Get a TraceNG instance",
output=TRACENG_OBJECT_SCHEMA)
def show(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
response.json(vm)
@Route.put(
r"/projects/{project_id}/traceng/nodes/{node_id}",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
200: "Instance updated",
400: "Invalid request",
404: "Instance doesn't exist",
409: "Conflict"
},
description="Update a TraceNG instance",
input=TRACENG_UPDATE_SCHEMA,
output=TRACENG_OBJECT_SCHEMA)
def update(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
vm.name = request.json.get("name", vm.name)
vm.ip_address = request.json.get("ip_address", vm.ip_address)
vm.updated()
response.json(vm)
@Route.delete(
r"/projects/{project_id}/traceng/nodes/{node_id}",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
204: "Instance deleted",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Delete a TraceNG instance")
def delete(request, response):
yield from TraceNG.instance().delete_node(request.match_info["node_id"])
response.set_status(204)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/duplicate",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
201: "Instance duplicated",
404: "Instance doesn't exist"
},
description="Duplicate a TraceNG instance")
def duplicate(request, response):
new_node = yield from TraceNG.instance().duplicate_node(
request.match_info["node_id"],
request.json["destination_node_id"]
)
response.set_status(201)
response.json(new_node)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/start",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
204: "Instance started",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Start a TraceNG instance",
input=TRACENG_START_SCHEMA,
output=TRACENG_OBJECT_SCHEMA)
def start(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
yield from vm.start(request.json["destination"])
response.json(vm)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/stop",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
204: "Instance stopped",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Stop a TraceNG instance")
def stop(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
yield from vm.stop()
response.set_status(204)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/suspend",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID"
},
status_codes={
204: "Instance suspended",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Suspend a TraceNG instance (does nothing)")
def suspend(request, response):
traceng_manager = TraceNG.instance()
traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
response.set_status(204)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/reload",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
},
status_codes={
204: "Instance reloaded",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Reload a TraceNG instance")
def reload(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
yield from vm.reload()
response.set_status(204)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port where the nio should be added"
},
status_codes={
201: "NIO created",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Add a NIO to a TraceNG instance",
input=NIO_SCHEMA,
output=NIO_SCHEMA)
def create_nio(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio_type = request.json["type"]
if nio_type not in ("nio_udp"):
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
nio = traceng_manager.create_nio(request.json)
yield from vm.port_add_nio_binding(int(request.match_info["port_number"]), nio)
response.set_status(201)
response.json(nio)
@Route.put(
r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port from where the nio should be updated"
},
status_codes={
201: "NIO updated",
400: "Invalid request",
404: "Instance doesn't exist"
},
input=NIO_SCHEMA,
output=NIO_SCHEMA,
description="Update a NIO from a TraceNG instance")
def update_nio(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio = vm.ethernet_adapter.get_nio(int(request.match_info["port_number"]))
if "filters" in request.json and nio:
nio.filters = request.json["filters"]
yield from vm.port_update_nio_binding(int(request.match_info["port_number"]), nio)
response.set_status(201)
response.json(request.json)
@Route.delete(
r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
"adapter_number": "Network adapter where the nio is located",
"port_number": "Port from where the nio should be removed"
},
status_codes={
204: "NIO deleted",
400: "Invalid request",
404: "Instance doesn't exist"
},
description="Remove a NIO from a TraceNG instance")
def delete_nio(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
yield from vm.port_remove_nio_binding(int(request.match_info["port_number"]))
response.set_status(204)
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/start_capture",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
"adapter_number": "Adapter to start a packet capture",
"port_number": "Port on the adapter"
},
status_codes={
200: "Capture started",
400: "Invalid request",
404: "Instance doesn't exist",
},
description="Start a packet capture on a TraceNG instance",
input=NODE_CAPTURE_SCHEMA)
def start_capture(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
port_number = int(request.match_info["port_number"])
pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
yield from vm.start_capture(port_number, pcap_file_path)
response.json({"pcap_file_path": pcap_file_path})
@Route.post(
r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/stop_capture",
parameters={
"project_id": "Project UUID",
"node_id": "Node UUID",
"adapter_number": "Adapter to stop a packet capture",
"port_number": "Port on the adapter"
},
status_codes={
204: "Capture stopped",
400: "Invalid request",
404: "Instance doesn't exist",
},
description="Stop a packet capture on a TraceNG instance")
def stop_capture(request, response):
traceng_manager = TraceNG.instance()
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
port_number = int(request.match_info["port_number"])
yield from vm.stop_capture(port_number)
response.set_status(204)

View File

@ -223,7 +223,7 @@ class NodeHandler:
project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"]) project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"])
node = project.get_node(request.match_info["node_id"]) node = project.get_node(request.match_info["node_id"])
yield from node.start() yield from node.start(data=request.json)
response.json(node) response.json(node)
response.set_status(201) response.set_status(201)

View File

@ -183,7 +183,7 @@ def kill_ghosts():
""" """
Kill process from previous GNS3 session Kill process from previous GNS3 session
""" """
detect_process = ["vpcs", "ubridge", "dynamips"] detect_process = ["vpcs", "traceng", "ubridge", "dynamips"]
for proc in psutil.process_iter(): for proc in psutil.process_iter():
try: try:
name = proc.name().lower().split(".")[0] name = proc.name().lower().split(".")[0]

View File

@ -30,6 +30,7 @@ NODE_TYPE_SCHEMA = {
"docker", "docker",
"dynamips", "dynamips",
"vpcs", "vpcs",
"traceng",
"virtualbox", "virtualbox",
"vmware", "vmware",
"iou", "iou",

View File

@ -0,0 +1,151 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
TRACENG_CREATE_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to create a new TraceNG instance",
"type": "object",
"properties": {
"name": {
"description": "TraceNG VM name",
"type": "string",
"minLength": 1,
},
"node_id": {
"description": "Node UUID",
"oneOf": [
{"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"}
]
},
"console": {
"description": "Console TCP port",
"minimum": 1,
"maximum": 65535,
"type": ["integer", "null"]
},
"console_type": {
"description": "Console type",
"enum": ["none"]
},
"ip_address": {
"description": "Source IP address for tracing",
"type": ["string"]
}
},
"additionalProperties": False,
"required": ["name"]
}
TRACENG_UPDATE_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to update a TraceNG instance",
"type": "object",
"properties": {
"name": {
"description": "TraceNG VM name",
"type": ["string", "null"],
"minLength": 1,
},
"console": {
"description": "Console TCP port",
"minimum": 1,
"maximum": 65535,
"type": ["integer", "null"]
},
"console_type": {
"description": "Console type",
"enum": ["none"]
},
"ip_address": {
"description": "Source IP address for tracing",
"type": ["string"]
}
},
"additionalProperties": False,
}
TRACENG_START_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to start a TraceNG instance",
"type": "object",
"properties": {
"destination": {
"description": "Host or IP address to trace",
"type": ["string"]
}
},
"required": ["destination"],
}
TRACENG_OBJECT_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "TraceNG instance",
"type": "object",
"properties": {
"name": {
"description": "TraceNG VM name",
"type": "string",
"minLength": 1,
},
"node_id": {
"description": "Node UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"node_directory": {
"description": "Path to the VM working directory",
"type": "string"
},
"status": {
"description": "VM status",
"enum": ["started", "stopped", "suspended"]
},
"console": {
"description": "Console TCP port",
"minimum": 1,
"maximum": 65535,
"type": ["integer", "null"]
},
"console_type": {
"description": "Console type",
"enum": ["none"]
},
"project_id": {
"description": "Project UUID",
"type": "string",
"minLength": 36,
"maxLength": 36,
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
},
"command_line": {
"description": "Last command line used by GNS3 to start TraceNG",
"type": "string"
},
"ip_address": {
"description": "Source IP address for tracing",
"type": ["string"]
}
},
"additionalProperties": False,
"required": ["name", "node_id", "status", "console", "console_type", "project_id", "command_line", "ip_address"]
}

View File

@ -0,0 +1,610 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="59.253815"
id="Andysvg"
inkscape:version="0.91 r13725"
sodipodi:docname="traceng.svg"
sodipodi:version="0.32"
version="1.0"
width="65.414536"
x="0.00000000"
y="0.00000000"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<metadata
id="metadata3">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:title />
<dc:description />
<dc:subject>
<rdf:Bag>
<rdf:li>hash</rdf:li>
<rdf:li />
<rdf:li>hardware</rdf:li>
<rdf:li>computer</rdf:li>
</rdf:Bag>
</dc:subject>
<dc:publisher>
<cc:Agent
rdf:about="http://www.openclipart.org">
<dc:title>Andy Fitzsimon</dc:title>
</cc:Agent>
</dc:publisher>
<dc:creator>
<cc:Agent>
<dc:title>Andy Fitzsimon</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>Andy Fitzsimon</dc:title>
</cc:Agent>
</dc:rights>
<dc:date />
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<cc:license
rdf:resource="http://web.resource.org/cc/PublicDomain" />
<dc:language>en</dc:language>
</cc:Work>
<cc:License
rdf:about="http://web.resource.org/cc/PublicDomain">
<cc:permits
rdf:resource="http://web.resource.org/cc/Reproduction" />
<cc:permits
rdf:resource="http://web.resource.org/cc/Distribution" />
<cc:permits
rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
</cc:License>
</rdf:RDF>
</metadata>
<defs
id="defs3">
<linearGradient
id="linearGradient1806">
<stop
id="stop1807"
offset="0.0000000"
style="stop-color:#000000;stop-opacity:0.35051546;" />
<stop
id="stop3276"
offset="0.64999998"
style="stop-color:#000000;stop-opacity:0.13402061;" />
<stop
id="stop1808"
offset="1.0000000"
style="stop-color:#000000;stop-opacity:0.0000000;" />
</linearGradient>
<radialGradient
cx="42.007256"
cy="39.007645"
fx="42.280807"
fy="39.410465"
id="radialGradient1977"
r="11.574221"
xlink:href="#linearGradient1806"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient893">
<stop
id="stop895"
offset="0"
style="stop-color:#000;stop-opacity:1;" />
<stop
id="stop896"
offset="1"
style="stop-color:#fff;stop-opacity:1;" />
</linearGradient>
<linearGradient
id="linearGradient1317">
<stop
id="stop1318"
offset="0.00000000"
style="stop-color:#000000;stop-opacity:0.52892560;" />
<stop
id="stop1320"
offset="0.50000000"
style="stop-color:#000000;stop-opacity:0.17355372;" />
<stop
id="stop1319"
offset="1.0000000"
style="stop-color:#000000;stop-opacity:0.00000000;" />
</linearGradient>
<linearGradient
id="linearGradient1133">
<stop
id="stop1134"
offset="0.00000000"
style="stop-color:#8bb7df;stop-opacity:1.0000000;" />
<stop
id="stop1136"
offset="0.76209301"
style="stop-color:#2a6092;stop-opacity:1.0000000;" />
<stop
id="stop1135"
offset="1.0000000"
style="stop-color:#375e82;stop-opacity:1.0000000;" />
</linearGradient>
<linearGradient
id="linearGradient1098">
<stop
id="stop1099"
offset="0.00000000"
style="stop-color:#ffffff;stop-opacity:1.0000000;" />
<stop
id="stop1101"
offset="0.50000000"
style="stop-color:#ffffff;stop-opacity:0.22314049;" />
<stop
id="stop1102"
offset="0.59930235"
style="stop-color:#ffffff;stop-opacity:0.00000000;" />
<stop
id="stop1100"
offset="1.0000000"
style="stop-color:#ffffff;stop-opacity:0.60330576;" />
</linearGradient>
<linearGradient
id="linearGradient902">
<stop
id="stop903"
offset="0.00000000"
style="stop-color:#000000;stop-opacity:0.00000000;" />
<stop
id="stop904"
offset="1.0000000"
style="stop-color:#000000;stop-opacity:0.22000000;" />
</linearGradient>
<linearGradient
id="linearGradient892">
<stop
id="stop893"
offset="0.00000000"
style="stop-color:#ffffff;stop-opacity:0.00000000;" />
<stop
id="stop894"
offset="1"
style="stop-color:#fff;stop-opacity:1;" />
</linearGradient>
<linearGradient
id="linearGradient888">
<stop
id="stop889"
offset="0.0000000"
style="stop-color:#626262;stop-opacity:1.0000000;" />
<stop
id="stop890"
offset="1"
style="stop-color:#fff;stop-opacity:1;" />
</linearGradient>
<linearGradient
id="linearGradient891"
x1="92.437965"
x2="27.674332"
xlink:href="#linearGradient888"
y1="-3.9104078"
y2="91.076988"
gradientTransform="matrix(0.8184166,0,0,0.530237,-9.8827678,-14.589608)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient901"
xlink:href="#linearGradient1806"
gradientTransform="matrix(0.8517959,0,0,0.5754549,70.875335,-17.351492)"
x1="9.4921856"
y1="22.862282"
x2="41.719688"
y2="22.862282"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient905"
x1="-77.726181"
x2="95.64444"
xlink:href="#linearGradient888"
y1="208.43991"
y2="11.699047"
gradientTransform="matrix(0.7314635,0,0,0.5932693,-9.8827694,-14.589616)"
gradientUnits="userSpaceOnUse" />
<radialGradient
cx="60.004654"
cy="56.485935"
fx="72.10788"
fy="39.288475"
id="radialGradient1132"
r="68.589226"
xlink:href="#linearGradient1133"
gradientTransform="matrix(0.8184166,0,0,0.530237,-9.8827678,-14.589608)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1138"
x1="-249.72067"
x2="-268.25406"
xlink:href="#linearGradient1806"
y1="375.922"
y2="75.912529"
gradientTransform="scale(1.087146,0.91984)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1140"
x1="45.685757"
x2="41.96706"
xlink:href="#linearGradient888"
y1="110.4447"
y2="232.24953"
gradientTransform="matrix(1.2743811,0,0,0.3405213,-9.8827694,-14.589616)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1141"
x1="0"
x2="0.92957747"
xlink:href="#linearGradient888"
y1="3.3012049"
y2="-0.45783132" />
<linearGradient
id="linearGradient1144"
x1="31.449743"
x2="31.617281"
xlink:href="#linearGradient892"
y1="203.49899"
y2="251.21892"
gradientTransform="matrix(1.4044089,0,0,0.3089952,-9.8827694,-14.589616)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1146"
x1="39.810947"
x2="17.87653"
xlink:href="#linearGradient892"
y1="90.197021"
y2="113.71949"
gradientTransform="matrix(0.8811179,0,0,0.4925045,-9.8827694,-14.589616)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1148"
x1="39.690613"
x2="70.224304"
xlink:href="#linearGradient892"
y1="49.507656"
y2="20.481863"
gradientTransform="scale(1.329144,0.752364)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1150"
x1="35.190361"
x2="8.3460579"
xlink:href="#linearGradient892"
y1="76.277557"
y2="105.42543"
gradientTransform="scale(1.328386,0.752793)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1156"
x1="25.220816"
x2="25.220816"
xlink:href="#linearGradient888"
y1="178.48862"
y2="234.26866"
gradientTransform="matrix(1.6156202,0,0,0.2685999,-9.8827678,-14.589608)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1157"
x1="51.46093"
x2="-16.224497"
xlink:href="#linearGradient888"
y1="269.85831"
y2="176.28694"
gradientTransform="matrix(1.6156202,0,0,0.2685999,-9.8827678,-14.589608)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1166"
x1="111.49758"
x2="107.04918"
xlink:href="#linearGradient1317"
y1="131.25249"
y2="148.78619"
gradientTransform="matrix(0.562951,0,0,0.378005,1.021178,-9.426161)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1167"
x1="141.60217"
x2="88.447014"
xlink:href="#linearGradient888"
y1="228.39311"
y2="133.5471"
gradientTransform="matrix(0.544555,0,0,0.390775,1.021178,-9.426161)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1169"
x1="146.69923"
x2="74.533691"
xlink:href="#linearGradient893"
y1="224.57898"
y2="81.4776"
gradientTransform="matrix(0.546024,0,0,0.389723,1.021178,-9.426161)"
gradientUnits="userSpaceOnUse" />
<linearGradient
gradientTransform="scale(0.998371,1.001632)"
id="linearGradient1170"
x1="0.47284532"
x2="0.48655096"
xlink:href="#linearGradient902"
y1="-0.016295359"
y2="1.8378206" />
<linearGradient
id="linearGradient1171"
x1="101.10657"
x2="95.100159"
xlink:href="#linearGradient902"
y1="177.77768"
y2="173.03152"
gradientTransform="matrix(0.62565,0,0,0.340123,1.021178,-9.426161)"
gradientUnits="userSpaceOnUse" />
<radialGradient
cx="0.47887325"
cy="0.53333336"
fx="0.47535211"
fy="0.26666668"
id="radialGradient1315"
r="0.41197181"
xlink:href="#linearGradient1317" />
<radialGradient
cx="0.5"
cy="0.50000006"
fx="0.50352114"
fy="0.18269235"
id="radialGradient1316"
r="0.34964636"
xlink:href="#linearGradient1317" />
<linearGradient
id="linearGradient1404"
x1="88.755692"
x2="88.996956"
xlink:href="#linearGradient892"
y1="169.09755"
y2="182.99155"
gradientTransform="matrix(0.629979,0,0,0.337786,1.021178,-9.426161)"
gradientUnits="userSpaceOnUse" />
<linearGradient
gradientTransform="scale(0.997825,1.00218)"
id="linearGradient1505"
x1="0.47157744"
x2="0.48548824"
xlink:href="#linearGradient902"
y1="-0.02485317"
y2="1.8570156" />
<linearGradient
gradientTransform="scale(0.995847,1.00417)"
id="linearGradient1506"
x1="0.4704251"
x2="0.48481107"
xlink:href="#linearGradient902"
y1="-0.04365262"
y2="1.9025002" />
<linearGradient
gradientTransform="scale(0.997153,1.002855)"
id="linearGradient2740"
x1="0.47041038"
x2="0.48453596"
xlink:href="#linearGradient902"
y1="-0.033741195"
y2="1.8771822" />
<linearGradient
id="linearGradient4283"
x1="-0.77314812"
x2="0.99074072"
xlink:href="#linearGradient893"
y1="2.0837989"
y2="-0.033519555" />
<linearGradient
id="linearGradient4284"
x1="-2.3960868e-17"
x2="0.92957747"
xlink:href="#linearGradient893"
y1="3.3012049"
y2="-0.45783132" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1806"
id="linearGradient1948"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.087146,0.91984)"
x1="-249.72067"
y1="375.922"
x2="-268.25406"
y2="75.912529" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1806"
id="linearGradient1950"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.087146,0.91984)"
x1="-249.72067"
y1="375.922"
x2="-268.25406"
y2="75.912529" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1806"
id="linearGradient1952"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.087146,0.91984)"
x1="-249.72067"
y1="375.922"
x2="-268.25406"
y2="75.912529" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient892"
id="linearGradient2625"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.329144,0.752364)"
x1="39.690613"
y1="49.507656"
x2="70.224304"
y2="20.481863" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient892"
id="linearGradient2627"
gradientUnits="userSpaceOnUse"
gradientTransform="scale(1.328386,0.752793)"
x1="35.190361"
y1="76.277557"
x2="8.3460579"
y2="105.42543" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient888"
id="linearGradient2633"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.3870648,0,0,0.2694829,71.57581,-24.087318)"
x1="92.437965"
y1="-3.9104078"
x2="27.674332"
y2="91.076988" />
</defs>
<sodipodi:namedview
bordercolor="#666666"
borderopacity="1.0"
id="base"
inkscape:cx="26.459162"
inkscape:cy="28.090626"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:window-height="1405"
inkscape:window-width="2280"
inkscape:window-x="696"
inkscape:window-y="149"
inkscape:zoom="16"
pagecolor="#ffffff"
showborder="true"
inkscape:current-layer="Andysvg"
showgrid="false"
inkscape:window-maximized="0" />
<rect
height="5.4088969"
id="rect1155"
style="fill:url(#linearGradient1156);fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient1157);stroke-width:0.95344429pt"
width="38.405891"
x="12.350429"
y="36.575089" />
<path
d="M 0.19287398,54.885213 C -0.67386281,56.46268 1.5579198,59.253939 3.3933636,59.253939 L 62.069027,59.253939 C 63.628857,59.253939 65.976201,57.281205 65.269522,55.925378 L 58.655165,43.235277 C 58.145696,42.257819 57.005954,41.779036 55.881408,41.779036 L 8.9408812,41.779036 C 8.0135624,41.779036 7.0317541,42.438291 6.5938539,43.235277 L 0.19287398,54.885213 z "
id="path1139"
sodipodi:nodetypes="czzzzzzzz"
style="fill:url(#linearGradient1140);fill-opacity:1;fill-rule:evenodd;stroke-width:1.44734821pt" />
<rect
height="39.110481"
id="rect1137"
rx="3.6272225"
ry="3.536587"
style="fill:url(#linearGradient905);fill-opacity:1;fill-rule:evenodd;stroke-width:1.62826681"
width="48.220726"
x="7.4732022"
y="-0.010164791" />
<rect
height="24.74659"
id="rect1131"
style="fill:#ff9955;fill-opacity:1;fill-rule:evenodd;stroke:url(#linearGradient891);stroke-width:0.96503658pt"
width="38.813015"
x="12.390426"
y="6.027596" />
<path
d="M 8.5906358,19.782157 L 8.3772707,34.032521 C 8.3432557,36.304242 9.6712558,37.75887 12.004493,37.777143 L 38.568566,37.985175 L 41.128957,32.160207 L 11.471076,31.952177 L 11.257713,19.678141 L 8.5906358,19.782157 z "
id="path1145"
sodipodi:nodetypes="czzccccc"
style="fill:url(#linearGradient1146);fill-opacity:1;fill-rule:evenodd;stroke-width:1pt" />
<path
d="M 2.7205883,54.675124 C 2.1113822,55.866786 2.9089235,57.975349 4.9701318,57.975349 L 60.179981,57.975349 C 61.276346,57.975349 62.926231,56.48511 62.429524,55.460899 L 57.78047,45.874547 C 57.422369,45.136152 56.621274,44.774474 55.830865,44.774474 L 8.8693353,44.774468 C 8.2175462,44.774468 7.5274604,45.272486 7.2196723,45.874547 L 2.7205883,54.675124 z "
id="path1143"
sodipodi:nodetypes="czzzzzzzz"
style="fill:url(#linearGradient1144);fill-opacity:1;fill-rule:evenodd;stroke-width:1pt" />
<ellipse
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path4212"
cx="21.5625"
cy="11.253814"
rx="3.3125"
ry="3.375" />
<ellipse
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path4212-3"
cx="41.1875"
cy="11.128816"
rx="3.3125"
ry="3.375" />
<ellipse
style="opacity:1;fill:#ff9955;fill-opacity:1;stroke:#ffffff;stroke-width:1.85415959;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="path4212-3-6"
cx="30.46245"
cy="25.978863"
rx="2.3854203"
ry="2.4479203" />
<path
inkscape:connector-curvature="0"
style="fill:#ffffff;stroke:#ffffff;stroke-width:0.38147008;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 37.747841,25.720332 c 2.423268,-1.218576 3.927625,-3.912271 3.812948,-7.621135 l 1.642658,1.638437 1.08515,-1.049406 -3.462731,-3.556066 -3.963528,3.384577 1.033228,0.870639 1.703184,-1.46973 c 0.452288,3.542567 -0.666814,5.13406 -2.97277,6.29367 -1.596753,0.802958 -2.928888,1.433178 -4.2106,-0.23115 l -0.510936,0.914481 c 0.714057,0.927235 0.370391,1.816393 1.288764,2.104435 0.947222,0.297085 3.631209,-0.814386 4.554633,-1.278752 z"
id="path3"
sodipodi:nodetypes="scccccccsccss" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g5" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g7" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g9" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g11" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g13" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g15" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g17" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g19" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g21" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g23" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g25" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g27" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g29" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g31" />
<g
transform="matrix(1.3039536,0,0,1.3039536,-225.75033,-238.74618)"
id="g33" />
<path
inkscape:connector-curvature="0"
style="fill:#ffffff;stroke:#ffffff;stroke-width:0.38147008;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 27.747543,11.203969 c 2.374543,1.310993 3.774049,4.060623 3.516628,7.762319 l 1.704535,-1.573962 1.043932,1.090417 -3.597106,3.420077 -3.830247,-3.534702 1.06599,-0.830203 1.645321,1.534229 c 0.588378,-3.522521 -0.468606,-5.15593 -2.728194,-6.403483 -1.564647,-0.863854 -2.871524,-1.544907 -4.216378,0.06883 l -0.475341,-0.933479 c 0.749236,-0.899048 0.440066,-1.800781 1.368851,-2.053243 0.95796,-0.2603868 3.597153,0.953621 4.502009,1.453203 z"
id="path3-7"
sodipodi:nodetypes="scccccccsccss" />
</svg>

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,179 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import asyncio
import sys
from tests.utils import asyncio_patch, AsyncioMagicMock
from unittest.mock import patch, MagicMock, ANY, PropertyMock
from gns3server.compute.traceng.traceng_vm import TraceNGVM
from gns3server.compute.traceng.traceng_error import TraceNGError
from gns3server.compute.traceng import TraceNG
from gns3server.compute.notification_manager import NotificationManager
@pytest.fixture
def manager(port_manager):
m = TraceNG.instance()
m.port_manager = port_manager
return m
@pytest.fixture(scope="function")
def vm(project, manager, ubridge_path):
vm = TraceNGVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
vm._start_ubridge = AsyncioMagicMock()
vm._ubridge_hypervisor = MagicMock()
vm._ubridge_hypervisor.is_running.return_value = True
return vm
def test_vm(project, manager):
vm = TraceNGVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
assert vm.name == "test"
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
def test_vm_invalid_traceng_path(vm, manager, loop):
with patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._traceng_path", return_value="/tmp/fake/path/traceng"):
with pytest.raises(TraceNGError):
nio = manager.create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
loop.run_until_complete(asyncio.async(vm.start()))
assert vm.name == "test"
assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0e"
def test_start(loop, vm, async_run):
process = MagicMock()
process.returncode = None
with NotificationManager.instance().queue() as queue:
async_run(queue.get(0)) # Ping
vm.ip_address = "192.168.1.1"
with patch("sys.platform", return_value="win"):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process) as mock_exec:
loop.run_until_complete(asyncio.async(vm.start("192.168.1.2")))
assert mock_exec.call_args[0] == (vm._traceng_path(),
'-u',
'-c',
ANY,
'-v',
ANY,
'-b',
'127.0.0.1',
'-s',
'ICMP',
'-f',
'192.168.1.1',
'192.168.1.2')
assert vm.is_running()
assert vm.command_line == ' '.join(mock_exec.call_args[0])
(action, event, kwargs) = async_run(queue.get(0))
assert action == "node.updated"
assert event == vm
def test_stop(loop, vm, async_run):
process = MagicMock()
# Wait process kill success
future = asyncio.Future()
future.set_result(True)
process.wait.return_value = future
process.returncode = None
vm.ip_address = "192.168.1.1"
with NotificationManager.instance().queue() as queue:
with patch("sys.platform", return_value="win"):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
async_run(vm.port_add_nio_binding(0, nio))
vm._ubridge_send = AsyncioMagicMock()
async_run(vm.start("192.168.1.2"))
assert vm.is_running()
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
loop.run_until_complete(asyncio.async(vm.stop()))
assert vm.is_running() is False
process.terminate.assert_called_with()
async_run(queue.get(0)) #  Ping
async_run(queue.get(0)) #  Started
(action, event, kwargs) = async_run(queue.get(0))
assert action == "node.updated"
assert event == vm
def test_reload(loop, vm, async_run):
process = MagicMock()
# Wait process kill success
future = asyncio.Future()
future.set_result(True)
process.wait.return_value = future
process.returncode = None
vm.ip_address = "192.168.1.1"
with patch("sys.platform", return_value="win"):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
async_run(vm.port_add_nio_binding(0, nio))
vm._ubridge_send = AsyncioMagicMock()
async_run(vm.start("192.168.1.2"))
assert vm.is_running()
with asyncio_patch("gns3server.utils.asyncio.wait_for_process_termination"):
async_run(vm.reload())
assert vm.is_running() is True
#if sys.platform.startswith("win"):
# process.send_signal.assert_called_with(1)
#else:
process.terminate.assert_called_with()
def test_add_nio_binding_udp(vm, async_run):
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1", "filters": {}})
async_run(vm.port_add_nio_binding(0, nio))
assert nio.lport == 4242
def test_port_remove_nio_binding(vm):
nio = TraceNG.instance().create_nio({"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_add_nio_binding(0, nio)
vm.port_remove_nio_binding(0)
assert vm._ethernet_adapter.ports[0] is None
def test_close(vm, port_manager, loop):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._check_requirements", return_value=True):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm.start()
loop.run_until_complete(asyncio.async(vm.close()))
assert vm.is_running() is False

View File

@ -31,11 +31,11 @@ from gns3server.version import __version__
def test_get(http_compute, windows_platform): def test_get(http_compute, windows_platform):
response = http_compute.get('/capabilities', example=True) response = http_compute.get('/capabilities', example=True)
assert response.status == 200 assert response.status == 200
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform} assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'traceng', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform}
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_get_on_gns3vm(http_compute, on_gns3vm): def test_get_on_gns3vm(http_compute, on_gns3vm):
response = http_compute.get('/capabilities', example=True) response = http_compute.get('/capabilities', example=True)
assert response.status == 200 assert response.status == 200
assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform} assert response.json == {'node_types': ['cloud', 'ethernet_hub', 'ethernet_switch', 'nat', 'vpcs', 'virtualbox', 'dynamips', 'frame_relay_switch', 'atm_switch', 'qemu', 'vmware', 'traceng', 'docker', 'iou'], 'version': __version__, 'platform': sys.platform}

View File

@ -0,0 +1,147 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import uuid
import sys
import os
from tests.utils import asyncio_patch
from unittest.mock import patch
@pytest.fixture(scope="function")
def vm(http_compute, project):
response = http_compute.post("/projects/{project_id}/traceng/nodes".format(project_id=project.id), {"name": "TraceNG TEST 1"})
assert response.status == 201
return response.json
def test_traceng_create(http_compute, project):
response = http_compute.post("/projects/{project_id}/traceng/nodes".format(project_id=project.id), {"name": "TraceNG TEST 1"}, example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/traceng/nodes"
assert response.json["name"] == "TraceNG TEST 1"
assert response.json["project_id"] == project.id
def test_traceng_get(http_compute, project, vm):
response = http_compute.get("/projects/{project_id}/traceng/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert response.status == 200
assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}"
assert response.json["name"] == "TraceNG TEST 1"
assert response.json["project_id"] == project.id
assert response.json["status"] == "stopped"
def test_traceng_create_port(http_compute, project, free_console_port):
response = http_compute.post("/projects/{project_id}/traceng/nodes".format(project_id=project.id), {"name": "TraceNG TEST 1", "console": free_console_port})
assert response.status == 201
assert response.route == "/projects/{project_id}/traceng/nodes"
assert response.json["name"] == "TraceNG TEST 1"
assert response.json["project_id"] == project.id
assert response.json["console"] == free_console_port
def test_traceng_nio_create_udp(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.add_ubridge_udp_connection"):
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_traceng_nio_update_udp(http_compute, vm):
response = http_compute.put("/projects/{project_id}/traceng/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]),
{
"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1",
"filters": {}},
example=True)
assert response.status == 201, response.body.decode("utf-8")
assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_traceng_delete_nio(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM._ubridge_send"):
http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"})
response = http_compute.delete("/projects/{project_id}/traceng/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert response.status == 204, response.body.decode()
assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
def test_traceng_start(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.start", return_value=True) as mock:
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/start".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"destination": "192.168.1.2"}, example=True)
assert mock.called
assert response.status == 200
assert response.json["name"] == "TraceNG TEST 1"
def test_traceng_stop(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.stop", return_value=True) as mock:
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/stop".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert mock.called
assert response.status == 204
def test_traceng_reload(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.traceng_vm.TraceNGVM.reload", return_value=True) as mock:
response = http_compute.post("/projects/{project_id}/traceng/nodes/{node_id}/reload".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert mock.called
assert response.status == 204
def test_traceng_delete(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.TraceNG.delete_node", return_value=True) as mock:
response = http_compute.delete("/projects/{project_id}/traceng/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert mock.called
assert response.status == 204
def test_traceng_duplicate(http_compute, vm):
with asyncio_patch("gns3server.compute.traceng.TraceNG.duplicate_node", return_value=True) as mock:
response = http_compute.post(
"/projects/{project_id}/traceng/nodes/{node_id}/duplicate".format(
project_id=vm["project_id"],
node_id=vm["node_id"]),
body={
"destination_node_id": str(uuid.uuid4())
},
example=True)
assert mock.called
assert response.status == 201
def test_traceng_update(http_compute, vm, tmpdir, free_console_port):
response = http_compute.put("/projects/{project_id}/traceng/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"name": "test",
"ip_address": "192.168.1.1",
},
example=True)
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["ip_address"] == "192.168.1.1"