Exemplo n.º 1
0
    def do_save(self, args):
        """save {/all | router1 [router2] ...}\nstores router configs in the network file"""

        if not globals.GApp.workspace.projectFile:
            print translate("Console", "You have to save your topology before using save")
        else:
            Dynagen_Console.do_save(self, args)
Exemplo n.º 2
0
    def do_push(self, args):
        """push {/all | router1 [router2] ...}\npushes router configs from the network file to the router's nvram"""

        if not globals.GApp.workspace.projectFile:
            print translate("Console", "You have to save your topology before using push")
        else:
            Dynagen_Console.do_push(self, args)
Exemplo n.º 3
0
    def do_push(self, args):
        """push {/all | router1 [router2] ...}\npushes router configs from the network file to the router's nvram"""

        if not globals.GApp.workspace.projectFile:
            print translate("Console", "You have to save your topology before using push")
        else:
            Dynagen_Console.do_push(self, args)
Exemplo n.º 4
0
    def do_clear(self, args):
        """clear [item]

Examples:
  clear mac <ethernet_switch_name> -- clear the mac address table of an ethernet switch
  clear topology -- clear the network topology"""

        if '?' in args or args.strip() == '':
            print self.do_clear.__doc__
            return
        try:
            command = args.split()[0].lower()
            params = args.split()[1:]

            if command == 'topology':
                globals.GApp.topology.clear()
                return

            if command == 'mac':
                try:
                    Dynagen_Console.do_clear(self, args)
                except Exception, e:
                    print e
        except ValueError:
            print translate("Console", "Incorrect number of paramaters or invalid parameters")
            return
        except KeyError:
            print translate("Console", "Unknown device: %s") % device
            return
        except lib.DynamipsError, e:
            print e
            return
Exemplo n.º 5
0
    def do_save(self, args):
        """save {/all | router1 [router2] ...}\nstores router configs in the network file"""

        if not globals.GApp.workspace.projectFile:
            print translate("Console", "You have to save your topology before using save")
        else:
            Dynagen_Console.do_save(self, args)
Exemplo n.º 6
0
    def do_qmonitor(self, args):
        """qmonitor <QEMU device> <command>\nCommunicate with qemu monitor mode.\nDisplay available commands: qmonitor <QEMU device> help"""

        if '?' in args or args.strip() == '':
            print self.do_qmonitor.__doc__
            return

        try:
            Dynagen_Console.do_qmonitor(self, args)
        except lib.DynamipsError, msg:
            QtGui.QMessageBox.critical(self, translate("Console", "Dynamips error"),  unicode(msg))
Exemplo n.º 7
0
    def do_resume(self, args):
        """resume  {/all | router1 [router2] ...}\nresume all or a specific router(s)"""

        try:
            Dynagen_Console.do_resume(self, args)
            devices = args.split(' ')
            for node in globals.GApp.topology.nodes.values():
                if isinstance(node, IOSRouter) and (node.hostname in devices or '/all' in devices):
                    node.startupInterfaces()
                    globals.GApp.mainWindow.treeWidget_TopologySummary.changeNodeStatus(node.hostname, 'running')
        except lib.DynamipsError, msg:
            QtGui.QMessageBox.critical(self, node.hostname + ': ' + translate("Console", "Dynamips error"),  unicode(msg))
Exemplo n.º 8
0
    def do_resume(self, args):
        """resume  {/all | device1 [device2] ...}\nresume all or a specific device(s)"""

        try:
            Dynagen_Console.do_resume(self, args)
            devices = args.split(' ')
            for node in globals.GApp.topology.nodes.values():
                if (isinstance(node, IOSRouter) or isinstance(node, AnyVBoxEmuDevice)) and (node.hostname in devices or '/all' in devices):
                    node.startupInterfaces()
                    globals.GApp.mainWindow.treeWidget_TopologySummary.changeNodeStatus(node.hostname, 'running')
        except lib.DynamipsError, msg:
            QtGui.QMessageBox.critical(self, translate("Console", "%s: Dynamips error") % node.hostname,  unicode(msg))
