Пример #1
0
 def _run_ssh(self, command, check_exit_code=True, attempts=1):
     if not self.sshpool:
         self.sshpool = utils.SSHPool(FLAGS.san_ip,
                                      FLAGS.san_ssh_port,
                                      FLAGS.ssh_conn_timeout,
                                      FLAGS.san_login,
                                      password=FLAGS.san_password,
                                      privatekey=FLAGS.san_private_key,
                                      min_size=FLAGS.ssh_min_pool_conn,
                                      max_size=FLAGS.ssh_max_pool_conn)
     try:
         total_attempts = attempts
         with self.sshpool.item() as ssh:
             while attempts > 0:
                 attempts -= 1
                 try:
                     return utils.ssh_execute(ssh, command,
                                            check_exit_code=check_exit_code)
                 except Exception as e:
                     LOG.error(e)
                     greenthread.sleep(random.randint(20, 500) / 100.0)
             raise paramiko.SSHException(_("SSH Command failed after '%r' "
                                           "attempts: '%s'"
                                           % (total_attempts, command)))
     except Exception as e:
         LOG.error(_("Error running ssh command: %s" % command))
         raise e
Пример #2
0
    def _run_ssh(self, command, check_exit_code=True):
        #TODO(justinsb): SSH connection caching (?)
        ssh = self._connect_to_ssh()

        #TODO(justinsb): Reintroduce the retry hack
        ret = utils.ssh_execute(ssh, command, check_exit_code=check_exit_code)

        ssh.close()

        return ret
Пример #3
0
    def _run_ssh(self, command, check_exit_code=True):
        #TODO(justinsb): SSH connection caching (?)
        ssh = self._connect_to_ssh()

        #TODO(justinsb): Reintroduce the retry hack
        ret = utils.ssh_execute(ssh, command, check_exit_code=check_exit_code)

        ssh.close()

        return ret
Пример #4
0
    def _run_ssh(self, cmd_list, check_exit_code=True, attempts=1):
        utils.check_ssh_injection(cmd_list)
        command = " ".join(cmd_list)

        if not self.sshpool:
            password = self.configuration.san_password
            privatekey = self.configuration.san_private_key
            min_size = self.configuration.ssh_min_pool_conn
            max_size = self.configuration.ssh_max_pool_conn
            self.sshpool = utils.SSHPool(
                self.configuration.san_ip,
                self.configuration.san_ssh_port,
                self.configuration.ssh_conn_timeout,
                self.configuration.san_login,
                password=password,
                privatekey=privatekey,
                min_size=min_size,
                max_size=max_size,
            )
        last_exception = None
        try:
            total_attempts = attempts
            with self.sshpool.item() as ssh:
                while attempts > 0:
                    attempts -= 1
                    try:
                        return utils.ssh_execute(ssh, command, check_exit_code=check_exit_code)
                    except Exception as e:
                        LOG.error(e)
                        last_exception = e
                        greenthread.sleep(random.randint(20, 500) / 100.0)
                try:
                    raise exception.ProcessExecutionError(
                        exit_code=last_exception.exit_code,
                        stdout=last_exception.stdout,
                        stderr=last_exception.stderr,
                        cmd=last_exception.cmd,
                    )
                except AttributeError:
                    raise exception.ProcessExecutionError(
                        exit_code=-1, stdout="", stderr="Error running SSH command", cmd=command
                    )

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error running SSH command: %s") % command)
Пример #5
0
    def _run_ssh(self, cmd_list, check_exit_code=True, attempts=1):
        utils.check_ssh_injection(cmd_list)
        command = ' '.join(cmd_list)

        if not self.sshpool:
            password = self.configuration.san_password
            privatekey = self.configuration.san_private_key
            min_size = self.configuration.ssh_min_pool_conn
            max_size = self.configuration.ssh_max_pool_conn
            self.sshpool = utils.SSHPool(self.configuration.san_ip,
                                         self.configuration.san_ssh_port,
                                         self.configuration.ssh_conn_timeout,
                                         self.configuration.san_login,
                                         password=password,
                                         privatekey=privatekey,
                                         min_size=min_size,
                                         max_size=max_size)
        last_exception = None
        try:
            total_attempts = attempts
            with self.sshpool.item() as ssh:
                while attempts > 0:
                    attempts -= 1
                    try:
                        return utils.ssh_execute(
                            ssh, command, check_exit_code=check_exit_code)
                    except Exception as e:
                        LOG.error(e)
                        last_exception = e
                        greenthread.sleep(random.randint(20, 500) / 100.0)
                try:
                    raise exception.ProcessExecutionError(
                        exit_code=last_exception.exit_code,
                        stdout=last_exception.stdout,
                        stderr=last_exception.stderr,
                        cmd=last_exception.cmd)
                except AttributeError:
                    raise exception.ProcessExecutionError(
                        exit_code=-1,
                        stdout="",
                        stderr="Error running SSH command",
                        cmd=command)

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Error running SSH command: %s") % command)
Пример #6
0
    def _run_ssh(self, command, check_exit_code=True, attempts=1):
        if not self.sshpool:
            self.sshpool = utils.SSHPool(FLAGS.san_ip,
                                         FLAGS.san_ssh_port,
                                         FLAGS.ssh_conn_timeout,
                                         FLAGS.san_login,
                                         password=FLAGS.san_password,
                                         privatekey=FLAGS.san_private_key,
                                         min_size=FLAGS.ssh_min_pool_conn,
                                         max_size=FLAGS.ssh_max_pool_conn)
        last_exception = None
        try:
            total_attempts = attempts
            with self.sshpool.item() as ssh:
                while attempts > 0:
                    attempts -= 1
                    try:
                        return utils.ssh_execute(
                            ssh,
                            command,
                            check_exit_code=check_exit_code)
                    except Exception as e:
                        LOG.error(e)
                        last_exception = e
                        greenthread.sleep(random.randint(20, 500) / 100.0)
                try:
                    raise exception.ProcessExecutionError(
                            exit_code=last_exception.exit_code,
                            stdout=last_exception.stdout,
                            stderr=last_exception.stderr,
                            cmd=last_exception.cmd)
                except AttributeError:
                    raise exception.ProcessExecutionError(
                            exit_code=-1,
                            stdout="",
                            stderr="Error running SSH command",
                            cmd=command)

        except Exception as e:
            LOG.error(_("Error running SSH command: %s") % command)
            raise e