IOUVM converter

This commit is contained in:
Julien Duponchelle
2015-07-23 15:44:07 +02:00
parent 97a7496854
commit d7b43ef5cf
5 changed files with 55 additions and 1 deletions

View File

@@ -66,6 +66,8 @@ class IOUVMConverterWizard(QtWidgets.QWizard, Ui_IOUVMConverterWizard):
return self._checkIOURC()
elif self.currentPage() == self.uiWizardUpdateConfiguration:
return self._updateConfig()
elif self.currentPage() == self.uiWizardPagePatchTopologies:
return self._patchTopologies()
return True
def _checkIOURC(self):
@@ -86,6 +88,9 @@ class IOUVMConverterWizard(QtWidgets.QWizard, Ui_IOUVMConverterWizard):
return True
def _updateConfig(self):
"""
Update the config file to use the GNS3 VM instead of IOU VM
"""
config = self._loadConfig()
if "devices" in config["IOU"]:
for device in config["IOU"]["devices"]:
@@ -95,6 +100,39 @@ class IOUVMConverterWizard(QtWidgets.QWizard, Ui_IOUVMConverterWizard):
self._writeConfig(config)
return True
def _patchTopologies(self):
"""
Patch topologies to use the GNS3 VM
"""
path = self.uiLineEditTopologiesPath.text()
try:
for (dirpath, dirnames, filenames) in os.walk(path):
for filename in filenames:
if filename.endswith(".gns3"):
self._patchTopology(os.path.join(dirpath, filename))
except OSError as e:
QtWidgets.QMessageBox.critical(self, "Error", "Can't open {}: {}".format(path, str(e)))
return False
return True
def _patchTopology(self, path):
"""
Path a specific topology
"""
try:
shutil.copy(path, "{}.{}.backup".format(path, datetime.now().isoformat()))
with open(path) as f:
topo = json.load(f)
if "topology" in topo and "servers" in topo["topology"]:
for server in topo["topology"]["servers"]:
if server["local"] == False:
server["vm"] = True
with open(path, 'w+') as f:
topo = json.dump(topo, f)
except OSError as e:
QtWidgets.QMessageBox.critical(self, "Error", "Can't open {}: {}".format(path, str(e)))
def _loadConfig(self):
with open(self._configurationFile()) as f:
return json.load(f)

View File

@@ -27,6 +27,7 @@ import shutil
import json
import glob
import logging
import subprocess
from .local_config import LocalConfig
from .modules import MODULES
@@ -246,6 +247,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.uiLabInstructionsAction.triggered.connect(self._labInstructionsActionSlot)
self.uiAboutQtAction.triggered.connect(self._aboutQtActionSlot)
self.uiAboutAction.triggered.connect(self._aboutActionSlot)
self.uiIOUVMConverterAction.triggered.connect(self._IOUVMConverterActionSlot)
# browsers tool bar connections
self.uiBrowseRoutersAction.triggered.connect(self._browseRoutersActionSlot)
@@ -374,6 +376,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
else:
self._createTemporaryProject()
def _IOUVMConverterActionSlot(self):
subprocess.Popen([shutil.which("gns3-iouvm-converter")])
def openProjectActionSlot(self):
"""
Slot called to open a project.

View File

@@ -168,6 +168,7 @@ background-none;
<string>&amp;Tools</string>
</property>
<addaction name="uiVPCSAction"/>
<addaction name="uiIOUVMConverterAction"/>
</widget>
<addaction name="uiFileMenu"/>
<addaction name="uiEditMenu"/>
@@ -1203,6 +1204,11 @@ background-none;
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="uiIOUVMConverterAction">
<property name="text">
<string>IOU VM Converter</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@@ -366,8 +366,8 @@ class Ui_MainWindow(object):
self.uiAddLinkAction.setCheckable(True)
icon29 = QtGui.QIcon()
icon29.addPixmap(QtGui.QPixmap(":/icons/connection-new-hover.svg"), QtGui.QIcon.Active, QtGui.QIcon.Off)
icon29.addPixmap(QtGui.QPixmap(":/icons/connection-new.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
icon29.addPixmap(QtGui.QPixmap(":/icons/cancel-connection.svg"), QtGui.QIcon.Active, QtGui.QIcon.On)
icon29.addPixmap(QtGui.QPixmap(":/icons/connection-new.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
icon29.addPixmap(QtGui.QPixmap(":/icons/cancel-connection.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On)
self.uiAddLinkAction.setIcon(icon29)
self.uiAddLinkAction.setObjectName("uiAddLinkAction")
@@ -408,6 +408,8 @@ class Ui_MainWindow(object):
self.uiSetupWizard = QtWidgets.QAction(MainWindow)
self.uiSetupWizard.setMenuRole(QtWidgets.QAction.NoRole)
self.uiSetupWizard.setObjectName("uiSetupWizard")
self.uiIOUVMConverterAction = QtWidgets.QAction(MainWindow)
self.uiIOUVMConverterAction.setObjectName("uiIOUVMConverterAction")
self.uiEditMenu.addAction(self.uiSelectAllAction)
self.uiEditMenu.addAction(self.uiSelectNoneAction)
self.uiEditMenu.addSeparator()
@@ -458,6 +460,7 @@ class Ui_MainWindow(object):
self.uiAnnotateMenu.addAction(self.uiDrawRectangleAction)
self.uiAnnotateMenu.addAction(self.uiDrawEllipseAction)
self.uiToolsMenu.addAction(self.uiVPCSAction)
self.uiToolsMenu.addAction(self.uiIOUVMConverterAction)
self.uiMenuBar.addAction(self.uiFileMenu.menuAction())
self.uiMenuBar.addAction(self.uiEditMenu.menuAction())
self.uiMenuBar.addAction(self.uiViewMenu.menuAction())
@@ -663,6 +666,7 @@ class Ui_MainWindow(object):
self.uiDownloadRemoteProject.setText(_translate("MainWindow", "Download remote project"))
self.uiQemuImgWizardAction.setText(_translate("MainWindow", "Qemu image wizard"))
self.uiSetupWizard.setText(_translate("MainWindow", "&Setup Wizard"))
self.uiIOUVMConverterAction.setText(_translate("MainWindow", "IOU VM Converter"))
from ..console_view import ConsoleView
from ..graphics_view import GraphicsView

View File

@@ -58,6 +58,7 @@ setup(
entry_points={
"gui_scripts": [
"gns3 = gns3.main:main",
"gns3-iouvm-converter = gns3.iouvm_converter:main"
]
},
packages=find_packages(".", exclude=["docs", "tests"]),