Exemplo n.º 9
0
    def do_suspend(self, args):
        """suspend  {/all | device1 [device2] ...}\nsuspend all or a specific device(s)"""

        try:
            Dynagen_Console.do_suspend(self, args)
            devices = args.split(' ')
            for node in globals.GApp.topology.nodes.values():
                if (isinstance(node, IOSRouter) or isinstance(node, AnyVBoxEmuDevice)) and (node.hostname in devices or '/all' in devices):
                    node.suspendInterfaces()
                    globals.GApp.mainWindow.treeWidget_TopologySummary.changeNodeStatus(node.hostname, 'suspended')
        except lib.DynamipsError, msg:
            QtGui.QMessageBox.critical(self, translate("Console", "%s: Dynamips error") % node.hostname,  unicode(msg))
Exemplo n.º 10
0
    def do_vboxexec(self, args):
        """vboxexec <VBOX device> <command>\nVirtualBox GuestControl execute sends a command to VirtualBox guest and prints it's output (experimental feature).
This requires VirtualBox Guest Additions to be installed inside the guest VM.

Example for Windows guest:
  vboxexec VBOX1 ping.exe 127.0.0.1
Example for Linux guest:
  vboxexec VBOX1 /bin/ping 127.0.0.1 -c4"""

        if '?' in args or args.strip() == '':
            print self.do_vboxexec.__doc__
            return
        if not globals.GApp.systconf['vbox'].enable_GuestControl:
            print "VirtualBox GuestControl execution is disabled in preferences"
            return

        try:
            node_name = args.split(' ')[0]
            for node in globals.GApp.topology.nodes.values():
                if isinstance(node, AnyVBoxEmuDevice) and node.hostname == node_name:
                    break
            Dynagen_Console.do_vboxexec(self, args)
        except lib.DynamipsError, msg:
            QtGui.QMessageBox.critical(self, translate("Console", "%s: Dynamips error") % node.hostname,  unicode(msg))
Exemplo n.º 11
0
    def do_ver(self, args):
        """Print hypervisors, dynagen, GNS3, libs versions and credits"""

        import sip
        import struct
        from __main__ import VERSION, GNS3_RUN_PATH

        bitness = struct.calcsize("P") * 8
        pythonver = str(sys.version_info[0]) + '.' +str(sys.version_info[1])+'.'+str(sys.version_info[2])
        if hasattr(sys, "frozen"):
            print 'GNS3 version is ' + VERSION + " (compiled)"
        else:
            print 'GNS3 version is ' + VERSION
        print 'Qt version is ' + QtCore.QT_VERSION_STR
        print 'PyQt version is ' + QtCore.PYQT_VERSION_STR
        print 'SIP version is ' + sip.SIP_VERSION_STR
        print "Python version is %s (%d-bit)" % (pythonver, bitness)
        print "Python default encoding is " + sys.getdefaultencoding()
        print unicode("\nGNS3 run path is %s\n" % GNS3_RUN_PATH)

        try:
            Dynagen_Console.do_ver(self, args)
        except Exception, e:
            print e
Exemplo n.º 12
0
    def do_import(self, args):
        """import {/all | router1 [router2] \"directory\"\nimport all or individual configuration files \nEnclose the directory or filename in quotes if there are spaces in the filespec."""

        Dynagen_Console.do_import(self, args)
