Example #1
0
    def __init__(self, iou_devices, parent):

        super().__init__(iou_devices, parent)
        self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/symbols/multilayer_switch.svg"))

        self.uiTypeComboBox.currentIndexChanged[str].connect(self._typeChangedSlot)

        if ComputeManager.instance().localPlatform().startswith("win") or ComputeManager.instance().localPlatform().startswith("darwin"):
            # Cannot use IOU locally on Windows and Mac
            self._disableLocalServer()

        # Available types
        self.uiTypeComboBox.addItems(["L2 image", "L3 image"])

        # Mandatory fields
        self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiNameWizardPage.registerField("image*", self.uiIOUImageLineEdit)

        self.uiIOUImageLineEdit.textChanged.connect(self._imageLineEditTextChangedSlot)

        # location of the base config templates
        self._base_iou_l2_config_template = "iou_l2_base_startup-config.txt"
        self._base_iou_l3_config_template = "iou_l3_base_startup-config.txt"

        from ..pages.iou_device_preferences_page import IOUDevicePreferencesPage
        self.addImageSelector(self.uiExistingImageRadioButton, self.uiIOUImageListComboBox, self.uiIOUImageLineEdit, self.uiIOUImageToolButton, IOUDevicePreferencesPage.getIOUImage)
Example #2
0
    def __init__(self, iou_devices, parent):

        super().__init__(iou_devices, parent)
        self.setPixmap(QtWidgets.QWizard.LogoPixmap,
                       QtGui.QPixmap(":/symbols/multilayer_switch.svg"))

        self.uiTypeComboBox.currentIndexChanged[str].connect(
            self._typeChangedSlot)

        if ComputeManager.instance().localPlatform().startswith(
                "win") or ComputeManager.instance().localPlatform().startswith(
                    "darwin"):
            # Cannot use IOU locally on Windows and Mac
            self._disableLocalServer()

        # Available types
        self.uiTypeComboBox.addItems(["L2 image", "L3 image"])

        # Mandatory fields
        self.uiNameWizardPage.registerField("name*", self.uiNameLineEdit)
        self.uiNameWizardPage.registerField("image*", self.uiIOUImageLineEdit)

        self.uiIOUImageLineEdit.textChanged.connect(
            self._imageLineEditTextChangedSlot)

        # location of the base config templates
        self._base_iou_l2_config_template = "iou_l2_base_startup-config.txt"
        self._base_iou_l3_config_template = "iou_l3_base_startup-config.txt"

        from ..pages.iou_device_preferences_page import IOUDevicePreferencesPage
        self.addImageSelector(self.uiExistingImageRadioButton,
                              self.uiIOUImageListComboBox,
                              self.uiIOUImageLineEdit,
                              self.uiIOUImageToolButton,
                              IOUDevicePreferencesPage.getIOUImage)
Example #3
0
def test_updateList_no_change(controller):
    cm = ComputeManager()
    computes = []
    compute = copy.copy(cm.getCompute("test1"))
    computes.append(compute)
    controller._http_client = MagicMock()
    cm.updateList(computes)
    assert not controller._http_client.createHTTPQuery.called
Example #4
0
def test_updateList_no_change(controller):
    cm = ComputeManager()
    computes = []
    compute = copy.copy(cm.getCompute("test1"))
    computes.append(compute)
    controller._http_client = MagicMock()
    cm.updateList(computes)
    assert not controller._http_client.createHTTPQuery.called
Example #5
0
def test_updateList_added(controller):
    cm = ComputeManager()
    computes = []
    compute = Compute()
    computes.append(compute)
    controller._http_client = MagicMock()
    cm.updateList(computes)
    assert compute.id() in cm._computes
    controller._http_client.createHTTPQuery.assert_called_with("POST", "/computes", None, body=compute.__json__())
Example #6
0
def test_updateList_updated(controller):
    cm = ComputeManager()
    computes = []
    compute = copy.copy(cm.getCompute("test1"))
    computes.append(compute)
    compute.setName("TEST2")
    cm.updateList(computes)
    assert cm._computes["test1"].name() == "TEST2"
    controller._http_client.createHTTPQuery.assert_called_with("PUT", "/computes/test1", None, body=compute.__json__())
Example #7
0
def test_updateList_updated(controller):
    cm = ComputeManager()
    computes = []
    compute = copy.copy(cm.getCompute("test1"))
    computes.append(compute)
    compute.setName("TEST2")
    cm.updateList(computes)
    assert cm._computes["test1"].name() == "TEST2"
    controller._http_client.createHTTPQuery.assert_called_with(
        "PUT", "/computes/test1", None, body=compute.__json__())
Example #8
0
def test_updateList_added(controller):
    cm = ComputeManager()
    computes = []
    compute = Compute()
    computes.append(compute)
    controller._http_client = MagicMock()
    cm.updateList(computes)
    assert compute.id() in cm._computes
    controller._http_client.createHTTPQuery.assert_called_with(
        "POST", "/computes", None, body=compute.__json__())
Example #9
0
def test_deleteCompute(controller):
    callback_delete = MagicMock()
    cm = ComputeManager()
    cm.deleted_signal.connect(callback_delete)
    compute = cm.getCompute("test")
    assert cm.getCompute("test") == compute
    cm.deleteCompute("test")
    assert "test" not in cm._computes
    assert callback_delete.called
    controller._http_client.createHTTPQuery.assert_called_with("DELETE", "/computes/test", None)
Example #10
0
    def _getQemuBinariesFromServerCallback(self,
                                           result,
                                           error=False,
                                           **kwargs):
        """
        Callback for getQemuBinariesFromServer.

        :param result: server response
        :param error: indicates an error (boolean)
        """

        if error:
            QtWidgets.QMessageBox.critical(self, "Qemu binaries",
                                           "{}".format(result["message"]))
        else:
            self.uiQemuListComboBox.clear()
            for qemu in result:
                if qemu["version"]:
                    self.uiQemuListComboBox.addItem(
                        "{path} (v{version})".format(path=qemu["path"],
                                                     version=qemu["version"]),
                        qemu["path"])
                else:
                    self.uiQemuListComboBox.addItem(
                        "{path}".format(path=qemu["path"]), qemu["path"])

            is_64bit = sys.maxsize > 2**32
            if ComputeManager.instance().localPlatform().startswith(
                    "win") and self.uiLocalRadioButton.isChecked():
                if self.uiLegacyASACheckBox.isChecked():
                    search_string = r"qemu-0.13.0\qemu-system-i386w.exe"
                elif is_64bit:
                    # default is qemu-system-x86_64w.exe on Windows 64-bit with a remote server
                    search_string = "x86_64w.exe"
                else:
                    # default is qemu-system-i386w.exe on Windows 32-bit with a remote server
                    search_string = "i386w.exe"
            elif ComputeManager.instance().localPlatform().startswith(
                    "darwin") and hasattr(
                        sys, "frozen") and self.uiLocalRadioButton.isChecked():
                search_string = "GNS3.app/Contents/MacOS/qemu/bin/qemu-system-x86_64"
            elif is_64bit:
                # default is qemu-system-x86_64 on other 64-bit platforms
                search_string = "x86_64"
            else:
                # default is qemu-system-i386 on other platforms
                search_string = "i386"

            index = self.uiQemuListComboBox.findData(
                search_string, flags=QtCore.Qt.MatchEndsWith)
            if index != -1:
                self.uiQemuListComboBox.setCurrentIndex(index)
Example #11
0
    def __init__(self, docker_containers, parent):

        super().__init__(docker_containers, parent)
        self._docker_containers = docker_containers
        self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/icons/docker.png"))

        self.uiNewImageRadioButton.setChecked(True)
        self._existingImageRadioButtonToggledSlot(False)
        self.uiExistingImageRadioButton.toggled.connect(self._existingImageRadioButtonToggledSlot)

        if ComputeManager.instance().localPlatform().startswith("win") or ComputeManager.instance().localPlatform().startswith("darwin"):
            # Cannot use Docker locally on Windows and Mac
            self._disableLocalServer()
