def _event_received(self, result, *args, **kwargs): # Log only relevant events if result["action"] not in ("ping", "compute.updated"): log.debug( "Event received from controller stream: {}".format(result)) if result["action"] == "template.created" or result[ "action"] == "template.updated": from gns3.template_manager import TemplateManager TemplateManager.instance().templateDataReceivedCallback( result["event"]) elif result["action"] == "template.deleted": from gns3.template_manager import TemplateManager TemplateManager.instance().deleteTemplateCallback(result["event"]) elif result["action"] == "compute.created" or result[ "action"] == "compute.updated": from .compute_manager import ComputeManager ComputeManager.instance().computeDataReceivedCallback( result["event"]) elif result["action"] == "log.error": log.error(result["event"]["message"]) elif result["action"] == "log.warning": log.warning(result["event"]["message"]) elif result["action"] == "log.info": log.info(result["event"]["message"], extra={"show": True}) elif result["action"] == "ping": pass
def savePreferences(self): """ Saves the VPCS node preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "vpcs": templates.append(template) for template_settings in self._vpcs_nodes.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the Ethernet hub preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "ethernet_hub": templates.append(template) for template_settings in self._ethernet_hubs.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the Docker image preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "docker": templates.append(template) for template_settings in self._docker_containers.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the QEMU VM preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "qemu": templates.append(template) for template_settings in self._qemu_vms.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the IOS router preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "dynamips": templates.append(template) for template_settings in self._ios_routers.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the VMware VM preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "vmware": templates.append(template) for template_settings in self._vmware_vms.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the cloud node preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "cloud": templates.append(template) for template_settings in self._cloud_nodes.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the VirtualBox VM preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "virtualbox": templates.append(template) for template_settings in self._virtualbox_vms.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def savePreferences(self): """ Saves the IOU devices preferences. """ templates = [] for template in TemplateManager.instance().templates().values(): if template.template_type() != "iou": templates.append(template) for template_settings in self._iou_devices.values(): templates.append(Template(template_settings)) TemplateManager.instance().updateList(templates)
def _migrateOldNodes(self): """ Migrate local node settings to the controller. """ if self._settings.get("nodes"): templates = [] for node in self._settings.get("nodes"): node_settings = VPCS_NODES_SETTINGS.copy() node_settings.update(node) templates.append(Template(node_settings)) TemplateManager.instance().updateList(templates) self._settings["nodes"] = [] self._saveSettings()
def _migrateOldVMs(self): """ Migrate local VM settings to the controller. """ if self._settings.get("vms"): templates = [] for vm in self._settings.get("vms"): vm_settings = VMWARE_VM_SETTINGS.copy() vm_settings.update(vm) templates.append(Template(vm_settings)) TemplateManager.instance().updateList(templates) self._settings["vms"] = [] self._saveSettings()
def _migrateOldVMs(self): """ Migrate local VM settings to the controller. """ if self._settings.get("vms"): templates = [] for vm in self._settings.get("vms"): vm_settings = VBOX_VM_SETTINGS.copy() vm_settings.update(vm) templates.append(Template(vm_settings)) TemplateManager.instance().updateList(templates) self._settings["vms"] = [] self._saveSettings()
def _migrateOldDevices(self): """ Migrate local device settings to the controller. """ if self._settings.get("devices"): templates = [] for device in self._settings.get("devices"): device_settings = IOU_DEVICE_SETTINGS.copy() device_settings.update(device) templates.append(Template(device_settings)) TemplateManager.instance().updateList(templates) self._settings["devices"] = [] self._saveSettings()
def _migrateOldContainers(self): """ Migrate local container settings to the controller. """ if self._settings.get("containers"): templates = [] for container in self._settings.get("containers"): container_settings = DOCKER_CONTAINER_SETTINGS.copy() container_settings.update(container) templates.append(Template(container_settings)) TemplateManager.instance().updateList(templates) self._settings["containers"] = [] self._saveSettings()
def loadPreferences(self): """ Loads the VirtualBox VM preferences. """ self._virtualbox_vms = {} templates = TemplateManager.instance().templates() for template_id, template in templates.items(): if template.template_type( ) == "virtualbox" and not template.builtin(): vmname = template.settings()["vmname"] server = template.compute_id() #TODO: use template id for the key key = "{server}:{vmname}".format(server=server, vmname=vmname) self._virtualbox_vms[key] = copy.deepcopy(template.settings()) self._items.clear() for key, vbox_vm in self._virtualbox_vms.items(): item = QtWidgets.QTreeWidgetItem(self.uiVirtualBoxVMsTreeWidget) item.setText(0, vbox_vm["name"]) Controller.instance().getSymbolIcon( vbox_vm["symbol"], qpartial(self._setItemIcon, item)) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiVirtualBoxVMsTreeWidget.setCurrentItem(self._items[0]) self.uiVirtualBoxVMsTreeWidget.sortByColumn( 0, QtCore.Qt.AscendingOrder) self.uiVirtualBoxVMsTreeWidget.setMaximumWidth( self.uiVirtualBoxVMsTreeWidget.sizeHintForColumn(0) + 10)
def loadPreferences(self): """ Loads the IOU devices preferences. """ self._iou_devices = {} templates = TemplateManager.instance().templates() for template_id, template in templates.items(): if template.template_type() == "iou" and not template.builtin(): name = template.name() server = template.compute_id() #TODO: use template id for the key key = "{server}:{name}".format(server=server, name=name) self._iou_devices[key] = copy.deepcopy(template.settings()) self._items.clear() for key, iou_device in self._iou_devices.items(): item = QtWidgets.QTreeWidgetItem(self.uiIOUDevicesTreeWidget) item.setText(0, iou_device["name"]) Controller.instance().getSymbolIcon(iou_device["symbol"], qpartial(self._setItemIcon, item)) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiIOUDevicesTreeWidget.setCurrentItem(self._items[0]) self.uiIOUDevicesTreeWidget.sortByColumn(0, QtCore.Qt.AscendingOrder) self.uiIOUDevicesTreeWidget.setMaximumWidth(self.uiIOUDevicesTreeWidget.sizeHintForColumn(0) + 10)
def _migrateOldRouters(self): """ Migrate local router settings to the controller. """ if self._settings.get("routers"): templates = [] for router in self._settings.get("routers"): router_settings = IOS_ROUTER_SETTINGS.copy() router_settings.update(router) if not router_settings.get("chassis"): del router_settings["chassis"] templates.append(Template(router_settings)) TemplateManager.instance().updateList(templates) self._settings["routers"] = [] self._saveSettings()
def loadPreferences(self): """ Loads the ethernet hub preferences. """ self._ethernet_hubs = {} templates = TemplateManager.instance().templates() for template_id, template in templates.items(): if template.template_type( ) == "ethernet_hub" and not template.builtin(): name = template.name() server = template.compute_id() #TODO: use template id for the key key = "{server}:{name}".format(server=server, name=name) self._ethernet_hubs[key] = copy.deepcopy(template.settings()) self._items.clear() for key, ethernet_hub in self._ethernet_hubs.items(): item = QtWidgets.QTreeWidgetItem(self.uiEthernetHubsTreeWidget) item.setText(0, ethernet_hub["name"]) Controller.instance().getSymbolIcon( ethernet_hub["symbol"], qpartial(self._setItemIcon, item)) item.setData(0, QtCore.Qt.UserRole, key) self._items.append(item) if self._items: self.uiEthernetHubsTreeWidget.setCurrentItem(self._items[0]) self.uiEthernetHubsTreeWidget.sortByColumn( 0, QtCore.Qt.AscendingOrder) self.uiEthernetHubsTreeWidget.setMaximumWidth( self.uiEthernetHubsTreeWidget.sizeHintForColumn(0) + 20)
def updateImageIdlepc(self, image_path, idlepc): """ Updates the Idle-PC for an IOS image. :param image_path: path to the IOS image :param idlepc: Idle-PC value """ for template in TemplateManager.instance().templates().values(): if template.template_type() == "dynamips": template_settings = template.settings() router_image = template_settings.get("image") old_idlepc = template_settings.get("idlepc") if os.path.basename( router_image) == image_path and old_idlepc != idlepc: template_settings["idlepc"] = idlepc template.setSettings(template_settings) log.debug( "Idle-PC value {} saved into '{}' template".format( idlepc, template.name())) TemplateManager.instance().updateTemplate(template)
def _event_received(self, result, *args, **kwargs): # Log only relevant events if result["action"] not in ("ping", "compute.updated"): log.debug("Event received from controller stream: {}".format(result)) if result["action"] == "template.created" or result["action"] == "template.updated": from gns3.template_manager import TemplateManager TemplateManager.instance().templateDataReceivedCallback(result["event"]) elif result["action"] == "template.deleted": from gns3.template_manager import TemplateManager TemplateManager.instance().deleteTemplateCallback(result["event"]) elif result["action"] == "compute.created" or result["action"] == "compute.updated": from .compute_manager import ComputeManager ComputeManager.instance().computeDataReceivedCallback(result["event"]) elif result["action"] == "log.error": log.error(result["event"]["message"]) elif result["action"] == "log.warning": log.warning(result["event"]["message"]) elif result["action"] == "log.info": log.info(result["event"]["message"], extra={"show": True}) elif result["action"] == "ping": pass