Exemplo n.º 13
0
    def do_idlepc(self, args):
        """idlepc {get|set|show|save|idlemax|idlesleep|showdrift} device [value]
idlepc save device [default]

get, set, or show the online idlepc value(s)
Examples:
  idlepc get r1             -- Get a list of the possible idlepc value(s) for
                                router r1
  idlepc show r1            -- Show the previously determined idlepc values for
                               router r1
  idlepc set r1 0x12345     -- Manually set r1's idlepc to 0x12345
  idlepc save r1            -- Save r1's current idlepc value to the "router r1"
                               section of your network file
  idlepc save r1 default    -- Save r1's current idlepc value to the device
                               defaults section of your network file
                               (i.e. [[7200]])
  idlepc save r1 db         -- Save r1's current idlepc value to the idlepc
                               database
  idlepc idlemax r1 1500    -- Commands for advanced manipulation of idlepc
  idlepc idlesleep r1 30       settings
  idlepc showdrift r1
                               """

        if '?' in args or args.strip() == '':
            print Dynagen_Console.do_idlepc.__doc__
            return
        try:
            command = args.split()[0]
            command = command.lower()
            params = args.split()[1:]
            if len(params) < 1:
                print Dynagen_Console.do_idlepc.__doc__
                return

            if command == 'save':
                print translate("Console", "Sorry, not implemented in GNS3")
                return

            if command == 'get' or command == 'show':
                device = params[0]
                if command == 'get':
                    current_idlepc = self.dynagen.devices[device].idlepc
                    if len(params) < 2 or params[1] != 'force' and current_idlepc != None:
                        print unicode(translate("Console", "%s already has an idlepc value applied (%s).")) % (device, current_idlepc)
                        return

                    print translate("Console", "Please wait while gathering statistics...")
                    globals.GApp.processEvents(QtCore.QEventLoop.AllEvents | QtCore.QEventLoop.WaitForMoreEvents, 1000)
                    result = self.dynagen.devices[device].idleprop(lib.IDLEPROPGET)
                elif command == 'show':
                    result = self.dynagen.devices[device].idleprop(lib.IDLEPROPSHOW)
                result.pop()        # Remove the '100-OK' line
                idles = {}
                i = 1
                output = ''
                for line in result:
                    (value, count) = line.split()[1:]

                    # Flag potentially "best" idlepc values (between 50 and 60)
                    iCount = int(count[1:-1])
                    if 50 < iCount < 60:
                        flag = '*'
                    else:
                        flag = ' '

                    output += "%s %2i: %s %s\n" % (flag, i, value, count)
                    idles[i] = value
                    i += 1

                # Allow user to choose a value by number
                if len(idles) == 0:
                    print translate("Console", "No idlepc values found")
                else:
                    output = unicode(translate("Console", "Potentially better idlepc values marked with '*'\nEnter the number of the idlepc value to apply [1-%i] or ENTER for no change:\n")) % len(idles) + output
                    globals.GApp.processEvents(QtCore.QEventLoop.AllEvents | QtCore.QEventLoop.WaitForMoreEvents, 1000)
                    (selection,  ok) = QtGui.QInputDialog.getText(globals.GApp.mainWindow, 'idlepc',
                                          output, QtGui.QLineEdit.Normal)

                    if not ok:
                        print translate("Console", "No changes made")
                        return
                    selection = str(selection)
                    if selection == "":
                        print translate("Console", "No changes made")
                        return

                    try:
                        self.dynagen.devices[device].idleprop(lib.IDLEPROPSET, idles[int(selection)])
                        print unicode(translate("Console", "Applied idlepc value %s to %s\n")) % (idles[int(selection)], device)
                        for node in globals.GApp.topology.nodes.values():
                            if isinstance(node, IOSRouter) and node.hostname == device:
                                router = node.get_dynagen_device()
                                if globals.GApp.iosimages.has_key(router.dynamips.host + ':' + router.image):
                                    image = globals.GApp.iosimages[router.dynamips.host + ':' + router.image]
                                    image.idlepc =  idles[int(selection)]
                    except:
                        print translate("Console", "Can't apply idlepc value")
            else:
                Dynagen_Console.do_idlepc(self, args)

        except ValueError:
            print translate("Console", "Incorrect number of paramaters or invalid parameters")
            return
        except KeyError:
            print unicode(translate("Console", "Unknown device: %s")) % device
            return
        except lib.DynamipsError, e:
            print e
            return
Exemplo n.º 14
0
    def do_import(self, args):
        """import {/all | router1 [router2] \"directory\"\nimport all or individual configuration files \nEnclose the directory or filename in quotes if there are spaces in the filespec."""

        Dynagen_Console.do_import(self, args)
