def update(self, new_settings): """ Updates the settings for this ATM 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(): updated = True self._ports.remove(port) else: ports_to_create.remove(port.name()) for port_name in ports_to_create: port = ATMPort(port_name) port.setPortNumber(int(port_name)) port.setStatus(ATMPort.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("ATM switch {} has been updated".format(self.name())) self.updated_signal.emit()
def setup(self, name=None, initial_ports=[], initial_mappings={}): """ Setups this ATM switch. :param name: optional name for this switch. :param initial_ports: ports to be automatically added when creating this ATM switch :param initial_mappings: mappings to be automatically added when creating this ATM switch """ # let's create a unique name if none has been chosen if not name: name = self.allocateName("ATM") if not name: self.error_signal.emit(self.id(), "could not allocate a name for this ATM switch") return if initial_mappings: # add initial mappings self._settings["mappings"] = initial_mappings.copy() # add initial ports for initial_port in initial_ports: port = ATMPort(initial_port["name"]) port.setPortNumber(initial_port["port_number"]) if "id" in initial_port: port.setId(initial_port["id"]) port.setStatus(ATMPort.started) port.setPacketCaptureSupported(True) self._ports.append(port) params = {"name": name} self._server.send_message("dynamips.atmsw.create", params, self._setupCallback)
def update(self, new_settings): """ Updates the settings for this ATM 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(): updated = True self._ports.remove(port) else: ports_to_create.remove(port.name()) for port_name in ports_to_create: port = ATMPort(port_name) port.setPortNumber(int(port_name)) port.setStatus(ATMPort.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("ATM switch {} has been updated".format(self.name())) self.updated_signal.emit()
def setup(self, name=None, device_id=None, initial_ports=[], initial_mappings={}): """ Setups this ATM switch. :param name: optional name for this switch. :param device_id: device identifier on the server :param initial_ports: ports to be automatically added when creating this ATM switch :param initial_mappings: mappings to be automatically added when creating this ATM switch """ # let's create a unique name if none has been chosen if not name: name = self.allocateName("ATM") if not name: self.error_signal.emit( self.id(), "could not allocate a name for this ATM switch") return if initial_mappings: # add initial mappings self._settings["mappings"] = initial_mappings.copy() # add initial ports for initial_port in initial_ports: port = ATMPort(initial_port["name"]) port.setPortNumber(initial_port["port_number"]) if "id" in initial_port: port.setId(initial_port["id"]) port.setStatus(ATMPort.started) port.setPacketCaptureSupported(True) self._ports.append(port) params = {"name": name, "device_type": "atm_switch"} if device_id: params["device_id"] = device_id self.httpPost("/dynamips/devices", self._setupCallback, body=params)
def setup(self, name=None, device_id=None, initial_ports=[], initial_mappings={}): """ Setups this ATM switch. :param name: optional name for this switch. :param device_id: device identifier on the server :param initial_ports: ports to be automatically added when creating this ATM switch :param initial_mappings: mappings to be automatically added when creating this ATM switch """ # let's create a unique name if none has been chosen if not name: name = self.allocateName("ATM") if not name: self.error_signal.emit(self.id(), "could not allocate a name for this ATM switch") return if initial_mappings: # add initial mappings self._settings["mappings"] = initial_mappings.copy() # add initial ports for initial_port in initial_ports: port = ATMPort(initial_port["name"]) port.setPortNumber(initial_port["port_number"]) if "id" in initial_port: port.setId(initial_port["id"]) port.setStatus(ATMPort.started) port.setPacketCaptureSupported(True) self._ports.append(port) params = {"name": name, "device_type": "atm_switch"} if device_id: params["device_id"] = device_id self.httpPost("/dynamips/devices", self._setupCallback, body=params)