def do_show(self, args): """show mac <ethernet_switch_name> \tshow the mac address table of an ethernet switch show device \tshow detail information about every device in current lab show device <device_name> \tshow detail information about a device show start \tshow startup lab configuration show run \tshow running configuration of current lab show run <device_name> \tshow running configuration of a router show hypervisors \tshow allocated memory for hypervisors by Hypervisor Manager show ports \tshow all TCP ports allocated by GNS3 show project_info \tshow the current project path """ if '?' in args or args.strip() == '': print self.do_show.__doc__ return command = args.split()[0].lower() if command == 'hypervisors' and globals.GApp.HypervisorManager: globals.GApp.HypervisorManager.showHypervisors() return elif command == 'ports': track = tracker.portTracker() track.showTcpPortAllocation() return elif command == 'project_info': print print "Project File:\t\t\t" + globals.GApp.mainWindow.projectFile if globals.GApp.workspace.projectWorkdir: print "Project Working directory:\t\t" + globals.GApp.workspace.projectWorkdir print "Project Config directory:\t\t" + globals.GApp.workspace.projectConfigs print qemu_flash_drives_directory = os.path.dirname(globals.GApp.workspace.projectFile) + os.sep + 'qemu-flash-drives' if os.access(qemu_flash_drives_directory, os.F_OK): workdir = qemu_flash_drives_directory elif globals.GApp.systconf['qemu'].qemuwrapper_workdir: workdir = globals.GApp.systconf['qemu'].qemuwrapper_workdir else: realpath = os.path.realpath(self.dynagen.global_filename) workdir = os.path.dirname(realpath) print "Qemuwrapper working directory:\t" + workdir if globals.GApp.systconf['vbox'].enable_VBoxManager: if globals.GApp.workspace.projectWorkdir: workdir = globals.GApp.workspace.projectWorkdir elif globals.GApp.systconf['vbox'].vboxwrapper_workdir: workdir = globals.GApp.systconf['vbox'].vboxwrapper_workdir else: realpath = os.path.realpath(self.dynagen.global_filename) workdir = os.path.dirname(realpath) print "Vboxwrapper working directory:\t" + workdir else: print "VBoxManager is disabled" print "Dynamips working directory:\t\t" + globals.GApp.systconf['dynamips'].workdir else: Dynagen_Console.do_show(self, args)
def __testDynamips(self): if len(globals.GApp.topology.nodes): reply = QtGui.QMessageBox.question( self, translate("UiConfig_PreferencesDynamips", "Message"), translate( "UiConfig_PreferencesDynamips", "This action is going to delete your current topology, would you like to continue?" ), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.No: return self.saveConf() if globals.GApp.systconf['dynamips'].path: if os.path.exists(globals.GApp.systconf['dynamips'].path) == False: self.labelDynamipsStatus.setText( '<font color="red">' + translate("UiConfig_PreferencesDynamips", "Dynamips path doesn't exist") + '</font>') return if not sys.platform.startswith('win') and not os.access( globals.GApp.systconf['dynamips'].path, os.X_OK): self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Dynamips path isn't marked as executable.<br>Please fix using the following command:<br>chmod +x path_to_dynamips" ) + '</font>') return try: p = sub.Popen([globals.GApp.systconf['dynamips'].path, '--help'], stdout=sub.PIPE) dynamips_stdout = p.communicate() except OSError: self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Failed to start Dynamips") + '</font>') return try: if not dynamips_stdout[0].splitlines()[0].__contains__('version'): self.labelDynamipsStatus.setText( '<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to determine version of Dynamips.") + '</font>') return version_raw = dynamips_stdout[0].splitlines()[0].split( 'version')[1].lstrip() version_1st = int(version_raw.split('.')[0]) version_2nd = int(version_raw.split('.')[1]) version_3rd = int(version_raw.split('.')[2].split('-')[0]) dynamips_ver = str(version_1st) + '.' + str( version_2nd) + '.' + str( version_3rd) + '-' + version_raw.split('.')[2].split( '-')[1] globals.GApp.systconf['dynamips'].detected_version = unicode( dynamips_ver) ConfDB().sync() except: self.labelDynamipsStatus.setText( '<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to determine version of Dynamips.") + '</font>') return if version_2nd < 2 or version_3rd < 8: self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Found Dynamips %s, which is not supported. Use 0.2.8+ instead." ) % dynamips_ver + '</font>') return if not testIfWritableDir(globals.GApp.systconf['dynamips'].workdir): self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Dynamips working directory does not exist or is not writable") + '</font>') return track = tracker.portTracker() # Check if any of the first 10 ports are free to use by hypervisors not_free_ports = track.getNotAvailableTcpPortRange( globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.hypervisor_baseport, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base port value<br>or close these ports" % str(not_free_ports)) + '</font>') return # Check if any of the first 10 ports are free to use for dynamips console ports not_free_ports = track.getNotAvailableTcpPortRange( globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.GApp.systconf['dynamips'].baseConsole, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base console value<br>or close these ports" % str(not_free_ports)) + '</font>') return # Check if any of the first 10 ports are free to use for dynamips aux ports not_free_ports = track.getNotAvailableTcpPortRange( globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.GApp.systconf['dynamips'].baseAUX, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate( "UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base AUX value<br>or close these ports" % str(not_free_ports)) + '</font>') return if globals.GApp.systconf['dynamips'].path: globals.GApp.workspace.clear() globals.GApp.HypervisorManager = HypervisorManager() if globals.GApp.HypervisorManager.preloadDynamips(): self.labelDynamipsStatus.setText( '<font color="green">' + translate("UiConfig_PreferencesDynamips", "Dynamips %s successfully started") % dynamips_ver + '</font>') else: self.labelDynamipsStatus.setText( '<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to start Dynamips") + '</font>')
def __testDynamips(self): if len(globals.GApp.topology.nodes): reply = QtGui.QMessageBox.question(self, translate("UiConfig_PreferencesDynamips", "Message"), translate("UiConfig_PreferencesDynamips", "This action is going to delete your current topology, would you like to continue?"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.No: return self.saveConf() if globals.GApp.systconf['dynamips'].path: if os.path.exists(globals.GApp.systconf['dynamips'].path) == False: self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Dynamips path doesn't exist") + '</font>') return if not sys.platform.startswith('win') and not os.access(globals.GApp.systconf['dynamips'].path, os.X_OK): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Dynamips path isn't marked as executable.<br>Please fix using the following command:<br>chmod +x path_to_dynamips") + '</font>') return try: p = sub.Popen([globals.GApp.systconf['dynamips'].path, '--help'], stdout=sub.PIPE) dynamips_stdout = p.communicate() except OSError: self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to start Dynamips") + '</font>') return try: if not dynamips_stdout[0].splitlines()[0].__contains__('version'): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to determine version of Dynamips.") + '</font>') return version_raw = dynamips_stdout[0].splitlines()[0].split('version')[1].lstrip() version_1st = int(version_raw.split('.')[0]) version_2nd = int(version_raw.split('.')[1]) version_3rd = int(version_raw.split('.')[2].split('-')[0]) dynamips_ver = str(version_1st)+'.'+str(version_2nd)+'.'+str(version_3rd)+'-'+version_raw.split('.')[2].split('-')[1] globals.GApp.systconf['dynamips'].detected_version = unicode(dynamips_ver) ConfDB().sync() except: self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to determine version of Dynamips.") + '</font>') return if version_2nd < 2 or version_3rd < 8: self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Found Dynamips %s, which is not supported. Use 0.2.8+ instead.") % dynamips_ver + '</font>') return if not testIfWritableDir(globals.GApp.systconf['dynamips'].workdir): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Dynamips working directory does not exist or is not writable") + '</font>') return track = tracker.portTracker() # Check if any of the first 10 ports are free to use by hypervisors not_free_ports = track.getNotAvailableTcpPortRange(globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.hypervisor_baseport, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base port value<br>or close these ports" % str(not_free_ports)) + '</font>') return # Check if any of the first 10 ports are free to use for dynamips console ports not_free_ports = track.getNotAvailableTcpPortRange(globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.GApp.systconf['dynamips'].baseConsole, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base console value<br>or close these ports" % str(not_free_ports)) + '</font>') return # Check if any of the first 10 ports are free to use for dynamips aux ports not_free_ports = track.getNotAvailableTcpPortRange(globals.GApp.systconf['dynamips'].HypervisorManager_binding, globals.GApp.systconf['dynamips'].baseAUX, 10) if len(not_free_ports): self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Ports already in use %s<br>Please choose another base AUX value<br>or close these ports" % str(not_free_ports)) + '</font>') return if globals.GApp.systconf['dynamips'].path: globals.GApp.workspace.clear() globals.GApp.HypervisorManager = HypervisorManager() if globals.GApp.HypervisorManager.preloadDynamips(): self.labelDynamipsStatus.setText('<font color="green">' + translate("UiConfig_PreferencesDynamips", "Dynamips %s successfully started") % dynamips_ver + '</font>') else: self.labelDynamipsStatus.setText('<font color="red">' + translate("UiConfig_PreferencesDynamips", "Failed to start Dynamips") + '</font>')