Example #12
0
    def __init__(self, docker_containers, parent):

        super().__init__(docker_containers, parent)
        self._docker_containers = docker_containers
        self.setPixmap(QtWidgets.QWizard.LogoPixmap, QtGui.QPixmap(":/icons/docker.png"))

        self.uiNewImageRadioButton.setChecked(True)
        self._existingImageRadioButtonToggledSlot(False)
        self.uiExistingImageRadioButton.toggled.connect(self._existingImageRadioButtonToggledSlot)

        if ComputeManager.instance().localPlatform().startswith("win") or ComputeManager.instance().localPlatform().startswith("darwin"):
            # Cannot use Docker locally on Windows and Mac
            self._disableLocalServer()
Example #13
0
def reset_modules():
    """
    Reset modules (VPCS, VirtualBox...) internal variables.
    """

    from gns3.ports.port import Port
    from gns3.modules.vpcs.vpcs_node import VPCSNode
    from gns3.modules.virtualbox.virtualbox_vm import VirtualBoxVM
    from gns3.modules.iou.iou_device import IOUDevice
    from gns3.compute_manager import ComputeManager

    ComputeManager.reset()
    VPCSNode.reset()
    VirtualBoxVM.reset()
    IOUDevice.reset()
Example #14
0
def reset_modules():
    """
    Reset modules (VPCS, VirtualBox...) internal variables.
    """

    from gns3.ports.port import Port
    from gns3.modules.vpcs.vpcs_node import VPCSNode
    from gns3.modules.virtualbox.virtualbox_vm import VirtualBoxVM
    from gns3.modules.iou.iou_device import IOUDevice
    from gns3.compute_manager import ComputeManager

    ComputeManager.reset()
    VPCSNode.reset()
    VirtualBoxVM.reset()
    IOUDevice.reset()
