def ssh_command_as_root(ssh_connection, cmd, check_exit_code=True):
 LOG.debug((_('Running cmd (SSH-as-root): %s') % cmd))
 chan = ssh_connection._transport.open_session()
 chan.exec_command('ioscli oem_setup_env')
 bufsize = (-1)
 stdin = chan.makefile('wb', bufsize)
 stdout = chan.makefile('rb', bufsize)
 stderr = chan.makefile_stderr('rb', bufsize)
 stdin.write(('%s\n%s\n' % (cmd, 'exit')))
 stdin.flush()
 exit_status = chan.recv_exit_status()
 if (exit_status != (-1)):
  LOG.debug((_('Result was %s') % exit_status))
  if (check_exit_code and (exit_status != 0)):
   raise nova_exception.ProcessExecutionError(exit_code=exit_status, stdout=stdout, stderr=stderr, cmd=''.join(cmd))
 return (stdout, stderr)

def ssh_command_as_root ( ssh_connection , cmd , check_exit_code = True ) : LOG . debug ( ( _ ( 'Running cmd (SSH-as-root): %s' ) % cmd ) ) chan = ssh_connection . _transport . open_session ( ) chan . exec_command ( 'ioscli oem_setup_env' ) bufsize = ( - 1 ) stdin = chan . makefile ( 'wb' , bufsize ) stdout = chan . makefile ( 'rb' , bufsize ) stderr = chan . makefile_stderr ( 'rb' , bufsize ) stdin . write ( ( '%s\n%s\n' % ( cmd , 'exit' ) ) ) stdin . flush ( ) exit_status = chan . recv_exit_status ( ) if ( exit_status != ( - 1 ) ) : LOG . debug ( ( _ ( 'Result was %s' ) % exit_status ) ) if ( check_exit_code and ( exit_status != 0 ) ) : raise nova_exception . ProcessExecutionError ( exit_code = exit_status , stdout = stdout , stderr = stderr , cmd = '' . join ( cmd ) ) return ( stdout , stderr )
method to execute remote command as root .