Exemplo n.º 15
0
    def do_idlepc(self, args):
        """idlepc {get|set|show|save|idlemax|idlesleep|showdrift} device [value]
idlepc save device [default]

get, set, or show the online idlepc value(s)
Examples:
  idlepc get r1             -- Get a list of the possible idlepc value(s) for
                                router r1
  idlepc show r1            -- Show the previously determined idlepc values for
                               router r1
  idlepc set r1 0x12345     -- Manually set r1's idlepc to 0x12345
  idlepc save r1            -- Save r1's current idlepc value to the "router r1"
                               section of your network file
  idlepc save r1 default    -- Save r1's current idlepc value to the device
                               defaults section of your network file
                               (i.e. [[7200]])
  idlepc save r1 db         -- Save r1's current idlepc value to the idlepc
                               database
  idlepc idlemax r1 1500    -- Commands for advanced manipulation of idlepc
  idlepc idlesleep r1 30       settings
  idlepc showdrift r1
                               """

        if '?' in args or args.strip() == '':
            print Dynagen_Console.do_idlepc.__doc__
            return
        try:
            command = args.split()[0]
            command = command.lower()
            params = args.split()[1:]
            if len(params) < 1:
                print Dynagen_Console.do_idlepc.__doc__
                return

            if command == 'save':
                print translate("Console", "Sorry, not implemented in GNS3")
                return

            if command == 'get' or command == 'show':
                device = params[0]
                if command == 'get':
                    current_idlepc = self.dynagen.devices[device].idlepc
                    if (len(params) < 2 or params[1] != 'force') and current_idlepc:
                        print translate("Console", "%s already has an idlepc value applied (%s).") % (device, current_idlepc)
                        return

                    print translate("Console", "Please wait while gathering statistics...")
                    globals.GApp.processEvents(QtCore.QEventLoop.AllEvents | QtCore.QEventLoop.WaitForMoreEvents, 1000)
                    result = self.dynagen.devices[device].idleprop(lib.IDLEPROPGET)
                elif command == 'show':
                    result = self.dynagen.devices[device].idleprop(lib.IDLEPROPSHOW)
                result.pop()        # Remove the '100-OK' line
                idles = {}
                i = 1
                output = ''
                for line in result:
                    (value, count) = line.split()[1:]

                    # Flag potentially "best" idlepc values (between 50 and 60)
                    iCount = int(count[1:-1])
                    if 50 < iCount < 60:
                        flag = '*'
                    else:
                        flag = ' '

                    output += "%s %2i: %s %s\n" % (flag, i, value, count)
                    idles[i] = value
                    i += 1

                # Allow user to choose a value by number
                if len(idles) == 0:
                    print translate("Console", "No idlepc values found")
                else:
                    output = translate("Console", "Potentially better idlepc values marked with '*'\nEnter the number of the idlepc value to apply [1-%i] or ENTER for no change:\n") % len(idles) + output
                    globals.GApp.processEvents(QtCore.QEventLoop.AllEvents | QtCore.QEventLoop.WaitForMoreEvents, 1000)
                    (selection,  ok) = QtGui.QInputDialog.getText(globals.GApp.mainWindow, 'idlepc',
                                          output, QtGui.QLineEdit.Normal)

                    if not ok:
                        print translate("Console", "No changes made")
                        return
                    selection = str(selection)
                    if selection == "":
                        print translate("Console", "No changes made")
                        return

                    try:
                        self.dynagen.devices[device].idleprop(lib.IDLEPROPSET, idles[int(selection)])
                        print translate("Console", "Applied idlepc value %s to %s\n") % (idles[int(selection)], device)
                        for node in globals.GApp.topology.nodes.values():
                            if isinstance(node, IOSRouter) and node.hostname == device:
                                router = node.get_dynagen_device()
                                if globals.GApp.iosimages.has_key(router.dynamips.host + ':' + router.image):
                                    image = globals.GApp.iosimages[router.dynamips.host + ':' + router.image]
                                    image.idlepc = idles[int(selection)]
                    except:
                        print translate("Console", "Can't apply idlepc value")
            else:
                Dynagen_Console.do_idlepc(self, args)

        except ValueError:
            print translate("Console", "Incorrect number of paramaters or invalid parameters")
            return
        except KeyError:
            print translate("Console", "Unknown device: %s") % device
            return
        except lib.DynamipsError, e:
            print e
            return
Exemplo n.º 16
0
    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)