Example #1
0
    def setup(self, name=None, initial_ports=[], initial_mappings={}):
        """
        Setups this Frame Relay switch.

        :param name: name for this switch.
        :param initial_ports: ports to be automatically added when creating this Frame relay switch
        :param initial_mappings: mappings to be automatically added when creating this Frame relay switch
        """

        # let's create a unique name if none has been chosen
        if not name:
            name = self.allocateName("FR")

        if not name:
            self.error_signal.emit(self.id(), "could not allocate a name for this Frame Relay switch")
            return

        if initial_mappings:
            # add initial mappings
            self._settings["mappings"] = initial_mappings.copy()

        # add initial ports
        for initial_port in initial_ports:
            port = FrameRelayPort(initial_port["name"])
            port.setPortNumber(initial_port["port_number"])
            if "id" in initial_port:
                port.setId(initial_port["id"])
            port.setStatus(FrameRelayPort.started)
            port.setPacketCaptureSupported(True)
            self._ports.append(port)

        params = {"name": name}
        self._server.send_message("dynamips.frsw.create", params, self._setupCallback)
Example #2
0
    def update(self, new_settings):
        """
        Updates the settings for this Frame Relay switch.

        :param new_settings: settings dictionary
        """

        updated = False
        if "mappings" in new_settings:
            ports_to_create = []
            mapping = new_settings["mappings"]

            for source, destination in mapping.items():
                source_port = source.split(":")[0]
                destination_port = destination.split(":")[0]
                if source_port not in ports_to_create:
                    ports_to_create.append(source_port)
                if destination_port not in ports_to_create:
                    ports_to_create.append(destination_port)

            for port in self._ports.copy():
                if port.isFree():
                    self._ports.remove(port)
                    updated = True
                    log.debug("port {} has been removed".format(port.name()))
                else:
                    ports_to_create.remove(port.name())

            for port_name in ports_to_create:
                port = FrameRelayPort(port_name)
                port.setPortNumber(int(port_name))
                port.setStatus(FrameRelayPort.started)
                port.setPacketCaptureSupported(True)
                self._ports.append(port)
                updated = True
                log.debug("port {} has been added".format(port_name))

            self._settings["mappings"] = new_settings["mappings"].copy()

        params = {}
        if "name" in new_settings and new_settings["name"] != self.name():
            if self.hasAllocatedName(new_settings["name"]):
                self.error_signal.emit(self.id(), 'Name "{}" is already used by another node'.format(new_settings["name"]))
                return
            params = {"id": self._frsw_id,
                      "name": new_settings["name"]}
            updated = True

        if updated:
            if params:
                log.debug("{} is being updated: {}".format(self.name(), params))
                self.httpPut("/dynamips/devices/{device_id}".format(device_id=self._device_id), self._updateCallback, body=params)
            else:
                log.info("{} has been updated".format(self.name()))
                self.updated_signal.emit()
Example #3
0
    def setup(self,
              name=None,
              device_id=None,
              initial_ports=[],
              initial_mappings={}):
        """
        Setups this Frame Relay switch.

        :param name: name for this switch.
        :param device_id: device identifier on the server
        :param initial_ports: ports to be automatically added when creating this Frame relay switch
        :param initial_mappings: mappings to be automatically added when creating this Frame relay switch
        """

        # let's create a unique name if none has been chosen
        if not name:
            name = self.allocateName("FR")

        if not name:
            self.error_signal.emit(
                self.id(),
                "could not allocate a name for this Frame Relay switch")
            return

        self._settings["name"] = name
        if initial_mappings:
            # add initial mappings
            self._settings["mappings"] = initial_mappings.copy()

        # add initial ports
        for initial_port in initial_ports:
            port = FrameRelayPort(initial_port["name"])
            port.setPortNumber(initial_port["port_number"])
            if "id" in initial_port:
                port.setId(initial_port["id"])
            port.setStatus(FrameRelayPort.started)
            port.setPacketCaptureSupported(True)
            self._ports.append(port)

        params = {"name": name, "device_type": "frame_relay_switch"}
        if device_id:
            params["device_id"] = device_id
        self.httpPost("/dynamips/devices", self._setupCallback, body=params)
    def update(self, new_settings):
        """
        Updates the settings for this Frame Relay switch.

        :param new_settings: settings dictionary
        """

        updated = False
        if "mappings" in new_settings:
            ports_to_create = []
            mapping = new_settings["mappings"]

            for source, destination in mapping.items():
                source_port = source.split(":")[0]
                destination_port = destination.split(":")[0]
                if source_port not in ports_to_create:
                    ports_to_create.append(source_port)
                if destination_port not in ports_to_create:
                    ports_to_create.append(destination_port)

            for port in self._ports.copy():
                if port.isFree():
                    self._ports.remove(port)
                    updated = True
                    log.debug("port {} has been removed".format(port.name()))
                else:
                    ports_to_create.remove(port.name())

            for port_name in ports_to_create:
                port = FrameRelayPort(port_name)
                port.setPortNumber(int(port_name))
                port.setStatus(FrameRelayPort.started)
                port.setPacketCaptureSupported(True)
                self._ports.append(port)
                updated = True
                log.debug("port {} has been added".format(port_name))

            self._settings["mappings"] = new_settings["mappings"].copy()

        params = {}
        if "name" in new_settings and new_settings["name"] != self.name():
            if self.hasAllocatedName(new_settings["name"]):
                self.error_signal.emit(
                    self.id(), 'Name "{}" is already used by another node'.format(new_settings["name"])
                )
                return
            params["name"] = new_settings["name"]
            updated = True

        if updated:
            if params:
                log.debug("{} is being updated: {}".format(self.name(), params))
                self.httpPut(
                    "/dynamips/devices/{device_id}".format(device_id=self._device_id), self._updateCallback, body=params
                )
            else:
                log.info("{} has been updated".format(self.name()))
                self.updated_signal.emit()
    def setup(self, name=None, device_id=None, initial_ports=[], initial_mappings={}):
        """
        Setups this Frame Relay switch.

        :param name: name for this switch.
        :param device_id: device identifier on the server
        :param initial_ports: ports to be automatically added when creating this Frame relay switch
        :param initial_mappings: mappings to be automatically added when creating this Frame relay switch
        """

        # let's create a unique name if none has been chosen
        if not name:
            name = self.allocateName("FR")

        if not name:
            self.error_signal.emit(self.id(), "could not allocate a name for this Frame Relay switch")
            return

        self._settings["name"] = name
        if initial_mappings:
            # add initial mappings
            self._settings["mappings"] = initial_mappings.copy()

        # add initial ports
        for initial_port in initial_ports:
            port = FrameRelayPort(initial_port["name"])
            port.setPortNumber(initial_port["port_number"])
            if "id" in initial_port:
                port.setId(initial_port["id"])
            port.setStatus(FrameRelayPort.started)
            port.setPacketCaptureSupported(True)
            self._ports.append(port)

        params = {"name": name,
                  "device_type": "frame_relay_switch"}
        if device_id:
            params["device_id"] = device_id
        self.httpPost("/dynamips/devices", self._setupCallback, body=params)