Ejemplo n.º 1
0
    def _exec_command(self, command):
        """
        Executes a command on the remote host.

        Args:
            command (str): a command to run remotely.

        Returns:
            str: command execution output.

        Raises:
            CommandExecutionFailure: if the remote host returned a code
                indicating a failure in execution.
        """
        split = shlex.split(command)

        rc, out, err = self._executor.run_cmd(split)

        if rc != 0:
            self.logger.error(
                ERROR_MSG_FORMAT.format(command=command,
                                        rc=rc,
                                        out=out,
                                        err=err))
            raise CommandExecutionFailure(executor=self._executor,
                                          cmd=split,
                                          rc=rc,
                                          err=err)
        return out
Ejemplo n.º 2
0
    def _exec_command(self, command):
        """
        Executes a command on the remote host.

        Args:
            command (str): a command to run remotely.

        Returns:
            str: command execution output.

        Raises:
            CommandExecutionFailure: if the remote host returned a code
                indicating a failure in execution.
        """
        split = shlex.split(command)

        rc, out, err = self._executor.run_cmd(split)

        if rc != 0:
            self.logger.error(f"\n"
                              f"command -> {command}\n"
                              f"RC -> {rc}\n"
                              f"OUT -> {out}\n"
                              f"ERROR -> {err}")
            raise CommandExecutionFailure(executor=self._executor,
                                          cmd=split,
                                          rc=rc,
                                          err=err)
        return out
Ejemplo n.º 3
0
    def _cmd(self, cmd):
        rc, out, err = self._m.runCmd(cmd)

        if rc:
            raise CommandExecutionFailure(self._m.executor, cmd, rc,
                                          "OUT: %s\nERR: %s" % (out, err))
        return out
Ejemplo n.º 4
0
    def _cmd(self, cmd):
        rc, out, err = self._m.runCmd(cmd)

        if rc:
            cmd_out = " ".join(cmd)
            raise CommandExecutionFailure("Fail to run command %s: %s ; %s" %
                                          (cmd_out, out, err))
        return out
Ejemplo n.º 5
0
    def set_hostname(self, name):
        """
        Set hostname persistently

        Args:
            name (str): Hostname to be set
        """
        cmd = ['hostnamectl', 'set-hostname', name]
        rc, _, err = self._m.runCmd(cmd)
        if rc:
            raise CommandExecutionFailure("Unable to set hostname: %s" % err)