def main():
    # Set login credentials and server details
    connect_timeout = 30
    devices = ['server1', 'server2', 'server3']
    username = '******'
    password = '******'

    try:
        # Create a multi-SSH runner.  Processes sets the number of processes
        # that can run at the same time.
        runner = MultiSSHRunner(processes=len(devices))

        # We must add jobs one at a time (allows for more flexibility)
        for device in devices:
            runner.add_ssh_job(
                hostname=device, connect_timeout=connect_timeout,
                username=username, password=password,
                interaction=server_interaction)

        # Run the interactions, returned is a list of outputs (outputs are in
        # whatever format returned by the interaction function)
        outputs = runner.run()

        # Go through and print the command outputs
        for device, output in zip(devices, outputs):
            print '-- Device:', device, '--\n'
            output1, output2 = output
            print '/etc/*release output:'
            print output1
            print 'uname -a output:'
            print output2
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()
Example #2
0
    def run_cmd(self, cmd):

        if self.multissh_runner is None:
            self.multissh_runner = MultiSSHRunner(processes=len(self.group))
        for server in self.group:
            self.multissh_runner.add_ssh_job(server['server'].hostname,
                                             connect_timeout=10, username=server['user'].user,
                                             password=server['credential'].credential,
                                             interaction=cmd.run_cmd)
Example #3
0
def main():

    # Set login credentials and the command to run
    connect_timeout = 30
    devices = ['server1', 'server2', 'server3']
    username = '******'
    password = '******'
    command = 'uname -a'

    try:
        # Create a multi-SSH runner.  Processes sets the number of processes
        # that can run at the same time.
        runner = MultiSSHRunner(processes=2)

        # We must add jobs one at a time (allows for more flexibility)
        for device in devices:
            runner.add_ssh_job(hostname=device,
                               connect_timeout=connect_timeout,
                               username=username,
                               password=password,
                               command=command)

        # Run the commands, returned is a list of tuples as follows:
        # (return_code, stdout, stderr)
        outputs = runner.run()

        # Process the output
        for device, output in zip(devices, outputs):
            if output:
                return_code, stdout, stderr = output
            # Check the return code was 0 (successful) and something was
            # returned in stdout
            if output and stdout and return_code == 0:
                print device, stdout,
            # If output has been set and we arrive here, then the return code
            # was non-zero or stdout was empty
            elif output:
                print device, 'Command did not run successfully'
            # Otherwise, we didn't connect successfully
            else:
                print device, 'Couldn\'t connect to this server'
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()
Example #4
0
def main():
    # Set login credentials and the command to run
    connect_timeout = 30
    devices = ['server1', 'server2', 'server3']
    username = '******'
    password = '******'
    command = 'uname -a'

    try:
        # Create a multi-SSH runner.  Processes sets the number of processes
        # that can run at the same time.
        runner = MultiSSHRunner(processes=2)

        # We must add jobs one at a time (allows for more flexibility)
        for device in devices:
            runner.add_ssh_job(
                hostname=device, connect_timeout=connect_timeout,
                username=username, password=password, command=command)

        # Run the commands, returned is a list of tuples as follows:
        # (return_code, stdout, stderr)
        outputs = runner.run()

        # Process the output
        for device, output in zip(devices, outputs):
            if output:
                return_code, stdout, stderr = output

            # Check the return code was 0 (successful) and something was
            # returned in stdout
            if output and stdout and return_code == 0:
                print device, stdout,
            # If output has been set and we arrive here, then the return code
            # was non-zero or stdout was empty
            elif output:
                print device, 'Command did not run successfully'
            # Otherwise, we didn't connect successfully
            else:
                print device, "Couldn't connect to this server"
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()
Example #5
0
class ThreadingServerGroup(SerialServerGroup):
    """
    Under construction.
    """

    def __init__(self, *args, **kwargs):
        """__init__
        Under Construction.
        """
        super(ThreadingServerGroup, self).__init__(*args, **kwargs)

        self.multissh_runner = None
        self.multissh_len = None

    def run_cmd(self, cmd):

        if self.multissh_runner is None:
            self.multissh_runner = MultiSSHRunner(processes=len(self.group))
        for server in self.group:
            self.multissh_runner.add_ssh_job(server['server'].hostname,
                                             connect_timeout=10, username=server['user'].user,
                                             password=server['credential'].credential,
                                             interaction=cmd.run_cmd)
def main():
    # Set login credentials and the command to run
    connect_timeout = 30
    devices = ['server1', 'server2', 'server3']
    username = '******'
    password = '******'

    try:
        # Create a multi-SSH runner.  Processes sets the number of processes
        # that can run at the same time.
        runner = MultiSSHRunner(processes=len(devices))

        # We must add jobs one at a time (allows for more flexibility)
        for device in devices:
            runner.add_ssh_job(
                hostname=device, connect_timeout=connect_timeout,
                username=username, password=password, interaction=tail_authlog)

        # Run the tail interactions
        runner.run()
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()
Example #7
0
def main():
    # Set login credentials and server details
    connect_timeout = 30
    devices = ['server1', 'server2', 'server3']
    username = '******'
    password = '******'

    try:
        # Create a multi-SSH runner.  Processes sets the number of processes
        # that can run at the same time.
        runner = MultiSSHRunner(processes=len(devices))

        # We must add jobs one at a time (allows for more flexibility)
        for device in devices:
            runner.add_ssh_job(hostname=device,
                               connect_timeout=connect_timeout,
                               username=username,
                               password=password,
                               interaction=server_interaction)

        # Run the interactions, returned is a list of outputs (outputs are in
        # whatever format returned by the interaction function)
        outputs = runner.run()

        # Go through and print the command outputs
        for device, output in zip(devices, outputs):
            print '-- Device:', device, '--\n'
            output1, output2 = output
            print '/etc/*release output:'
            print output1
            print 'uname -a output:'
            print output2
    except KeyboardInterrupt:
        pass
    except:
        traceback.print_exc()