Executes a command via ssh and sends back the exit status code.

def RunCommandOnHosts(cmd, hostnames, ssh_key):
  """ Executes a command via ssh and sends back the exit status code. """
  if not hostnames:
    return
  p = multiprocessing.Pool(1)
  remote_command_args = [(cmd, hostname, ssh_key) for hostname in hostnames]
  #print remote_command_args
  result = None
  while not result:
    try:    
      result = p.map_async(__RemoteExecuteHelper, remote_command_args).get(999999) # allows for keyboard interrupt
    except paramiko.SSHException as e:      
      logging.info( 'failure in RunCommandOnHosts: %s' % (e))
      time.sleep(5)
    
  p.close()
  p.join()
  return result