def _uploadImages(self, qemu_vm):
        """
        Upload hard drive images to Cloud Files.
        """

        # Start uploading the image to cloud files
        self._upload_image_progress_dialog = QtGui.QProgressDialog(
            "Uploading image file(s)", "Cancel", 0, 0, parent=self)
        self._upload_image_progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
        self._upload_image_progress_dialog.setWindowTitle("Qemu image upload")
        self._upload_image_progress_dialog.show()

        try:
            uploads = []
            src = qemu_vm.get("hda_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("hdb_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            upload_thread = UploadFilesThread(self, MainWindow.instance().cloudSettings(), uploads)
            upload_thread.completed.connect(self._imageUploadComplete)
            upload_thread.start()
        except Exception as e:
            self._upload_image_progress_dialog.reject()
            import logging
            log = logging.getLogger(__name__)
            log.error(e)
            QtGui.QMessageBox.critical(self, "Qemu image upload", "Error uploading Qemu image: {}".format(e))
示例#2
0
    def _iouDeviceNewSlot(self):
        """
        Creates a new IOU device.
        """

        wizard = IOUDeviceWizard(self._iou_devices, parent=self)
        wizard.show()
        if wizard.exec_():

            new_device_settings = wizard.getSettings()
            key = "{server}:{name}".format(
                server=new_device_settings["server"],
                name=new_device_settings["name"])
            self._iou_devices[key] = IOU_DEVICE_SETTINGS.copy()
            self._iou_devices[key].update(new_device_settings)

            item = QtGui.QTreeWidgetItem(self.uiIOUDevicesTreeWidget)
            item.setText(0, self._iou_devices[key]["name"])
            item.setIcon(0,
                         QtGui.QIcon(self._iou_devices[key]["default_symbol"]))
            item.setData(0, QtCore.Qt.UserRole, key)
            self._items.append(item)
            self.uiIOUDevicesTreeWidget.setCurrentItem(item)

            if new_device_settings["server"] == 'cloud':
                import logging
                log = logging.getLogger(__name__)

                # Start uploading the image to cloud files
                self._upload_image_progress_dialog = QtGui.QProgressDialog(
                    "Uploading image file {}".format(
                        new_device_settings['image']),
                    "Cancel",
                    0,
                    0,
                    parent=self)
                self._upload_image_progress_dialog.setWindowModality(
                    QtCore.Qt.WindowModal)
                self._upload_image_progress_dialog.setWindowTitle(
                    "IOU image upload")
                self._upload_image_progress_dialog.show()
                try:
                    src = self._iou_devices[key]['path']
                    # Eg: images/IOU/i86.bin
                    dst = 'images/IOU/{}'.format(
                        self._iou_devices[key]['image'])
                    upload_thread = UploadFilesThread(
                        self,
                        MainWindow.instance().cloudSettings(), [(src, dst)])
                    upload_thread.completed.connect(self._imageUploadComplete)
                    upload_thread.start()
                except Exception as e:
                    self._upload_image_progress_dialog.reject()
                    log.error(e)
                    QtGui.QMessageBox.critical(
                        self, "IOU image upload",
                        "Error uploading IOU image: {}".format(e))
    def _iouDeviceNewSlot(self):
        """
        Creates a new IOU device.
        """

        wizard = IOUDeviceWizard(self._iou_devices, parent=self)
        wizard.show()
        if wizard.exec_():

            new_device_settings = wizard.getSettings()
            key = "{server}:{name}".format(server=new_device_settings["server"], name=new_device_settings["name"])
            self._iou_devices[key] = IOU_DEVICE_SETTINGS.copy()
            self._iou_devices[key].update(new_device_settings)

            item = QtGui.QTreeWidgetItem(self.uiIOUDevicesTreeWidget)
            item.setText(0, self._iou_devices[key]["name"])
            item.setIcon(0, QtGui.QIcon(self._iou_devices[key]["default_symbol"]))
            item.setData(0, QtCore.Qt.UserRole, key)
            self._items.append(item)
            self.uiIOUDevicesTreeWidget.setCurrentItem(item)

            if new_device_settings["server"] == 'cloud':
                import logging
                log = logging.getLogger(__name__)

                # Start uploading the image to cloud files
                self._upload_image_progress_dialog = QtGui.QProgressDialog(
                    "Uploading image file {}".format(new_device_settings['image']), "Cancel", 0, 0, parent=self)
                self._upload_image_progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
                self._upload_image_progress_dialog.setWindowTitle("IOU image upload")
                self._upload_image_progress_dialog.show()
                try:
                    src = self._iou_devices[key]['path']
                    # Eg: images/IOU/i86.bin
                    dst = 'images/IOU/{}'.format(self._iou_devices[key]['image'])
                    upload_thread = UploadFilesThread(self, MainWindow.instance().cloudSettings(), [(src, dst)])
                    upload_thread.completed.connect(self._imageUploadComplete)
                    upload_thread.start()
                except Exception as e:
                    self._upload_image_progress_dialog.reject()
                    log.error(e)
                    QtGui.QMessageBox.critical(self, "IOU image upload", "Error uploading IOU image: {}".format(e))
    def _uploadImages(self, qemu_vm):
        """
        Upload hard drive images to Cloud Files.
        """

        # Start uploading the image to cloud files
        self._upload_image_progress_dialog = QtGui.QProgressDialog(
            "Uploading image file(s)", "Cancel", 0, 0, parent=self)
        self._upload_image_progress_dialog.setWindowModality(
            QtCore.Qt.WindowModal)
        self._upload_image_progress_dialog.setWindowTitle("Qemu image upload")
        self._upload_image_progress_dialog.show()

        try:
            uploads = []
            src = qemu_vm.get("hda_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("hdb_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("hdc_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("hdd_disk_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("initrd", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            src = qemu_vm.get("kernel_image", None)
            if src:
                _, filename = ntpath.split(src)
                dst = "images/qemu/{}".format(filename)
                uploads.append((src, dst))

            upload_thread = UploadFilesThread(
                self,
                MainWindow.instance().cloudSettings(), uploads)
            upload_thread.completed.connect(self._imageUploadComplete)
            upload_thread.start()
        except Exception as e:
            self._upload_image_progress_dialog.reject()
            import logging
            log = logging.getLogger(__name__)
            log.error(e)
            QtGui.QMessageBox.critical(
                self, "Qemu image upload",
                "Error uploading Qemu image: {}".format(e))
    def _iosRouterNewSlot(self):
        """
        Creates a new IOS router.
        """

        wizard = IOSRouterWizard(self._ios_routers, parent=self)
        wizard.show()
        if wizard.exec_():

            ios_settings = wizard.getSettings()
            key = "{server}:{name}".format(server=ios_settings["server"], name=ios_settings["name"])

            self._ios_routers[key] = IOS_ROUTER_SETTINGS.copy()
            self._ios_routers[key].update(ios_settings)

            if ios_settings["server"] == 'cloud':
                import logging
                log = logging.getLogger(__name__)

                log.debug(ios_settings["image"])
                # Start uploading the image to cloud files

                self._upload_image_progress_dialog = QtGui.QProgressDialog("Uploading image file {}".format(ios_settings['image']), "Cancel", 0, 0, parent=self)
                self._upload_image_progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
                self._upload_image_progress_dialog.setWindowTitle("IOS image upload")
                self._upload_image_progress_dialog.show()
                try:
                    upload_thread = UploadFilesThread(
                        self,
                        cloud_settings=MainWindow.instance().cloudSettings(),
                        files_to_upload=[(
                            self._ios_routers[key]["image"],
                            'images/' + os.path.relpath(self._ios_routers[key]["image"],
                                                        self._main_window.settings().imagesDirPath())
                        )]
                    )
                    upload_thread.completed.connect(self._imageUploadComplete)
                    upload_thread.start()
                except Exception as e:
                    self._upload_image_progress_dialog.reject()
                    log.error(e)
                    QtGui.QMessageBox.critical(self, "IOS image upload", "Error uploading IOS image: {}".format(e))

            if ios_settings["platform"] == "c7200":
                self._ios_routers[key]["midplane"] = "vxr"
                self._ios_routers[key]["npe"] = "npe-400"
            else:
                self._ios_routers[key]["iomem"] = 5

            for slot_id in range(0, 7):
                slot = "slot{}".format(slot_id)
                if slot in ios_settings:
                    self._ios_routers[key][slot] = ios_settings[slot]

            for wic_id in range(0, 3):
                wic = "wic{}".format(wic_id)
                if wic in ios_settings:
                    self._ios_routers[key][wic] = ios_settings[wic]

            self._ios_routers[key].update(ios_settings)
            item = QtGui.QTreeWidgetItem(self.uiIOSRoutersTreeWidget)
            item.setText(0, self._ios_routers[key]["name"])
            item.setIcon(0, QtGui.QIcon(self._ios_routers[key]["default_symbol"]))
            item.setData(0, QtCore.Qt.UserRole, key)
            self._items.append(item)
            self.uiIOSRoutersTreeWidget.setCurrentItem(item)
    def _iosRouterNewSlot(self):
        """
        Creates a new IOS router.
        """

        wizard = IOSRouterWizard(self._ios_routers, parent=self)
        wizard.show()
        if wizard.exec_():

            ios_settings = wizard.getSettings()
            key = "{server}:{name}".format(server=ios_settings["server"], name=ios_settings["name"])

            # set the default base startup-config
            resource_name = "configs/ios_base_startup-config.txt"
            if hasattr(sys, "frozen") and os.path.isfile(resource_name):
                startup_config = os.path.normpath(resource_name)
            elif pkg_resources.resource_exists("gns3", resource_name):
                ios_base_config_path = pkg_resources.resource_filename("gns3", resource_name)
                startup_config = os.path.normpath(ios_base_config_path)

            # set the default base private-config
            resource_name = "configs/ios_base_private-config.txt"
            if hasattr(sys, "frozen") and os.path.isfile(resource_name):
                private_config = os.path.normpath(resource_name)
            elif pkg_resources.resource_exists("gns3", resource_name):
                ios_base_config_path = pkg_resources.resource_filename("gns3", resource_name)
                private_config = os.path.normpath(ios_base_config_path)

            ios_settings["startup_config"] = startup_config
            ios_settings["private_config"] = private_config

            self._ios_routers[key] = IOS_ROUTER_SETTINGS.copy()
            self._ios_routers[key].update(ios_settings)

            if ios_settings["server"] == 'cloud':
                import logging
                log = logging.getLogger(__name__)

                log.debug(ios_settings["image"])
                # Start uploading the image to cloud files

                self._upload_image_progress_dialog = QtGui.QProgressDialog("Uploading image file {}".format(ios_settings['image']), "Cancel", 0, 0, parent=self)
                self._upload_image_progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
                self._upload_image_progress_dialog.setWindowTitle("IOS image upload")
                self._upload_image_progress_dialog.show()
                try:
                    src = self._ios_routers[key]['path']
                    # Eg: images/IOS/c3745.img
                    dst = 'images/IOS/{}'.format(self._ios_routers[key]['image'])
                    upload_thread = UploadFilesThread(self, MainWindow.instance().cloudSettings(), [(src, dst)])
                    upload_thread.completed.connect(self._imageUploadComplete)
                    upload_thread.start()
                except Exception as e:
                    self._upload_image_progress_dialog.reject()
                    log.error(e)
                    QtGui.QMessageBox.critical(self, "IOS image upload", "Error uploading IOS image: {}".format(e))

            if ios_settings["platform"] == "c7200":
                self._ios_routers[key]["midplane"] = "vxr"
                self._ios_routers[key]["npe"] = "npe-400"
            else:
                self._ios_routers[key]["iomem"] = 5

            for slot_id in range(0, 7):
                slot = "slot{}".format(slot_id)
                if slot in ios_settings:
                    self._ios_routers[key][slot] = ios_settings[slot]

            for wic_id in range(0, 3):
                wic = "wic{}".format(wic_id)
                if wic in ios_settings:
                    self._ios_routers[key][wic] = ios_settings[wic]

            self._ios_routers[key].update(ios_settings)
            item = QtGui.QTreeWidgetItem(self.uiIOSRoutersTreeWidget)
            item.setText(0, self._ios_routers[key]["name"])
            item.setIcon(0, QtGui.QIcon(self._ios_routers[key]["default_symbol"]))
            item.setData(0, QtCore.Qt.UserRole, key)
            self._items.append(item)
            self.uiIOSRoutersTreeWidget.setCurrentItem(item)
    def _iosRouterNewSlot(self):
        """
        Creates a new IOS router.
        """

        wizard = IOSRouterWizard(self._ios_routers, parent=self)
        wizard.show()
        if wizard.exec_():

            ios_settings = wizard.getSettings()
            key = "{server}:{name}".format(server=ios_settings["server"],
                                           name=ios_settings["name"])

            self._ios_routers[key] = IOS_ROUTER_SETTINGS.copy()
            self._ios_routers[key].update(ios_settings)

            if ios_settings["server"] == 'cloud':
                import logging
                log = logging.getLogger(__name__)

                log.debug(ios_settings["image"])
                # Start uploading the image to cloud files

                self._upload_image_progress_dialog = QtGui.QProgressDialog(
                    "Uploading image file {}".format(ios_settings['image']),
                    "Cancel",
                    0,
                    0,
                    parent=self)
                self._upload_image_progress_dialog.setWindowModality(
                    QtCore.Qt.WindowModal)
                self._upload_image_progress_dialog.setWindowTitle(
                    "IOS image upload")
                self._upload_image_progress_dialog.show()
                try:
                    upload_thread = UploadFilesThread(
                        self,
                        cloud_settings=MainWindow.instance().cloudSettings(),
                        files_to_upload=[
                            (self._ios_routers[key]["image"],
                             'images/' + os.path.relpath(
                                 self._ios_routers[key]["image"],
                                 self._main_window.settings().imagesDirPath()))
                        ])
                    upload_thread.completed.connect(self._imageUploadComplete)
                    upload_thread.start()
                except Exception as e:
                    self._upload_image_progress_dialog.reject()
                    log.error(e)
                    QtGui.QMessageBox.critical(
                        self, "IOS image upload",
                        "Error uploading IOS image: {}".format(e))

            if ios_settings["platform"] == "c7200":
                self._ios_routers[key]["midplane"] = "vxr"
                self._ios_routers[key]["npe"] = "npe-400"
            else:
                self._ios_routers[key]["iomem"] = 5

            for slot_id in range(0, 7):
                slot = "slot{}".format(slot_id)
                if slot in ios_settings:
                    self._ios_routers[key][slot] = ios_settings[slot]

            for wic_id in range(0, 3):
                wic = "wic{}".format(wic_id)
                if wic in ios_settings:
                    self._ios_routers[key][wic] = ios_settings[wic]

            self._ios_routers[key].update(ios_settings)
            item = QtGui.QTreeWidgetItem(self.uiIOSRoutersTreeWidget)
            item.setText(0, self._ios_routers[key]["name"])
            item.setIcon(0,
                         QtGui.QIcon(self._ios_routers[key]["default_symbol"]))
            item.setData(0, QtCore.Qt.UserRole, key)
            self._items.append(item)
            self.uiIOSRoutersTreeWidget.setCurrentItem(item)