Example #1
0
File: ssh_jobs.py Project: idmf/rho
 def run(self):
     while not self.quitting:
         try:
             # grab a "ssh_job" off the q
             ssh_job = self.ssh_queue.get()
             self.get_transport(ssh_job)
             self.out_queue.put(ssh_job)
             self.ssh_queue.task_done()
         except Exception, e:
             log.error("Exception: %s" % e)
             log.error(traceback.print_tb(sys.exc_info()[2]))
             self.ssh_queue.task_done()
Example #2
0
File: ssh_jobs.py Project: idmf/rho
    def run(self):
        while not self.quitting:
            ssh_job = self.out_queue.get()
            if ssh_job == "quit":
                self.quit()

            try:
                self.report.add(ssh_job)
            except Exception, e:
                log.error("Exception: %s" % e)
                log.error(traceback.print_tb(sys.exc_info()[2]))
                self.quit()

            self.out_queue.task_done()
Example #3
0
    def get_transport(self, ssh_job):
        if ssh_job.ip is "":
            return None

        try:
            self.connect(ssh_job)
            if not self.ssh:
                return

            # there was a connection/auth failure
            if ssh_job.error:
                return
            self.run_cmds(ssh_job)
            self.ssh.close()

        except Exception as e:
            log.error("Exception on %s: %s" % (ssh_job.ip, e))
            log.error(sys.exc_info())
            log.error(traceback.print_tb(sys.exc_info()[2]))
            ssh_job.connection_result = False
            ssh_job.command_output = e
Example #4
0
File: ssh_jobs.py Project: idmf/rho
    def connect(self, ssh_job):
        # do the actual paramiko ssh connection

        # Copy the list of ports, we'll modify it as we go:
        ports_to_try = list(ssh_job.ports)

        found_port = None # we'll set this once we identify a port that works
        found_auth = False

        while True:
            if found_auth:
                break

            if found_port != None:
                log.warn("Found ssh on %s:%s, but no auths worked." %
                        (ssh_job.ip, found_port))
                break

            if len(ports_to_try) == 0:
                log.debug("Could not find/connect to ssh on: %s" % ssh_job.ip)
                err = _("unable to connect")
                ssh_job.error = err
                break

            port = ports_to_try.pop(0)

            for auth in ssh_job.auths:
                ssh_job.error = None

                debug_str = "%s:%s/%s" % (ssh_job.ip, port, auth.name)
                # this checks the case of a passphrase we can't decrypt
                try:
                    pkey = get_pkey(auth)
                except paramiko.SSHException, e:
                    # paramiko throws an SSHException for pretty much everything... ;-<
                    log.error("ssh key error for %s: %s" % (debug_str, str(e)))
                    ssh_job.error = str(e)
                    continue

                self.ssh = paramiko.SSHClient()
                self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

                try:
                    log.info("trying: %s" % debug_str)

                    self.show_connect(ssh_job, port, auth)
                    self.ssh.connect(ssh_job.ip, port=int(port), 
                                     username=auth.username,
                                     password=auth.password,
                                     pkey=pkey,
                                     allow_agent=ssh_job.allow_agent,
                                     look_for_keys=ssh_job.look_for_keys,
                                     timeout=ssh_job.timeout)
                    ssh_job.port = port
                    ssh_job.auth = auth
                    found_port = port
                    found_auth = True
                    log.info("success: %s" % debug_str)
                    break

                # Implies we've found an SSH server listening:
                except paramiko.AuthenticationException, e:
                    # Because we stop checking ports once we find one where ssh
                    # is listening, we can report the error message here and it
                    # will end up in the final report correctly:
                    err = _("login failed")
                    log.error(err)
                    ssh_job.error = err
                    found_port = port
                    continue

                # No route to host:
                except socket.error, e:
                    log.warn("No route to host, skipping port: %s" % debug_str)
                    ssh_job.error = str(e)
                    break