def _excmd(self, sshcmd): """ return (connected_ok, response_array) """ connected_ok = True resp = [] try: conn = Connection(self.hostname) conn.connect() self.logger.info("ssh connection created.") isAuthenticated = conn.authenticateWithPassword(self.user, self.password) if not isAuthenticated: connected_ok = False self.logger.error("ssh failed to authenticatd.") else: self.logger.info("ssh authenticated.") sess = conn.openSession() self.logger.info("ssh session created.") sess.execCommand(sshcmd) self.logger.info("ssh command issued. cmd is %s" % sshcmd) stdout = StreamGobbler(sess.getStdout()) br = BufferedReader(InputStreamReader(stdout)) while True: line = br.readLine() if line is None: break else: resp.append(line) self.logger.warning("ssh command output: " % resp) except IOException, ex: connected_ok = False # print "oops..error,", ex self.logger.error("ssh exception: %s" % ex)
def _excmd(self, sshcmd): ''' return (connected_ok, response_array) ''' connected_ok = True resp = [] try: conn = Connection(self.hostname) conn.connect() self.logger.info('ssh connection created.') isAuthenticated = conn.authenticateWithPassword( self.user, self.password) if not isAuthenticated: connected_ok = False self.logger.error('ssh failed to authenticatd.') else: self.logger.info('ssh authenticated.') sess = conn.openSession() self.logger.info('ssh session created.') sess.execCommand(sshcmd) self.logger.info('ssh command issued. cmd is %s' % sshcmd) stdout = StreamGobbler(sess.getStdout()) br = BufferedReader(InputStreamReader(stdout)) while True: line = br.readLine() if line is None: break else: resp.append(line) self.logger.warning('ssh command output: ' % resp) except IOException, ex: connected_ok = False #print "oops..error,", ex self.logger.error('ssh exception: %s' % ex)