Ejemplo n.º 1
0
    def vtysh_multicmd(self, commands, pretty_output=True, daemon=None):
        """
        Runs the provided commands in the vty shell and return the result of
        execution.

        pretty_output: defines how the return value will be presented. When
        True it will show the command as they were executed in the vty shell,
        otherwise it will only show lines that failed.
        """
        # Prepare the temporary file that will hold the commands
        fname = topotest.get_file(commands)

        dparam = ""
        if daemon is not None:
            dparam += "-d {}".format(daemon)

        # Run the commands and delete the temporary file
        if pretty_output:
            vtysh_command = "vtysh {} < {}".format(dparam, fname)
        else:
            vtysh_command = "vtysh {} -f {}".format(dparam, fname)

        res = self.run(vtysh_command)
        os.unlink(fname)

        self.logger.info(
            '\nvtysh command => "{}"\nvtysh output <= "{}"'.format(
                vtysh_command, res))

        return res
Ejemplo n.º 2
0
    def vtysh_multicmd(self, commands, pretty_output=True, daemon=None):
        """
        Runs the provided commands in the vty shell and return the result of
        execution.

        pretty_output: defines how the return value will be presented. When
        True it will show the command as they were executed in the vty shell,
        otherwise it will only show lines that failed.
        """
        # Prepare the temporary file that will hold the commands
        fname = topotest.get_file(commands)

        dparam = ''
        if daemon is not None:
            dparam += '-d {}'.format(daemon)

        # Run the commands and delete the temporary file
        if pretty_output:
            vtysh_command = 'vtysh {} < {}'.format(dparam, fname)
        else:
            vtysh_command = 'vtysh {} -f {}'.format(dparam, fname)

        res = self.run(vtysh_command)
        os.unlink(fname)

        self.logger.info('\nvtysh command => "{}"\nvtysh output <= "{}"'.format(
            vtysh_command, res))

        return res
Ejemplo n.º 3
0
    def vtysh_multicmd(self, commands, pretty_output=True):
        """
        Runs the provided commands in the vty shell and return the result of
        execution.

        pretty_output: defines how the return value will be presented. When
        True it will show the command as they were executed in the vty shell,
        otherwise it will only show lines that failed.
        """
        # Prepare the temporary file that will hold the commands
        fname = topotest.get_file(commands)

        # Run the commands and delete the temporary file
        if pretty_output:
            vtysh_command = 'vtysh < {}'.format(fname)
        else:
            vtysh_command = 'vtysh -f {}'.format(fname)

        res = self.run(vtysh_command)
        os.unlink(fname)

        return res
Ejemplo n.º 4
0
    def vtysh_multicmd(self, commands, pretty_output=True, daemon=None):
        """
        Runs the provided commands in the vty shell and return the result of
        execution.

        pretty_output: defines how the return value will be presented. When
        True it will show the command as they were executed in the vty shell,
        otherwise it will only show lines that failed.
        """
        # Prepare the temporary file that will hold the commands
        fname = topotest.get_file(commands)

        dparam = ""
        if daemon is not None:
            dparam += "-d {}".format(daemon)

        # Run the commands and delete the temporary file
        if pretty_output:
            vtysh_command = "vtysh {} < {}".format(dparam, fname)
        else:
            vtysh_command = "vtysh {} -f {}".format(dparam, fname)

        dbgcmds = commands if is_string(commands) else "\n".join(commands)
        dbgcmds = "\t" + dbgcmds.replace("\n", "\n\t")
        self.logger.info("vtysh command => FILE:\n{}".format(dbgcmds))

        res = self.run(vtysh_command)
        os.unlink(fname)

        dbgres = res.strip()
        if dbgres:
            if "\n" in dbgres:
                dbgres = dbgres.replace("\n", "\n\t")
                self.logger.info("vtysh result:\n\t{}".format(dbgres))
            else:
                self.logger.info('vtysh result: "{}"'.format(dbgres))
        return res