@Name: runCommand @Desc: Runs a command over ssh and returns the result along with status code @Input: command to execute @Output: 1: status of command executed. SUCCESS : If command execution is successful FAILED :
(self, command)
| 155 | return ret |
| 156 | |
| 157 | def runCommand(self, command): |
| 158 | ''' |
| 159 | @Name: runCommand |
| 160 | @Desc: Runs a command over ssh and |
| 161 | returns the result along with status code |
| 162 | @Input: command to execute |
| 163 | @Output: 1: status of command executed. |
| 164 | SUCCESS : If command execution is successful |
| 165 | FAILED : If command execution has failed |
| 166 | 2: stdin,stdout,stderr values of command output |
| 167 | ''' |
| 168 | ret = {"status": FAILED, "stdin": None, "stdout": None, |
| 169 | "stderr": INVALID_INPUT} |
| 170 | if command is None or command == '': |
| 171 | return ret |
| 172 | try: |
| 173 | status_check = 1 |
| 174 | stdin, stdout, stderr = self.ssh.\ |
| 175 | exec_command(command, timeout=self.timeout) |
| 176 | if stdout is not None: |
| 177 | status_check = stdout.channel.recv_exit_status() |
| 178 | if status_check == 0: |
| 179 | ret["status"] = SUCCESS |
| 180 | ret["stdout"] = stdout.readlines() |
| 181 | if stderr is not None: |
| 182 | ret["stderr"] = stderr.readlines() |
| 183 | except Exception as e: |
| 184 | ret["stderr"] = GetDetailExceptionInfo(e) |
| 185 | self.logger.exception("SshClient: Exception under runCommand :%s" % |
| 186 | GetDetailExceptionInfo(e)) |
| 187 | finally: |
| 188 | self.logger.debug(" Host: %s Cmd: %s Output:%s" % |
| 189 | (self.host, command, str(ret))) |
| 190 | return ret |
| 191 | |
| 192 | def scp(self, srcFile, destPath): |
| 193 | transport = Transport((self.host, int(self.port))) |