diff --git a/gns3server/compute/dynamips/__init__.py b/gns3server/compute/dynamips/__init__.py index 4b05661d..4b6243ee 100644 --- a/gns3server/compute/dynamips/__init__.py +++ b/gns3server/compute/dynamips/__init__.py @@ -43,8 +43,7 @@ from ..port_manager import PortManager from .dynamips_error import DynamipsError from .hypervisor import Hypervisor from .nodes.router import Router -from .dynamips_vm_factory import DynamipsVMFactory -from .dynamips_device_factory import DynamipsDeviceFactory +from .dynamips_factory import DynamipsFactory # NIOs from .nios.nio_udp import NIOUDP @@ -112,9 +111,8 @@ PLATFORMS_DEFAULT_RAM = {"c1700": 160, class Dynamips(BaseManager): - _NODE_CLASS = DynamipsVMFactory + _NODE_CLASS = DynamipsFactory _NODE_TYPE = "dynamips" - _DEVICE_CLASS = DynamipsDeviceFactory _ghost_ios_lock = None def __init__(self): @@ -250,73 +248,6 @@ class Dynamips(BaseManager): return self._dynamips_path - @asyncio.coroutine - def create_device(self, name, project_id, node_id, device_type, *args, **kwargs): - """ - Create a new Dynamips device. - - :param name: Device name - :param project_id: Project identifier - :param node_id: Node identifier - """ - - project = ProjectManager.instance().get_project(project_id) - if node_id and isinstance(node_id, int): - with (yield from BaseManager._convert_lock): - node_id = yield from self.convert_old_project(project, node_id, name) - - if not node_id: - node_id = str(uuid4()) - - device = self._DEVICE_CLASS(name, node_id, project, self, device_type, *args, **kwargs) - yield from device.create() - self._devices[device.id] = device - return device - - def get_device(self, node_id, project_id=None): - """ - Returns a device instance. - - :param node_id: Node identifier - :param project_id: Project identifier - - :returns: Device instance - """ - - if project_id: - # check the project_id exists - project = ProjectManager.instance().get_project(project_id) - - try: - UUID(node_id, version=4) - except ValueError: - raise aiohttp.web.HTTPBadRequest(text="Node ID {} is not a valid UUID".format(node_id)) - - if node_id not in self._devices: - raise aiohttp.web.HTTPNotFound(text="Node ID {} doesn't exist".format(node_id)) - - device = self._devices[node_id] - if project_id: - if device.project.id != project.id: - raise aiohttp.web.HTTPNotFound(text="Project ID {} doesn't belong to device {}".format(project_id, device.name)) - - return device - - @asyncio.coroutine - def delete_device(self, node_id): - """ - Delete a device - - :param node_id: Node identifier - - :returns: Device instance - """ - - device = self.get_device(node_id) - yield from device.delete() - del self._devices[device.id] - return device - def find_dynamips(self): # look for Dynamips diff --git a/gns3server/compute/dynamips/dynamips_device_factory.py b/gns3server/compute/dynamips/dynamips_device_factory.py deleted file mode 100644 index bae2db84..00000000 --- a/gns3server/compute/dynamips/dynamips_device_factory.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015 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 . - - -from .dynamips_error import DynamipsError -from .nodes.atm_switch import ATMSwitch -from .nodes.ethernet_switch import EthernetSwitch -from .nodes.ethernet_hub import EthernetHub -from .nodes.frame_relay_switch import FrameRelaySwitch - -import logging -log = logging.getLogger(__name__) - -DEVICES = {'atm_switch': ATMSwitch, - 'frame_relay_switch': FrameRelaySwitch, - 'ethernet_switch': EthernetSwitch, - 'ethernet_hub': EthernetHub} - - -class DynamipsDeviceFactory: - - """ - Factory to create an Device object based on the type - """ - - def __new__(cls, name, node_id, project, manager, device_type, **kwargs): - - if device_type not in DEVICES: - raise DynamipsError("Unknown device type: {}".format(device_type)) - - return DEVICES[device_type](name, node_id, project, manager, **kwargs) diff --git a/gns3server/compute/dynamips/dynamips_vm_factory.py b/gns3server/compute/dynamips/dynamips_factory.py similarity index 57% rename from gns3server/compute/dynamips/dynamips_vm_factory.py rename to gns3server/compute/dynamips/dynamips_factory.py index f0c7cf1b..220e0d23 100644 --- a/gns3server/compute/dynamips/dynamips_vm_factory.py +++ b/gns3server/compute/dynamips/dynamips_factory.py @@ -24,6 +24,10 @@ from .nodes.c3600 import C3600 from .nodes.c3725 import C3725 from .nodes.c3745 import C3745 from .nodes.c7200 import C7200 +from .nodes.atm_switch import ATMSwitch +from .nodes.ethernet_switch import EthernetSwitch +from .nodes.ethernet_hub import EthernetHub +from .nodes.frame_relay_switch import FrameRelaySwitch import logging log = logging.getLogger(__name__) @@ -37,15 +41,27 @@ PLATFORMS = {'c1700': C1700, 'c7200': C7200} -class DynamipsVMFactory: +DEVICES = {'atm_switch': ATMSwitch, + 'frame_relay_switch': FrameRelaySwitch, + 'ethernet_switch': EthernetSwitch, + 'ethernet_hub': EthernetHub} + + +class DynamipsFactory: """ Factory to create an Router object based on the correct platform. """ - def __new__(cls, name, node_id, project, manager, dynamips_id, platform, **kwargs): + def __new__(cls, name, node_id, project, manager, node_type="dynamips", dynamips_id=None, platform=None, **kwargs): - if platform not in PLATFORMS: - raise DynamipsError("Unknown router platform: {}".format(platform)) + if node_type == "dynamips": + if platform not in PLATFORMS: + raise DynamipsError("Unknown router platform: {}".format(platform)) - return PLATFORMS[platform](name, node_id, project, manager, dynamips_id, **kwargs) + return PLATFORMS[platform](name, node_id, project, manager, dynamips_id, **kwargs) + else: + if node_type not in DEVICES: + raise DynamipsError("Unknown device type: {}".format(node_type)) + + return DEVICES[node_type](name, node_id, project, manager, **kwargs) diff --git a/gns3server/compute/dynamips/nodes/atm_switch.py b/gns3server/compute/dynamips/nodes/atm_switch.py index fc0e3330..07fe063b 100644 --- a/gns3server/compute/dynamips/nodes/atm_switch.py +++ b/gns3server/compute/dynamips/nodes/atm_switch.py @@ -120,24 +120,30 @@ class ATMSwitch(Device): self._mappings = mappings @asyncio.coroutine - def delete(self): - """ - Deletes this ATM switch. - """ - + def close(self): for nio in self._nios.values(): if nio and isinstance(nio, NIOUDP): self.manager.port_manager.release_udp_port(nio.lport, self._project) - try: - yield from self._hypervisor.send('atmsw delete "{}"'.format(self._name)) - log.info('ATM switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) - except DynamipsError: - log.debug("Could not properly delete ATM switch {}".format(self._name)) + if self._hypervisor: + try: + yield from self._hypervisor.send('atmsw delete "{}"'.format(self._name)) + log.info('ATM switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) + except DynamipsError: + log.debug("Could not properly delete ATM switch {}".format(self._name)) if self._hypervisor and self in self._hypervisor.devices: self._hypervisor.devices.remove(self) if self._hypervisor and not self._hypervisor.devices: yield from self.hypervisor.stop() + self._hypervisor = None + return True + + @asyncio.coroutine + def delete(self): + """ + Deletes this ATM switch. + """ + yield from self.close() def has_port(self, port): """ diff --git a/gns3server/compute/dynamips/nodes/ethernet_hub.py b/gns3server/compute/dynamips/nodes/ethernet_hub.py index 365d832e..969ce307 100644 --- a/gns3server/compute/dynamips/nodes/ethernet_hub.py +++ b/gns3server/compute/dynamips/nodes/ethernet_hub.py @@ -111,6 +111,10 @@ class EthernetHub(Bridge): @asyncio.coroutine def delete(self): + return (yield from self.close()) + + @asyncio.coroutine + def close(self): """ Deletes this hub. """ @@ -126,6 +130,8 @@ class EthernetHub(Bridge): log.debug("Could not properly delete Ethernet hub {}".format(self._name)) if self._hypervisor and not self._hypervisor.devices: yield from self.hypervisor.stop() + self._hypervisor = None + return True @asyncio.coroutine def add_nio(self, nio, port_number): diff --git a/gns3server/compute/dynamips/nodes/ethernet_switch.py b/gns3server/compute/dynamips/nodes/ethernet_switch.py index 4fd75011..037a837e 100644 --- a/gns3server/compute/dynamips/nodes/ethernet_switch.py +++ b/gns3server/compute/dynamips/nodes/ethernet_switch.py @@ -146,6 +146,10 @@ class EthernetSwitch(Device): @asyncio.coroutine def delete(self): + return (yield from self.close()) + + @asyncio.coroutine + def close(self): """ Deletes this Ethernet switch. """ @@ -154,15 +158,18 @@ class EthernetSwitch(Device): if nio and isinstance(nio, NIOUDP): self.manager.port_manager.release_udp_port(nio.lport, self._project) - try: - yield from self._hypervisor.send('ethsw delete "{}"'.format(self._name)) - log.info('Ethernet switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) - except DynamipsError: - log.debug("Could not properly delete Ethernet switch {}".format(self._name)) + if self._hypervisor: + try: + yield from self._hypervisor.send('ethsw delete "{}"'.format(self._name)) + log.info('Ethernet switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) + except DynamipsError: + log.debug("Could not properly delete Ethernet switch {}".format(self._name)) if self._hypervisor and self in self._hypervisor.devices: self._hypervisor.devices.remove(self) if self._hypervisor and not self._hypervisor.devices: yield from self.hypervisor.stop() + self._hypervisor = None + return True @asyncio.coroutine def add_nio(self, nio, port_number): diff --git a/gns3server/compute/dynamips/nodes/frame_relay_switch.py b/gns3server/compute/dynamips/nodes/frame_relay_switch.py index 3ec39001..943e3d02 100644 --- a/gns3server/compute/dynamips/nodes/frame_relay_switch.py +++ b/gns3server/compute/dynamips/nodes/frame_relay_switch.py @@ -119,24 +119,31 @@ class FrameRelaySwitch(Device): self._mappings = mappings @asyncio.coroutine - def delete(self): - """ - Deletes this Frame Relay switch. - """ - + def close(self): for nio in self._nios.values(): if nio and isinstance(nio, NIOUDP): self.manager.port_manager.release_udp_port(nio.lport, self._project) - try: - yield from self._hypervisor.send('frsw delete "{}"'.format(self._name)) - log.info('Frame Relay switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) - except DynamipsError: - log.debug("Could not properly delete Frame relay switch {}".format(self._name)) + if self._hypervisor: + try: + yield from self._hypervisor.send('frsw delete "{}"'.format(self._name)) + log.info('Frame Relay switch "{name}" [{id}] has been deleted'.format(name=self._name, id=self._id)) + except DynamipsError: + log.debug("Could not properly delete Frame relay switch {}".format(self._name)) + if self._hypervisor and self in self._hypervisor.devices: self._hypervisor.devices.remove(self) if self._hypervisor and not self._hypervisor.devices: yield from self.hypervisor.stop() + self._hypervisor = None + + @asyncio.coroutine + def delete(self): + """ + Deletes this Frame Relay switch. + """ + yield from self.close() + return True def has_port(self, port): """ diff --git a/gns3server/handlers/api/compute/atm_switch_handler.py b/gns3server/handlers/api/compute/atm_switch_handler.py index 5a77628b..f54d6bed 100644 --- a/gns3server/handlers/api/compute/atm_switch_handler.py +++ b/gns3server/handlers/api/compute/atm_switch_handler.py @@ -52,10 +52,10 @@ class ATMSwitchHandler: # Use the Dynamips ATM switch to simulate this node dynamips_manager = Dynamips.instance() - node = yield from dynamips_manager.create_device(request.json.pop("name"), + node = yield from dynamips_manager.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), - device_type="atm_switch", + node_type="atm_switch", mappings=request.json.get("mappings")) response.set_status(201) response.json(node) @@ -76,7 +76,7 @@ class ATMSwitchHandler: def show(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(node) @Route.put( @@ -97,7 +97,7 @@ class ATMSwitchHandler: def update(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if "name" in request.json and node.name != request.json["name"]: yield from node.set_name(request.json["name"]) if "mappings" in request.json: @@ -120,7 +120,7 @@ class ATMSwitchHandler: def delete(request, response): dynamips_manager = Dynamips.instance() - yield from dynamips_manager.delete_device(request.match_info["node_id"]) + yield from dynamips_manager.delete_node(request.match_info["node_id"]) response.set_status(204) @Route.post( @@ -137,7 +137,7 @@ class ATMSwitchHandler: description="Start an ATM switch") def start(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -154,7 +154,7 @@ class ATMSwitchHandler: description="Stop an ATM switch") def stop(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -171,7 +171,7 @@ class ATMSwitchHandler: description="Suspend an ATM Relay switch") def suspend(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -193,7 +193,7 @@ class ATMSwitchHandler: def create_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = yield from dynamips_manager.create_nio(node, request.json) port_number = int(request.match_info["port_number"]) yield from node.add_nio(nio, port_number) @@ -217,7 +217,7 @@ class ATMSwitchHandler: def delete_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) nio = yield from node.remove_nio(port_number) yield from nio.delete() @@ -241,7 +241,7 @@ class ATMSwitchHandler: def start_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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(node.project.capture_working_directory(), request.json["capture_file_name"]) yield from node.start_capture(port_number, pcap_file_path, request.json["data_link_type"]) @@ -264,7 +264,7 @@ class ATMSwitchHandler: def stop_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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 node.stop_capture(port_number) response.set_status(204) diff --git a/gns3server/handlers/api/compute/dynamips_vm_handler.py b/gns3server/handlers/api/compute/dynamips_vm_handler.py index a4bb31f3..78a7f6cb 100644 --- a/gns3server/handlers/api/compute/dynamips_vm_handler.py +++ b/gns3server/handlers/api/compute/dynamips_vm_handler.py @@ -73,10 +73,11 @@ class DynamipsVMHandler: request.match_info["project_id"], request.json.get("node_id"), request.json.get("dynamips_id"), - platform, + platform=platform, console=request.json.get("console"), aux=request.json.get("aux"), - chassis=request.json.pop("chassis", default_chassis)) + chassis=request.json.pop("chassis", default_chassis), + node_type="dynamips") yield from dynamips_manager.update_vm_settings(vm, request.json) response.set_status(201) diff --git a/gns3server/handlers/api/compute/ethernet_hub_handler.py b/gns3server/handlers/api/compute/ethernet_hub_handler.py index 1123a50d..492f5041 100644 --- a/gns3server/handlers/api/compute/ethernet_hub_handler.py +++ b/gns3server/handlers/api/compute/ethernet_hub_handler.py @@ -53,19 +53,12 @@ class EthernetHubHandler: # Use the Dynamips Ethernet hub to simulate this node dynamips_manager = Dynamips.instance() - node = yield from dynamips_manager.create_device(request.json.pop("name"), + node = yield from dynamips_manager.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), - device_type="ethernet_hub", + node_type="ethernet_hub", ports=request.json.get("ports_mapping")) - # On Linux, use the generic hub - # builtin_manager = Builtin.instance() - # node = yield from builtin_manager.create_node(request.json.pop("name"), - # request.match_info["project_id"], - # request.json.get("node_id"), - # node_type="ethernet_hub") - response.set_status(201) response.json(node) @@ -85,10 +78,8 @@ class EthernetHubHandler: def show(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) - # builtin_manager = Builtin.instance() - # node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(node) @Route.put( @@ -109,14 +100,12 @@ class EthernetHubHandler: def update(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if "name" in request.json and node.name != request.json["name"]: yield from node.set_name(request.json["name"]) if "ports_mapping" in request.json: node.ports_mapping = request.json["ports_mapping"] - # builtin_manager = Builtin.instance() - # node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) node.updated() response.json(node) @@ -135,9 +124,7 @@ class EthernetHubHandler: def delete(request, response): dynamips_manager = Dynamips.instance() - yield from dynamips_manager.delete_device(request.match_info["node_id"]) - # builtin_manager = Builtin.instance() - # yield from builtin_manager.delete_node(request.match_info["node_id"]) + yield from dynamips_manager.delete_node(request.match_info["node_id"]) response.set_status(204) @Route.post( @@ -154,7 +141,7 @@ class EthernetHubHandler: description="Start an Ethernet hub") def start(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -171,7 +158,7 @@ class EthernetHubHandler: description="Stop an Ethernet hub") def stop(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -188,7 +175,7 @@ class EthernetHubHandler: description="Suspend an Ethernet hub") def suspend(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -210,15 +197,11 @@ class EthernetHubHandler: def create_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = yield from dynamips_manager.create_nio(node, request.json) port_number = int(request.match_info["port_number"]) yield from node.add_nio(nio, port_number) - #builtin_manager = Builtin.instance() - #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) - #nio = yield from builtin_manager.create_nio(request.json["nio"]) - response.set_status(201) response.json(nio) @@ -239,9 +222,7 @@ class EthernetHubHandler: def delete_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) - #builtin_manager = Builtin.instance() - #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) nio = yield from node.remove_nio(port_number) yield from nio.delete() @@ -265,9 +246,7 @@ class EthernetHubHandler: def start_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) - #builtin_manager = Builtin.instance() - #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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(node.project.capture_working_directory(), request.json["capture_file_name"]) yield from node.start_capture(port_number, pcap_file_path, request.json["data_link_type"]) @@ -290,9 +269,7 @@ class EthernetHubHandler: def stop_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) - #builtin_manager = Builtin.instance() - #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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 node.stop_capture(port_number) response.set_status(204) diff --git a/gns3server/handlers/api/compute/ethernet_switch_handler.py b/gns3server/handlers/api/compute/ethernet_switch_handler.py index f8396a1d..72a05107 100644 --- a/gns3server/handlers/api/compute/ethernet_switch_handler.py +++ b/gns3server/handlers/api/compute/ethernet_switch_handler.py @@ -53,10 +53,10 @@ class EthernetSwitchHandler: # Use the Dynamips Ethernet switch to simulate this node dynamips_manager = Dynamips.instance() - node = yield from dynamips_manager.create_device(request.json.pop("name"), + node = yield from dynamips_manager.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), - device_type="ethernet_switch", + node_type="ethernet_switch", ports=request.json.get("ports_mapping")) # On Linux, use the generic switch @@ -85,7 +85,7 @@ class EthernetSwitchHandler: def show(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) # builtin_manager = Builtin.instance() # node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) @@ -109,7 +109,7 @@ class EthernetSwitchHandler: def update(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if "name" in request.json and node.name != request.json["name"]: yield from node.set_name(request.json["name"]) if "ports_mapping" in request.json: @@ -136,9 +136,7 @@ class EthernetSwitchHandler: def delete(request, response): dynamips_manager = Dynamips.instance() - yield from dynamips_manager.delete_device(request.match_info["node_id"]) - # builtin_manager = Builtin.instance() - # yield from builtin_manager.delete_node(request.match_info["node_id"]) + yield from dynamips_manager.delete_node(request.match_info["node_id"]) response.set_status(204) @Route.post( @@ -155,7 +153,7 @@ class EthernetSwitchHandler: description="Start an Ethernet switch") def start(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -172,7 +170,7 @@ class EthernetSwitchHandler: description="Stop an Ethernet switch") def stop(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -189,7 +187,7 @@ class EthernetSwitchHandler: description="Suspend an Ethernet switch") def suspend(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -211,7 +209,7 @@ class EthernetSwitchHandler: def create_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = yield from dynamips_manager.create_nio(node, request.json) port_number = int(request.match_info["port_number"]) yield from node.add_nio(nio, port_number) @@ -240,7 +238,7 @@ class EthernetSwitchHandler: def delete_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) #builtin_manager = Builtin.instance() #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) @@ -266,7 +264,7 @@ class EthernetSwitchHandler: def start_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) #builtin_manager = Builtin.instance() #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) @@ -291,7 +289,7 @@ class EthernetSwitchHandler: def stop_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) #builtin_manager = Builtin.instance() #node = builtin_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) diff --git a/gns3server/handlers/api/compute/frame_relay_switch_handler.py b/gns3server/handlers/api/compute/frame_relay_switch_handler.py index 980c4ef6..e0aa9891 100644 --- a/gns3server/handlers/api/compute/frame_relay_switch_handler.py +++ b/gns3server/handlers/api/compute/frame_relay_switch_handler.py @@ -52,10 +52,10 @@ class FrameRelaySwitchHandler: # Use the Dynamips Frame Relay switch to simulate this node dynamips_manager = Dynamips.instance() - node = yield from dynamips_manager.create_device(request.json.pop("name"), + node = yield from dynamips_manager.create_node(request.json.pop("name"), request.match_info["project_id"], request.json.get("node_id"), - device_type="frame_relay_switch", + node_type="frame_relay_switch", mappings=request.json.get("mappings")) response.set_status(201) response.json(node) @@ -76,7 +76,7 @@ class FrameRelaySwitchHandler: def show(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.json(node) @Route.put( @@ -97,7 +97,7 @@ class FrameRelaySwitchHandler: def update(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) if "name" in request.json and node.name != request.json["name"]: yield from node.set_name(request.json["name"]) if "mappings" in request.json: @@ -120,7 +120,7 @@ class FrameRelaySwitchHandler: def delete(request, response): dynamips_manager = Dynamips.instance() - yield from dynamips_manager.delete_device(request.match_info["node_id"]) + yield from dynamips_manager.delete_node(request.match_info["node_id"]) response.set_status(204) @Route.post( @@ -137,7 +137,7 @@ class FrameRelaySwitchHandler: description="Start a Frame Relay switch") def start(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -154,7 +154,7 @@ class FrameRelaySwitchHandler: description="Stop a Frame Relay switch") def stop(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -171,7 +171,7 @@ class FrameRelaySwitchHandler: description="Suspend a Frame Relay switch") def suspend(request, response): - Dynamips.instance().get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + Dynamips.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) response.set_status(204) @Route.post( @@ -193,7 +193,7 @@ class FrameRelaySwitchHandler: def create_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) nio = yield from dynamips_manager.create_nio(node, request.json) port_number = int(request.match_info["port_number"]) yield from node.add_nio(nio, port_number) @@ -217,7 +217,7 @@ class FrameRelaySwitchHandler: def delete_nio(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) port_number = int(request.match_info["port_number"]) nio = yield from node.remove_nio(port_number) yield from nio.delete() @@ -241,7 +241,7 @@ class FrameRelaySwitchHandler: def start_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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(node.project.capture_working_directory(), request.json["capture_file_name"]) yield from node.start_capture(port_number, pcap_file_path, request.json["data_link_type"]) @@ -264,7 +264,7 @@ class FrameRelaySwitchHandler: def stop_capture(request, response): dynamips_manager = Dynamips.instance() - node = dynamips_manager.get_device(request.match_info["node_id"], project_id=request.match_info["project_id"]) + node = dynamips_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 node.stop_capture(port_number) response.set_status(204)