Example #15
0
    def _refreshInfo(self, ethernet_hub):

        self.uiEthernetHubInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", ethernet_hub["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", ethernet_hub["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    ethernet_hub["server"]).name()
            ])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Number of ports:",
             str(len(ethernet_hub["ports_mapping"]))])

        self.uiEthernetHubInfoTreeWidget.expandAll()
        self.uiEthernetHubInfoTreeWidget.resizeColumnToContents(0)
        self.uiEthernetHubInfoTreeWidget.resizeColumnToContents(1)
        self.uiEthernetHubsTreeWidget.setMaximumWidth(
            self.uiEthernetHubsTreeWidget.sizeHintForColumn(0) + 20)
    def _refreshInfo(self, vbox_vm):

        self.uiVirtualBoxVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", vbox_vm["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["VirtualBox name:", vbox_vm["vmname"]])
        if vbox_vm["linked_clone"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", vbox_vm["default_name_format"]])
        QtWidgets.QTreeWidgetItem(section_item, ["RAM:", str(vbox_vm["ram"])])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(vbox_vm["server"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Headless mode enabled:", "{}".format(vbox_vm["headless"])])
        QtWidgets.QTreeWidgetItem(section_item, ["ACPI shutdown enabled:", "{}".format(vbox_vm["acpi_shutdown"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Linked base VM:", "{}".format(vbox_vm["linked_clone"])])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(vbox_vm["adapters"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Name format:", vbox_vm["port_name_format"]])
        if vbox_vm["port_segment_size"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Segment size:", str(vbox_vm["port_segment_size"])])
        if vbox_vm["first_port_name"]:
            QtWidgets.QTreeWidgetItem(section_item, ["First port name:", vbox_vm["first_port_name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Use any adapter:", "{}".format(vbox_vm["use_any_adapter"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Type:", vbox_vm["adapter_type"]])

        self.uiVirtualBoxVMInfoTreeWidget.expandAll()
        self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiVirtualBoxVMsTreeWidget.setMaximumWidth(self.uiVirtualBoxVMsTreeWidget.sizeHintForColumn(0) + 10)
Example #17
0
    def _refreshInfo(self, cloud_node):
        """
        Refreshes the content of the tree widget.
        """

        self.uiCloudNodeInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", cloud_node["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", cloud_node.get("template_id", "none")])
        if cloud_node["remote_console_type"] != "none":
            QtWidgets.QTreeWidgetItem(section_item, ["Console host:", cloud_node["remote_console_host"]])
            QtWidgets.QTreeWidgetItem(section_item, ["Console port:", "{}".format(cloud_node["remote_console_port"])])
            if cloud_node["remote_console_type"] in ("http", "https"):
                QtWidgets.QTreeWidgetItem(section_item, ["Console HTTP path:", cloud_node["remote_console_http_path"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", cloud_node["remote_console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", cloud_node["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(cloud_node["compute_id"]).name()])
        except KeyError:
            pass

        self.uiCloudNodeInfoTreeWidget.expandAll()
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(0)
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(1)
        self.uiCloudNodesTreeWidget.setMaximumWidth(self.uiCloudNodesTreeWidget.sizeHintForColumn(0) + 20)
    def _refreshInfo(self, ethernet_switch):
        """
        Refreshes the content of the tree widget.
        """

        self.uiEthernetSwitchInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", ethernet_switch["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", ethernet_switch.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", ethernet_switch["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(ethernet_switch["compute_id"]).name()])
        except KeyError:
            pass

        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", ethernet_switch["console_type"]])
        for port in ethernet_switch["ports_mapping"]:
            section_item = self._createSectionItem("Port{}".format(port["port_number"]))
            QtWidgets.QTreeWidgetItem(section_item, ["Name:", port["name"]])
            QtWidgets.QTreeWidgetItem(section_item, ["Type:", port["type"]])
            QtWidgets.QTreeWidgetItem(section_item, ["VLAN:", str(port["vlan"])])

        self.uiEthernetSwitchInfoTreeWidget.expandAll()
        self.uiEthernetSwitchInfoTreeWidget.resizeColumnToContents(0)
        self.uiEthernetSwitchInfoTreeWidget.resizeColumnToContents(1)
        self.uiEthernetSwitchesTreeWidget.setMaximumWidth(self.uiEthernetSwitchesTreeWidget.sizeHintForColumn(0) + 20)
Example #19
0
    def initializePage(self, page_id):

        super().initializePage(page_id)

        if self.currentPage() == self.uiNameWizardPage:
            if self.uiLocalRadioButton.isChecked(
            ) and not ComputeManager.instance().localPlatform().startswith(
                    "linux"):
                QtWidgets.QMessageBox.warning(
                    self, "QEMU on Windows or Mac",
                    "The recommended way to run QEMU on Windows and OSX is to use the GNS3 VM"
                )

        if self.page(page_id) in [
                self.uiDiskWizardPage, self.uiInitrdKernelImageWizardPage
        ]:
            self.loadImagesList("/qemu/images")
        elif self.page(page_id) == self.uiBinaryMemoryWizardPage:
            try:
                Qemu.instance().getQemuBinariesFromServer(
                    self._compute_id, self._getQemuBinariesFromServerCallback)
            except ModuleError as e:
                QtWidgets.QMessageBox.critical(
                    self, "Qemu binaries",
                    "Error while getting the QEMU binaries: {}".format(e))
    def _refreshInfo(self, vbox_vm):

        self.uiVirtualBoxVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", vbox_vm["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["VirtualBox name:", vbox_vm["vmname"]])
        if vbox_vm["linked_base"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", vbox_vm["default_name_format"]])
        QtWidgets.QTreeWidgetItem(section_item, ["RAM:", str(vbox_vm["ram"])])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(vbox_vm["server"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Headless mode enabled:", "{}".format(vbox_vm["headless"])])
        QtWidgets.QTreeWidgetItem(section_item, ["ACPI shutdown enabled:", "{}".format(vbox_vm["acpi_shutdown"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Linked base VM:", "{}".format(vbox_vm["linked_base"])])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(vbox_vm["adapters"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Name format:", vbox_vm["port_name_format"]])
        if vbox_vm["port_segment_size"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Segment size:", str(vbox_vm["port_segment_size"])])
        if vbox_vm["first_port_name"]:
            QtWidgets.QTreeWidgetItem(section_item, ["First port name:", vbox_vm["first_port_name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Use any adapter:", "{}".format(vbox_vm["use_any_adapter"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Type:", vbox_vm["adapter_type"]])

        self.uiVirtualBoxVMInfoTreeWidget.expandAll()
        self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiVirtualBoxVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiVirtualBoxVMsTreeWidget.setMaximumWidth(self.uiVirtualBoxVMsTreeWidget.sizeHintForColumn(0) + 10)
Example #21
0
    def __init__(self, devices, parent):
        super().__init__(parent)
        self.setupUi(self)

        self.setModal(True)

        self._devices = devices
        self._local_server_disable = False

        self.setWizardStyle(QtWidgets.QWizard.ModernStyle)
        if sys.platform.startswith("darwin"):
            # we want to see the cancel button on OSX
            self.setOptions(QtWidgets.QWizard.NoDefaultButton)

        self.uiRemoteRadioButton.toggled.connect(self._remoteServerToggledSlot)
        if hasattr(self, "uiVMRadioButton"):
            self.uiVMRadioButton.toggled.connect(self._vmToggledSlot)

        self.uiLocalRadioButton.toggled.connect(self._localToggledSlot)
        if Controller.instance().isRemote():
            self.uiLocalRadioButton.setText("Run device on the main server")

        # By default we use the local server
        self._compute_id = "local"
        self.uiLocalRadioButton.setChecked(True)
        self._localToggledSlot(True)

        if len(ComputeManager.instance().computes()) == 1:
            # skip the server page if we use the first server
            self.setStartId(1)
Example #22
0
    def initializePage(self, page_id):

        if self.page(page_id) == self.uiServerWizardPage:
            self.uiRemoteServersComboBox.clear()

            self.uiRemoteRadioButton.setEnabled(False)
            if hasattr(self, "uiVMRadioButton"):
                self.uiVMRadioButton.setEnabled(False)
            self.uiLocalRadioButton.setEnabled(False)
            for compute in ComputeManager.instance().computes():
                if compute.id() == "local":
                    self.uiLocalRadioButton.setEnabled(True)
                elif compute.id() == "vm":
                    if hasattr(self, "uiVMRadioButton"):
                        self.uiVMRadioButton.setEnabled(True)
                else:
                    self.uiRemoteRadioButton.setEnabled(True)
                    self.uiRemoteServersComboBox.addItem(compute.name(), compute.id())

            if self.uiLocalRadioButton.isEnabled() and not self._local_server_disable:
                self.uiLocalRadioButton.setChecked(True)
            elif hasattr(self, "uiVMRadioButton") and self.uiVMRadioButton.isEnabled():
                self.uiVMRadioButton.setChecked(True)
            else:
                if self.uiRemoteRadioButton.isEnabled():
                    self.uiRemoteRadioButton.setChecked(True)
                else:
                    self.uiLocalRadioButton.setChecked(True)
Example #23
0
 def _event_received(self, result, *args, **kwargs):
     # Log only relevant events
     if result["action"] not in ("ping", "compute.updated"):
         log.debug("Event received: %s", result)
     if result["action"] == "node.created":
         node = Topology.instance().getNodeFromUuid(result["event"]["node_id"])
         if node is None:
             Topology.instance().createNode(result["event"])
     elif result["action"] == "node.updated":
         node = Topology.instance().getNodeFromUuid(result["event"]["node_id"])
         if node is not None:
             node.updateNodeCallback(result["event"])
     elif result["action"] == "node.deleted":
         node = Topology.instance().getNodeFromUuid(result["event"]["node_id"])
         if node is not None:
             node.delete(skip_controller=True)
     elif result["action"] == "link.created":
         link = Topology.instance().getLinkFromUuid(result["event"]["link_id"])
         if link is None:
             Topology.instance().createLink(result["event"])
     elif result["action"] == "link.updated":
         link = Topology.instance().getLinkFromUuid(result["event"]["link_id"])
         if link is not None:
             link.updateLinkCallback(result["event"])
     elif result["action"] == "link.deleted":
         link = Topology.instance().getLinkFromUuid(result["event"]["link_id"])
         if link is not None:
             link.deleteLink(skip_controller=True)
     elif result["action"] == "drawing.created":
         drawing = Topology.instance().getDrawingFromUuid(result["event"]["drawing_id"])
         if drawing is None:
             Topology.instance().createDrawing(result["event"])
     elif result["action"] == "drawing.updated":
         drawing = Topology.instance().getDrawingFromUuid(result["event"]["drawing_id"])
         if drawing is not None:
             drawing.updateDrawingCallback(result["event"])
     elif result["action"] == "drawing.deleted":
         drawing = Topology.instance().getDrawingFromUuid(result["event"]["drawing_id"])
         if drawing is not None:
             drawing.delete(skip_controller=True)
     elif result["action"] == "project.closed":
         Topology.instance().setProject(None)
     elif result["action"] == "project.updated":
         self._projectUpdatedCallback(result["event"])
     elif result["action"] == "snapshot.restored":
         Topology.instance().createLoadProject({"project_id": result["event"]["project_id"]})
     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"] == "compute.created" or result["action"] == "compute.updated":
         cm = ComputeManager.instance()
         cm.computeDataReceivedCallback(result["event"])
     elif result["action"] == "settings.updated":
         LocalConfig.instance().refreshConfigFromController()
         ApplianceManager.instance().refresh()
     elif result["action"] == "ping":
         pass
Example #24
0
    def _refreshInfo(self, cloud_node):

        self.uiCloudNodeInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", cloud_node["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", cloud_node["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    cloud_node["server"]).name()
            ])
        except KeyError:
            pass

        self.uiCloudNodeInfoTreeWidget.expandAll()
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(0)
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(1)
        self.uiCloudNodesTreeWidget.setMaximumWidth(
            self.uiCloudNodesTreeWidget.sizeHintForColumn(0) + 20)
    def _refreshInfo(self, docker_container):
        """
        Refreshes the content of the tree widget.
        """

        self.uiDockerVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", docker_container["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", docker_container.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Image name:", docker_container["image"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(docker_container["compute_id"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", str(docker_container["console_type"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto start console:", "{}".format(docker_container["console_auto_start"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", docker_container["default_name_format"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(docker_container["adapters"])])
        if docker_container["start_command"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Start command:", str(docker_container["start_command"])])
        if docker_container["environment"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Environment:", str(docker_container["environment"])])

        if docker_container["extra_hosts"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Extra hosts:", str(docker_container["extra_hosts"])])

        if docker_container["extra_volumes"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Extra volumes:", "\n".join(docker_container["extra_volumes"])])

        self.uiDockerVMInfoTreeWidget.expandAll()
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiDockerVMsTreeWidget.setMaximumWidth(self.uiDockerVMsTreeWidget.sizeHintForColumn(0) + 10)
    def _refreshInfo(self, vpcs_node):
        """
        Refreshes the content of the tree widget.
        """

        self.uiVPCSInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", vpcs_node["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", vpcs_node.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", vpcs_node["default_name_format"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", vpcs_node["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto start console:", "{}".format(vpcs_node["console_auto_start"])])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(vpcs_node["compute_id"]).name()])
        except KeyError:
            pass
        if vpcs_node["base_script_file"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Base script file:", vpcs_node["base_script_file"]])

        self.uiVPCSInfoTreeWidget.expandAll()
        self.uiVPCSInfoTreeWidget.resizeColumnToContents(0)
        self.uiVPCSInfoTreeWidget.resizeColumnToContents(1)
        self.uiVPCSTreeWidget.setMaximumWidth(self.uiVPCSTreeWidget.sizeHintForColumn(0) + 20)
Example #27
0
    def _refreshInfo(self, iou_device):

        self.uiIOUDeviceInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", iou_device["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", iou_device["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    iou_device["server"]).name()
            ])
        except KeyError:
            # Compute doesn't exists
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Image:", iou_device["path"]])
        if iou_device["startup_config"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Startup-config:", iou_device["startup_config"]])

        if iou_device["private_config"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Private-config:", iou_device["private_config"]])

        if iou_device["use_default_iou_values"]:
            QtWidgets.QTreeWidgetItem(section_item, ["RAM:", "default"])
            QtWidgets.QTreeWidgetItem(section_item, ["NVRAM:", "default"])
        else:
            QtWidgets.QTreeWidgetItem(
                section_item, ["RAM:", "{} MiB".format(iou_device["ram"])])
            QtWidgets.QTreeWidgetItem(
                section_item, ["NVRAM:", "{} KiB".format(iou_device["nvram"])])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, [
            "Ethernet adapters:", "{} ({} interfaces)".format(
                iou_device["ethernet_adapters"],
                iou_device["ethernet_adapters"] * 4)
        ])
        QtWidgets.QTreeWidgetItem(section_item, [
            "Serial adapters:", "{} ({} interfaces)".format(
                iou_device["serial_adapters"],
                iou_device["serial_adapters"] * 4)
        ])

        self.uiIOUDeviceInfoTreeWidget.expandAll()
        self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(0)
        self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(1)
        self.uiIOUDevicesTreeWidget.setMaximumWidth(
            self.uiIOUDevicesTreeWidget.sizeHintForColumn(0) + 10)
Example #28
0
def test_computeDataReceivedCallback():
    callback_create = MagicMock()
    callback_update = MagicMock()
    cm = ComputeManager()
    cm.created_signal.connect(callback_create)
    cm.updated_signal.connect(callback_update)
    cm.computeDataReceivedCallback({
        "compute_id": "test",
        "name": "Test server",
        "connected": False,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {"test": "a"}
    })
    assert cm._computes["test"].name() == "Test server"
    assert cm._computes["test"].protocol() == "http"
    assert cm._computes["test"].host() == "test.org"
    assert cm._computes["test"].port() == 3080
    assert cm._computes["test"].user() is None
    assert cm._computes["test"].capabilities() == {"test": "a"}
    assert cm._computes["test"].connected() is False
    assert callback_create.called
    assert not callback_update.called

    # Data should be update
    cm.computeDataReceivedCallback({
        "compute_id": "test",
        "name": "Test Compute",
        "connected": True,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {"test": "a"}
    })
    assert cm._computes["test"].name() == "Test Compute"
    assert cm._computes["test"].connected()
    assert callback_update.called
Example #29
0
def test_getComputeRemote1X():
    """
    It should convert old server id
    """
    cm = ComputeManager()
    cm.computeDataReceivedCallback({
        "compute_id": "aaecb19d-5a32-4c18-ac61-f54f92a0f594",
        "name": "Test Compute",
        "connected": True,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {"test": "a"}
    })

    compute = cm.getCompute("aaecb19d-5a32-4c18-ac61-f54f92a0f594")
    assert cm.getCompute("http://test.org:3080") == compute
Example #30
0
def test_listComputesCallback():
    callback = MagicMock()
    cm = ComputeManager()
    cm.created_signal.connect(callback)
    cm._listComputesCallback([
        {
            "compute_id": "local",
            "name": "Local server",
            "connected": False,
            "protocol": "http",
            "host": "localhost",
            "port": 3080,
            "user": None,
            "cpu_usage_percent": None,
            "memory_usage_percent": None,
            "capabilities": {"test": "a"}
        }
    ])
    assert cm._computes["local"].name() == "Local server"
    assert callback.called
Example #31
0
def test_listComputesCallback():
    callback = MagicMock()
    cm = ComputeManager()
    cm.created_signal.connect(callback)
    cm._listComputesCallback([{
        "compute_id": "local",
        "name": "Local server",
        "connected": False,
        "protocol": "http",
        "host": "localhost",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {
            "test": "a"
        }
    }])
    assert cm._computes["local"].name() == "Local server"
    assert callback.called
Example #32
0
    def _getQemuBinariesFromServerCallback(self, result, error=False, **kwargs):
        """
        Callback for getQemuBinariesFromServer.

        :param result: server response
        :param error: indicates an error (boolean)
        """

        if error:
            QtWidgets.QMessageBox.critical(self, "Qemu binaries", "{}".format(result["message"]))
        else:
            self.uiQemuListComboBox.clear()
            for qemu in result:
                if qemu["version"]:
                    self.uiQemuListComboBox.addItem("{path} (v{version})".format(path=qemu["path"], version=qemu["version"]), qemu["path"])
                else:
                    self.uiQemuListComboBox.addItem("{path}".format(path=qemu["path"]), qemu["path"])

            is_64bit = sys.maxsize > 2 ** 32
            if ComputeManager.instance().localPlatform().startswith("win") and self.uiLocalRadioButton.isChecked():
                if self.uiLegacyASACheckBox.isChecked():
                    search_string = r"qemu-0.13.0\qemu-system-i386w.exe"
                elif is_64bit:
                    # default is qemu-system-x86_64w.exe on Windows 64-bit with a remote server
                    search_string = "x86_64w.exe"
                else:
                    # default is qemu-system-i386w.exe on Windows 32-bit with a remote server
                    search_string = "i386w.exe"
            elif ComputeManager.instance().localPlatform().startswith("darwin") and hasattr(sys, "frozen") and self.uiLocalRadioButton.isChecked():
                search_string = "GNS3.app/Contents/MacOS/qemu/bin/qemu-system-x86_64"
            elif is_64bit:
                # default is qemu-system-x86_64 on other 64-bit platforms
                search_string = "x86_64"
            else:
                # default is qemu-system-i386 on other platforms
                search_string = "i386"

            index = self.uiQemuListComboBox.findData(search_string, flags=QtCore.Qt.MatchEndsWith)
            if index != -1:
                self.uiQemuListComboBox.setCurrentIndex(index)
Example #33
0
def test_updateList_deleted(controller):
    cm = ComputeManager()
    computes = []
    computes.append(cm.getCompute("test1"))
    computes.append(cm.getCompute("test2"))
    # This server new to be deleted because exist in compute manager
    # but not in setting list
    cm.getCompute("test3")
    cm.updateList(computes)
    assert "test1" in cm._computes
    assert "test2" in cm._computes
    assert "test3" not in cm._computes
Example #34
0
    def initializePage(self, page_id):

        super().initializePage(page_id)

        if self.currentPage() == self.uiNameWizardPage:
            if self.uiLocalRadioButton.isChecked() and not ComputeManager.instance().localPlatform().startswith("linux"):
                QtWidgets.QMessageBox.warning(self, "QEMU on Windows or Mac", "The recommended way to run QEMU on Windows and OSX is to use the GNS3 VM")

        if self.page(page_id) in [self.uiDiskWizardPage, self.uiInitrdKernelImageWizardPage]:
            self.loadImagesList("/qemu/images")
        elif self.page(page_id) == self.uiBinaryMemoryWizardPage:
            try:
                Qemu.instance().getQemuBinariesFromServer(self._compute_id, self._getQemuBinariesFromServerCallback)
            except ModuleError as e:
                QtWidgets.QMessageBox.critical(self, "Qemu binaries", "Error while getting the QEMU binaries: {}".format(e))
Example #35
0
def test_deleteCompute(controller):
    callback_delete = MagicMock()
    cm = ComputeManager()
    cm.deleted_signal.connect(callback_delete)
    compute = cm.getCompute("test")
    assert cm.getCompute("test") == compute
    cm.deleteCompute("test")
    assert "test" not in cm._computes
    assert callback_delete.called
    controller._http_client.createHTTPQuery.assert_called_with(
        "DELETE", "/computes/test", None)
Example #36
0
    def _refreshInfo(self, cloud_node):
        """
        Refreshes the content of the tree widget.
        """

        self.uiCloudNodeInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", cloud_node["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Template ID:",
             cloud_node.get("template_id", "none")])
        if cloud_node["remote_console_type"] != "none":
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Console host:", cloud_node["remote_console_host"]])
            QtWidgets.QTreeWidgetItem(section_item, [
                "Console port:", "{}".format(cloud_node["remote_console_port"])
            ])
            if cloud_node["remote_console_type"] in ("http", "https"):
                QtWidgets.QTreeWidgetItem(section_item, [
                    "Console HTTP path:",
                    cloud_node["remote_console_http_path"]
                ])
        QtWidgets.QTreeWidgetItem(
            section_item, ["Console type:", cloud_node["remote_console_type"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", cloud_node["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    cloud_node["compute_id"]).name()
            ])
        except KeyError:
            pass

        self.uiCloudNodeInfoTreeWidget.expandAll()
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(0)
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(1)
        self.uiCloudNodesTreeWidget.setMaximumWidth(
            self.uiCloudNodesTreeWidget.sizeHintForColumn(0) + 20)
    def _refreshInfo(self, cloud_node):

        self.uiCloudNodeInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", cloud_node["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", cloud_node["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(cloud_node["server"]).name()])
        except KeyError:
            pass

        self.uiCloudNodeInfoTreeWidget.expandAll()
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(0)
        self.uiCloudNodeInfoTreeWidget.resizeColumnToContents(1)
        self.uiCloudNodesTreeWidget.setMaximumWidth(self.uiCloudNodesTreeWidget.sizeHintForColumn(0) + 20)
Example #38
0
def test_updateList_deleted(controller):
    cm = ComputeManager()
    computes = []
    computes.append(cm.getCompute("test1"))
    computes.append(cm.getCompute("test2"))
    # This server new to be deleted because exist in compute manager
    # but not in setting list
    cm.getCompute("test3")
    cm.updateList(computes)
    assert "test1" in cm._computes
    assert "test2" in cm._computes
    assert "test3" not in cm._computes
    def _refreshInfo(self, iou_device):
        """
        Refreshes the content of the tree widget.
        """

        self.uiIOUDeviceInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", iou_device["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", iou_device.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", iou_device["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(iou_device["compute_id"]).name()])
        except KeyError:
            # Compute doesn't exists
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", iou_device["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto start console:", "{}".format(iou_device["console_auto_start"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Image:", iou_device["path"]])
        if iou_device["startup_config"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Startup-config:", iou_device["startup_config"]])

        if iou_device["private_config"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Private-config:", iou_device["private_config"]])

        if iou_device["use_default_iou_values"]:
            QtWidgets.QTreeWidgetItem(section_item, ["RAM:", "default"])
            QtWidgets.QTreeWidgetItem(section_item, ["NVRAM:", "default"])
        else:
            QtWidgets.QTreeWidgetItem(section_item, ["RAM:", "{} MiB".format(iou_device["ram"])])
            QtWidgets.QTreeWidgetItem(section_item, ["NVRAM:", "{} KiB".format(iou_device["nvram"])])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, ["Ethernet adapters:", "{} ({} interfaces)".format(iou_device["ethernet_adapters"],
                                                                                                   iou_device["ethernet_adapters"] * 4)])
        QtWidgets.QTreeWidgetItem(section_item, ["Serial adapters:", "{} ({} interfaces)".format(iou_device["serial_adapters"],
                                                                                                 iou_device["serial_adapters"] * 4)])

        self.uiIOUDeviceInfoTreeWidget.expandAll()
        self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(0)
        self.uiIOUDeviceInfoTreeWidget.resizeColumnToContents(1)
        self.uiIOUDevicesTreeWidget.setMaximumWidth(self.uiIOUDevicesTreeWidget.sizeHintForColumn(0) + 10)
    def _refreshInfo(self, ethernet_switch):
        """
        Refreshes the content of the tree widget.
        """

        self.uiEthernetSwitchInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", ethernet_switch["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Template ID:",
             ethernet_switch.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", ethernet_switch["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    ethernet_switch["compute_id"]).name()
            ])
        except KeyError:
            pass

        QtWidgets.QTreeWidgetItem(
            section_item, ["Console type:", ethernet_switch["console_type"]])
        for port in ethernet_switch["ports_mapping"]:
            section_item = self._createSectionItem("Port{}".format(
                port["port_number"]))
            QtWidgets.QTreeWidgetItem(section_item, ["Name:", port["name"]])
            QtWidgets.QTreeWidgetItem(section_item, ["Type:", port["type"]])
            QtWidgets.QTreeWidgetItem(section_item,
                                      ["VLAN:", str(port["vlan"])])

        self.uiEthernetSwitchInfoTreeWidget.expandAll()
        self.uiEthernetSwitchInfoTreeWidget.resizeColumnToContents(0)
        self.uiEthernetSwitchInfoTreeWidget.resizeColumnToContents(1)
        self.uiEthernetSwitchesTreeWidget.setMaximumWidth(
            self.uiEthernetSwitchesTreeWidget.sizeHintForColumn(0) + 20)
Example #41
0
    def _projectCreatedSlot(self, *args):
        if Topology.instance().project() is None:
            return
        try:
            Topology.instance().project().project_updated_signal.disconnect(self._projectCreatedSlot)
            self._project_created = True
        except TypeError:
            pass  # If the slot is not connected (project already created)

        module = Dynamips.instance()
        platform = self.uiPlatformComboBox.currentText()
        ios_image = self.uiIOSImageLineEdit.text()
        ram = self.uiRamSpinBox.value()
        router_class = PLATFORM_TO_CLASS[platform]

        self._router = router_class(module, ComputeManager.instance().getCompute(self._compute_id), Topology.instance().project())
        self._router.create(ios_image, ram, name="AUTOIDLEPC")
        self._router.created_signal.connect(self.createdSlot)
        self._router.server_error_signal.connect(self.serverErrorSlot)
        self.uiIdlePCFinderPushButton.setEnabled(False)
Example #42
0
    def _refreshInfo(self, docker_image):

        self.uiDockerVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Image name:", docker_image["image"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    docker_image["server"]).name()
            ])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(
            section_item, ["Console type:",
                           str(docker_image["console_type"])])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", docker_image["default_name_format"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Adapters:", str(docker_image["adapters"])])
        if docker_image["start_command"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Start command:",
                 str(docker_image["start_command"])])
        if docker_image["environment"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Environment:",
                 str(docker_image["environment"])])

        self.uiDockerVMInfoTreeWidget.expandAll()
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiDockerVMsTreeWidget.setMaximumWidth(
            self.uiDockerVMsTreeWidget.sizeHintForColumn(0) + 10)
Example #43
0
def test_computeDataReceivedCallback():
    callback_create = MagicMock()
    callback_update = MagicMock()
    cm = ComputeManager()
    cm.created_signal.connect(callback_create)
    cm.updated_signal.connect(callback_update)
    cm.computeDataReceivedCallback({
        "compute_id": "test",
        "name": "Test server",
        "connected": False,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {
            "test": "a"
        }
    })
    assert cm._computes["test"].name() == "Test server"
    assert cm._computes["test"].protocol() == "http"
    assert cm._computes["test"].host() == "test.org"
    assert cm._computes["test"].port() == 3080
    assert cm._computes["test"].user() is None
    assert cm._computes["test"].capabilities() == {"test": "a"}
    assert cm._computes["test"].connected() is False
    assert callback_create.called
    assert not callback_update.called

    # Data should be update
    cm.computeDataReceivedCallback({
        "compute_id": "test",
        "name": "Test Compute",
        "connected": True,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {
            "test": "a"
        }
    })
    assert cm._computes["test"].name() == "Test Compute"
    assert cm._computes["test"].connected()
    assert callback_update.called
    def _refreshInfo(self, ethernet_hub):
        """
        Refreshes the content of the tree widget.
        """

        self.uiEthernetHubInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", ethernet_hub["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", ethernet_hub.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", ethernet_hub["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(ethernet_hub["compute_id"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Number of ports:", str(len(ethernet_hub["ports_mapping"]))])

        self.uiEthernetHubInfoTreeWidget.expandAll()
        self.uiEthernetHubInfoTreeWidget.resizeColumnToContents(0)
        self.uiEthernetHubInfoTreeWidget.resizeColumnToContents(1)
        self.uiEthernetHubsTreeWidget.setMaximumWidth(self.uiEthernetHubsTreeWidget.sizeHintForColumn(0) + 20)
Example #45
0
    def _refreshInfo(self, traceng_node):
        """
        Refreshes the content of the tree widget.
        """

        self.uiTraceNGInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", traceng_node["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", traceng_node.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["IP address:", traceng_node["ip_address"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", traceng_node["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(traceng_node["compute_id"]).name()])
        except KeyError:
            pass

        self.uiTraceNGInfoTreeWidget.expandAll()
        self.uiTraceNGInfoTreeWidget.resizeColumnToContents(0)
        self.uiTraceNGInfoTreeWidget.resizeColumnToContents(1)
        self.uiTraceNGTreeWidget.setMaximumWidth(self.uiTraceNGTreeWidget.sizeHintForColumn(0) + 20)
    def _refreshInfo(self, vmware_vm):
        """
        Refreshes the content of the tree widget.
        """

        self.uiVMwareVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", vmware_vm["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", vmware_vm.get("template_id", "none")])
        if vmware_vm["linked_clone"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", vmware_vm["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(vmware_vm["compute_id"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Headless mode enabled:", "{}".format(vmware_vm["headless"])])
        QtWidgets.QTreeWidgetItem(section_item, ["On close:", "{}".format(vmware_vm["on_close"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Linked base VM:", "{}".format(vmware_vm["linked_clone"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", vmware_vm["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto start console:", "{}".format(vmware_vm["console_auto_start"])])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(vmware_vm["adapters"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Name format:", vmware_vm["port_name_format"]])
        if vmware_vm["port_segment_size"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Segment size:", str(vmware_vm["port_segment_size"])])
        if vmware_vm["first_port_name"]:
            QtWidgets.QTreeWidgetItem(section_item, ["First port name:", vmware_vm["first_port_name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Use any adapter:", "{}".format(vmware_vm["use_any_adapter"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Type:", vmware_vm["adapter_type"]])

        self.uiVMwareVMInfoTreeWidget.expandAll()
        self.uiVMwareVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiVMwareVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiVMwareVMsTreeWidget.setMaximumWidth(self.uiVMwareVMsTreeWidget.sizeHintForColumn(0) + 10)
    def _refreshInfo(self, docker_image):

        self.uiDockerVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Image name:", docker_image["image"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(docker_image["server"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", str(docker_image["console_type"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", docker_image["default_name_format"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(docker_image["adapters"])])
        if docker_image["start_command"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Start command:", str(docker_image["start_command"])])
        if docker_image["environment"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Environment:", str(docker_image["environment"])])

        self.uiDockerVMInfoTreeWidget.expandAll()
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiDockerVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiDockerVMsTreeWidget.setMaximumWidth(self.uiDockerVMsTreeWidget.sizeHintForColumn(0) + 10)
Example #48
0
    def _projectCreatedSlot(self, *args):
        if Topology.instance().project() is None:
            return
        try:
            Topology.instance().project().project_updated_signal.disconnect(
                self._projectCreatedSlot)
            self._project_created = True
        except TypeError:
            pass  # If the slot is not connected (project already created)

        module = Dynamips.instance()
        platform = self.uiPlatformComboBox.currentText()
        ios_image = self.uiIOSImageLineEdit.text()
        ram = self.uiRamSpinBox.value()
        router_class = PLATFORM_TO_CLASS[platform]

        self._router = router_class(
            module,
            ComputeManager.instance().getCompute(self._compute_id),
            Topology.instance().project())
        self._router.create(ios_image, ram, name="AUTOIDLEPC")
        self._router.created_signal.connect(self.createdSlot)
        self._router.server_error_signal.connect(self.serverErrorSlot)
        self.uiIdlePCFinderPushButton.setEnabled(False)
Example #49
0
def test_getComputeRemote1X():
    """
    It should convert old server id
    """
    cm = ComputeManager()
    cm.computeDataReceivedCallback({
        "compute_id": "aaecb19d-5a32-4c18-ac61-f54f92a0f594",
        "name": "Test Compute",
        "connected": True,
        "protocol": "http",
        "host": "test.org",
        "port": 3080,
        "user": None,
        "cpu_usage_percent": None,
        "memory_usage_percent": None,
        "capabilities": {
            "test": "a"
        }
    })

    compute = cm.getCompute("aaecb19d-5a32-4c18-ac61-f54f92a0f594")
    assert cm.getCompute("http://test.org:3080") == compute
Example #50
0
def test_getCompute():
    cm = ComputeManager()
    compute = cm.getCompute("local")
    assert cm.getCompute("local") == compute
    def _refreshInfo(self, qemu_vm):

        self.uiQemuVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", qemu_vm["name"]])
        if qemu_vm["linked_clone"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", qemu_vm["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(qemu_vm["server"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", qemu_vm["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["CPUs:", str(qemu_vm["cpus"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Memory:", "{} MB".format(qemu_vm["ram"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Linked base VM:", "{}".format(qemu_vm["linked_clone"])])

        if qemu_vm["qemu_path"]:
            QtWidgets.QTreeWidgetItem(section_item, ["QEMU binary:", os.path.basename(qemu_vm["qemu_path"])])

        # fill out the Hard disks section
        if qemu_vm["hda_disk_image"] or qemu_vm["hdb_disk_image"] or qemu_vm["hdc_disk_image"] or qemu_vm["hdd_disk_image"]:
            section_item = self._createSectionItem("Hard disks")
            if qemu_vm["hda_disk_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Disk image (hda):", qemu_vm["hda_disk_image"]])
                QtWidgets.QTreeWidgetItem(section_item, ["Disk interface (hda):", qemu_vm["hda_disk_interface"]])
            if qemu_vm["hdb_disk_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Disk image (hdb):", qemu_vm["hdb_disk_image"]])
                QtWidgets.QTreeWidgetItem(section_item, ["Disk interface (hdb):", qemu_vm["hdb_disk_interface"]])
            if qemu_vm["hdc_disk_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Disk image (hdc):", qemu_vm["hdc_disk_image"]])
                QtWidgets.QTreeWidgetItem(section_item, ["Disk interface (hdc):", qemu_vm["hdc_disk_interface"]])
            if qemu_vm["hdd_disk_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Disk image (hdd):", qemu_vm["hdd_disk_image"]])
                QtWidgets.QTreeWidgetItem(section_item, ["Disk interface (hdd):", qemu_vm["hdd_disk_interface"]])
            if qemu_vm["cdrom_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["CD/DVD image:", qemu_vm["cdrom_image"]])
            if qemu_vm["bios_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Bios image:", qemu_vm["bios_image"]])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(section_item, ["Adapters:", str(qemu_vm["adapters"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Name format:", qemu_vm["port_name_format"]])
        if qemu_vm["port_segment_size"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Segment size:", str(qemu_vm["port_segment_size"])])
        if qemu_vm["first_port_name"]:
            QtWidgets.QTreeWidgetItem(section_item, ["First port name:", qemu_vm["first_port_name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Type:", qemu_vm["adapter_type"]])
        if qemu_vm["mac_address"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Base MAC address:", qemu_vm["mac_address"]])

        # fill out the Linux boot section
        if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm["kernel_command_line"]:
            section_item = self._createSectionItem("Linux boot")
            if qemu_vm["initrd"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Initial RAM disk:", qemu_vm["initrd"]])
            if qemu_vm["kernel_image"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Kernel image:", qemu_vm["kernel_image"]])
            if qemu_vm["kernel_command_line"]:
                QtWidgets.QTreeWidgetItem(section_item, ["Kernel command line:", qemu_vm["kernel_command_line"]])

        # performance section
        section_item = self._createSectionItem("Optimizations")
        if qemu_vm["cpu_throttling"]:
            QtWidgets.QTreeWidgetItem(section_item, ["CPU throttling:", "{}%".format(qemu_vm["cpu_throttling"])])
        else:
            QtWidgets.QTreeWidgetItem(section_item, ["CPU throttling:", "disabled"])
        QtWidgets.QTreeWidgetItem(section_item, ["Process priority:", qemu_vm["process_priority"]])

        # fill out the Additional options section
        section_item = self._createSectionItem("Additional options")
        if qemu_vm["options"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Options:", qemu_vm["options"]])
        QtWidgets.QTreeWidgetItem(section_item, ["ACPI shutdown:", "{}".format(qemu_vm["acpi_shutdown"])])

        self.uiQemuVMInfoTreeWidget.expandAll()
        self.uiQemuVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiQemuVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiQemuVMsTreeWidget.setMaximumWidth(self.uiQemuVMsTreeWidget.sizeHintForColumn(0) + 10)
    def _refreshInfo(self, ios_router):
        """
        Refreshes the content of the tree widget.
        """

        self.uiIOSRouterInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", ios_router["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Template ID:",
             ios_router.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Default name format:", ios_router["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    ios_router["compute_id"]).name()
            ])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Platform:", ios_router["platform"]])
        if ios_router.get("chassis"):
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Chassis:", ios_router.get("chassis")])
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Image:", ios_router["image"]])
        QtWidgets.QTreeWidgetItem(
            section_item, ["Console type:", ios_router["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, [
            "Auto start console:", "{}".format(
                ios_router["console_auto_start"])
        ])
        if ios_router["idlepc"]:
            QtWidgets.QTreeWidgetItem(section_item,
                                      ["Idle-PC:", ios_router["idlepc"]])
        if ios_router["startup_config"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Startup-config:", ios_router["startup_config"]])
        if ios_router["private_config"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Private-config:", ios_router["private_config"]])
        if ios_router["platform"] == "c7200":
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Midplane:", ios_router.get("midplane", "vxr")])
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["NPE:", ios_router.get("npe", "npe-400")])

        # fill out the Memories and disk section
        section_item = self._createSectionItem("Memories and disks")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["RAM:", "{} MiB".format(ios_router["ram"])])
        QtWidgets.QTreeWidgetItem(
            section_item, ["NVRAM:", "{} KiB".format(ios_router["nvram"])])
        if "iomem" in ios_router and ios_router["iomem"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["I/O memory:", "{}%".format(ios_router["iomem"])])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["PCMCIA disk0:", "{} MiB".format(ios_router["disk0"])])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["PCMCIA disk1:", "{} MiB".format(ios_router["disk1"])])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Auto delete:", "{}".format(ios_router["auto_delete_disks"])])

        # fill out the Adapters section
        section_item = self._createSectionItem("Adapters")
        for slot_id in range(0, 7):
            slot = "slot{}".format(slot_id)
            if slot in ios_router and ios_router[slot]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Slot {}:".format(slot_id), ios_router[slot]])
        if section_item.childCount() == 0:
            self.uiIOSRouterInfoTreeWidget.takeTopLevelItem(
                self.uiIOSRouterInfoTreeWidget.indexOfTopLevelItem(
                    section_item))

        # fill out the WICs section
        section_item = self._createSectionItem("WICs")
        for wic_id in range(0, 3):
            wic = "wic{}".format(wic_id)
            if wic in ios_router and ios_router[wic]:
                QtWidgets.QTreeWidgetItem(
                    section_item, ["WIC {}:".format(wic_id), ios_router[wic]])
        if section_item.childCount() == 0:
            self.uiIOSRouterInfoTreeWidget.takeTopLevelItem(
                self.uiIOSRouterInfoTreeWidget.indexOfTopLevelItem(
                    section_item))

        self.uiIOSRouterInfoTreeWidget.expandAll()
        self.uiIOSRouterInfoTreeWidget.resizeColumnToContents(0)
        self.uiIOSRouterInfoTreeWidget.resizeColumnToContents(1)
        self.uiIOSRoutersTreeWidget.setMaximumWidth(
            self.uiIOSRoutersTreeWidget.sizeHintForColumn(0) + 10)
    def _refreshInfo(self, qemu_vm):
        """
        Refreshes the content of the tree widget.
        """

        self.uiQemuVMInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Template name:", qemu_vm["name"]])
        QtWidgets.QTreeWidgetItem(
            section_item, ["Template ID:",
                           qemu_vm.get("template_id", "none")])
        if qemu_vm["linked_clone"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Default name format:", qemu_vm["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, [
                "Server:",
                ComputeManager.instance().getCompute(
                    qemu_vm["compute_id"]).name()
            ])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Console type:", qemu_vm["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, [
            "Auto start console:", "{}".format(qemu_vm["console_auto_start"])
        ])
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["CPUs:", str(qemu_vm["cpus"])])
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Memory:", "{} MB".format(qemu_vm["ram"])])
        QtWidgets.QTreeWidgetItem(
            section_item,
            ["Linked base VM:", "{}".format(qemu_vm["linked_clone"])])

        if qemu_vm["qemu_path"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["QEMU binary:",
                 os.path.basename(qemu_vm["qemu_path"])])

        # fill out the Hard disks section
        if qemu_vm["hda_disk_image"] or qemu_vm["hdb_disk_image"] or qemu_vm[
                "hdc_disk_image"] or qemu_vm["hdd_disk_image"]:
            section_item = self._createSectionItem("Hard disks")
            if qemu_vm["hda_disk_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk image (hda):", qemu_vm["hda_disk_image"]])
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk interface (hda):", qemu_vm["hda_disk_interface"]])
            if qemu_vm["hdb_disk_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk image (hdb):", qemu_vm["hdb_disk_image"]])
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk interface (hdb):", qemu_vm["hdb_disk_interface"]])
            if qemu_vm["hdc_disk_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk image (hdc):", qemu_vm["hdc_disk_image"]])
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk interface (hdc):", qemu_vm["hdc_disk_interface"]])
            if qemu_vm["hdd_disk_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk image (hdd):", qemu_vm["hdd_disk_image"]])
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Disk interface (hdd):", qemu_vm["hdd_disk_interface"]])
            if qemu_vm["cdrom_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item, ["CD/DVD image:", qemu_vm["cdrom_image"]])
            if qemu_vm["bios_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item, ["Bios image:", qemu_vm["bios_image"]])

        # fill out the Network section
        section_item = self._createSectionItem("Network")
        QtWidgets.QTreeWidgetItem(
            section_item, ["Adapters:", str(qemu_vm["adapters"])])
        QtWidgets.QTreeWidgetItem(
            section_item, ["Name format:", qemu_vm["port_name_format"]])
        if qemu_vm["port_segment_size"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["Segment size:",
                 str(qemu_vm["port_segment_size"])])
        if qemu_vm["first_port_name"]:
            QtWidgets.QTreeWidgetItem(
                section_item, ["First port name:", qemu_vm["first_port_name"]])
        QtWidgets.QTreeWidgetItem(section_item,
                                  ["Type:", qemu_vm["adapter_type"]])
        if qemu_vm["mac_address"]:
            QtWidgets.QTreeWidgetItem(
                section_item, ["Base MAC address:", qemu_vm["mac_address"]])

        # fill out the Linux boot section
        if qemu_vm["initrd"] or qemu_vm["kernel_image"] or qemu_vm[
                "kernel_command_line"]:
            section_item = self._createSectionItem("Linux boot")
            if qemu_vm["initrd"]:
                QtWidgets.QTreeWidgetItem(
                    section_item, ["Initial RAM disk:", qemu_vm["initrd"]])
            if qemu_vm["kernel_image"]:
                QtWidgets.QTreeWidgetItem(
                    section_item, ["Kernel image:", qemu_vm["kernel_image"]])
            if qemu_vm["kernel_command_line"]:
                QtWidgets.QTreeWidgetItem(
                    section_item,
                    ["Kernel command line:", qemu_vm["kernel_command_line"]])

        # performance section
        section_item = self._createSectionItem("Optimizations")
        if qemu_vm["cpu_throttling"]:
            QtWidgets.QTreeWidgetItem(
                section_item,
                ["CPU throttling:", "{}%".format(qemu_vm["cpu_throttling"])])
        else:
            QtWidgets.QTreeWidgetItem(section_item,
                                      ["CPU throttling:", "disabled"])
        QtWidgets.QTreeWidgetItem(
            section_item, ["Process priority:", qemu_vm["process_priority"]])

        # fill out the Additional options section
        section_item = self._createSectionItem("Additional options")
        if qemu_vm["options"]:
            QtWidgets.QTreeWidgetItem(section_item,
                                      ["Options:", qemu_vm["options"]])
        QtWidgets.QTreeWidgetItem(
            section_item, ["On close:", "{}".format(qemu_vm["on_close"])])

        self.uiQemuVMInfoTreeWidget.expandAll()
        self.uiQemuVMInfoTreeWidget.resizeColumnToContents(0)
        self.uiQemuVMInfoTreeWidget.resizeColumnToContents(1)
        self.uiQemuVMsTreeWidget.setMaximumWidth(
            self.uiQemuVMsTreeWidget.sizeHintForColumn(0) + 10)
Example #54
0
 def _event_received(self, result, *args, **kwargs):
     # Log only relevant events
     if result["action"] not in ("ping", "compute.updated"):
         log.debug("Event received: %s", result)
     if result["action"] == "node.created":
         node = Topology.instance().getNodeFromUuid(
             result["event"]["node_id"])
         if node is None:
             Topology.instance().createNode(result["event"])
     elif result["action"] == "node.updated":
         node = Topology.instance().getNodeFromUuid(
             result["event"]["node_id"])
         if node is not None:
             node.updateNodeCallback(result["event"])
     elif result["action"] == "node.deleted":
         node = Topology.instance().getNodeFromUuid(
             result["event"]["node_id"])
         if node is not None:
             node.delete(skip_controller=True)
     elif result["action"] == "link.created":
         link = Topology.instance().getLinkFromUuid(
             result["event"]["link_id"])
         if link is None:
             Topology.instance().createLink(result["event"])
     elif result["action"] == "link.updated":
         link = Topology.instance().getLinkFromUuid(
             result["event"]["link_id"])
         if link is not None:
             link.updateLinkCallback(result["event"])
     elif result["action"] == "link.deleted":
         link = Topology.instance().getLinkFromUuid(
             result["event"]["link_id"])
         if link is not None:
             link.deleteLink(skip_controller=True)
     elif result["action"] == "drawing.created":
         drawing = Topology.instance().getDrawingFromUuid(
             result["event"]["drawing_id"])
         if drawing is None:
             Topology.instance().createDrawing(result["event"])
     elif result["action"] == "drawing.updated":
         drawing = Topology.instance().getDrawingFromUuid(
             result["event"]["drawing_id"])
         if drawing is not None:
             drawing.updateDrawingCallback(result["event"])
     elif result["action"] == "drawing.deleted":
         drawing = Topology.instance().getDrawingFromUuid(
             result["event"]["drawing_id"])
         if drawing is not None:
             drawing.delete(skip_controller=True)
     elif result["action"] == "project.closed":
         Topology.instance().setProject(None)
     elif result["action"] == "project.updated":
         self._projectUpdatedCallback(result["event"])
     elif result["action"] == "snapshot.restored":
         Topology.instance().createLoadProject(
             {"project_id": result["event"]["project_id"]})
     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"] == "compute.created" or result[
             "action"] == "compute.updated":
         cm = ComputeManager.instance()
         cm.computeDataReceivedCallback(result["event"])
     elif result["action"] == "settings.updated":
         LocalConfig.instance().refreshConfigFromController()
         ApplianceManager.instance().refresh()
     elif result["action"] == "ping":
         pass
    def _refreshInfo(self, ios_router):
        """
        Refreshes the content of the tree widget.
        """

        self.uiIOSRouterInfoTreeWidget.clear()

        # fill out the General section
        section_item = self._createSectionItem("General")
        QtWidgets.QTreeWidgetItem(section_item, ["Template name:", ios_router["name"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Template ID:", ios_router.get("template_id", "none")])
        QtWidgets.QTreeWidgetItem(section_item, ["Default name format:", ios_router["default_name_format"]])
        try:
            QtWidgets.QTreeWidgetItem(section_item, ["Server:", ComputeManager.instance().getCompute(ios_router["compute_id"]).name()])
        except KeyError:
            pass
        QtWidgets.QTreeWidgetItem(section_item, ["Platform:", ios_router["platform"]])
        if ios_router.get("chassis"):
            QtWidgets.QTreeWidgetItem(section_item, ["Chassis:", ios_router.get("chassis")])
        QtWidgets.QTreeWidgetItem(section_item, ["Image:", ios_router["image"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Console type:", ios_router["console_type"]])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto start console:", "{}".format(ios_router["console_auto_start"])])
        if ios_router["idlepc"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Idle-PC:", ios_router["idlepc"]])
        if ios_router["startup_config"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Startup-config:", ios_router["startup_config"]])
        if ios_router["private_config"]:
            QtWidgets.QTreeWidgetItem(section_item, ["Private-config:", ios_router["private_config"]])
        if ios_router["platform"] == "c7200":
            QtWidgets.QTreeWidgetItem(section_item, ["Midplane:", ios_router.get("midplane", "vxr")])
            QtWidgets.QTreeWidgetItem(section_item, ["NPE:", ios_router.get("npe", "npe-400")])

        # fill out the Memories and disk section
        section_item = self._createSectionItem("Memories and disks")
        QtWidgets.QTreeWidgetItem(section_item, ["RAM:", "{} MiB".format(ios_router["ram"])])
        QtWidgets.QTreeWidgetItem(section_item, ["NVRAM:", "{} KiB".format(ios_router["nvram"])])
        if "iomem" in ios_router and ios_router["iomem"]:
            QtWidgets.QTreeWidgetItem(section_item, ["I/O memory:", "{}%".format(ios_router["iomem"])])
        QtWidgets.QTreeWidgetItem(section_item, ["PCMCIA disk0:", "{} MiB".format(ios_router["disk0"])])
        QtWidgets.QTreeWidgetItem(section_item, ["PCMCIA disk1:", "{} MiB".format(ios_router["disk1"])])
        QtWidgets.QTreeWidgetItem(section_item, ["Auto delete:", "{}".format(ios_router["auto_delete_disks"])])

        # fill out the Adapters section
        section_item = self._createSectionItem("Adapters")
        for slot_id in range(0, 7):
            slot = "slot{}".format(slot_id)
            if slot in ios_router and ios_router[slot]:
                QtWidgets.QTreeWidgetItem(section_item, ["Slot {}:".format(slot_id), ios_router[slot]])
        if section_item.childCount() == 0:
            self.uiIOSRouterInfoTreeWidget.takeTopLevelItem(self.uiIOSRouterInfoTreeWidget.indexOfTopLevelItem(section_item))

        # fill out the WICs section
        section_item = self._createSectionItem("WICs")
        for wic_id in range(0, 3):
            wic = "wic{}".format(wic_id)
            if wic in ios_router and ios_router[wic]:
                QtWidgets.QTreeWidgetItem(section_item, ["WIC {}:".format(wic_id), ios_router[wic]])
        if section_item.childCount() == 0:
            self.uiIOSRouterInfoTreeWidget.takeTopLevelItem(self.uiIOSRouterInfoTreeWidget.indexOfTopLevelItem(section_item))

        self.uiIOSRouterInfoTreeWidget.expandAll()
        self.uiIOSRouterInfoTreeWidget.resizeColumnToContents(0)
        self.uiIOSRouterInfoTreeWidget.resizeColumnToContents(1)
        self.uiIOSRoutersTreeWidget.setMaximumWidth(self.uiIOSRoutersTreeWidget.sizeHintForColumn(0) + 10)