Beispiel #1
0
def execute(command, host=None, bg=True, **kwds):
    '''execute a command (possibly) on a remote host

Execute a process, and return the launcher. Use 'response' to retrieve the
response from the executed command. Use 'kill' to kill the launcher, and 'pid'
to get the process id for the launcher.

Inputs:
    command -- command string to be executed
    host    -- hostname of execution target  [default = None (i.e. run locally)]
    bg      -- run as background process?  [default = True]
  '''
    #XXX: options, background, stdin can be set w/ kwds (also name, launcher)
    bg = bool(bg)  # overrides 'background'
    if host in [None, '']:
        from Launcher import Launcher
        launcher = Launcher(**kwds)
        launcher(command=command, background=bg)
    else:
        from LauncherSSH import LauncherSSH
        opt = kwds.pop('options', '-q')
        launcher = LauncherSSH(**kwds)
        launcher(options=opt, command=command, host=host, background=bg)
    logging.info('executing {%s}', launcher.message)
    launcher.launch()
    #response = launcher.response()
    #launcher.kill()
    #return response
    return launcher
Beispiel #2
0
def serve(server, rhost, rport, profile='.bash_profile'):
    '''begin serving RPC requests

Inputs:
    server  -- name of RPC server  (i.e. 'ppserver')
    rhost   -- hostname on which a server should be launched
    rport   -- port number (on rhost) that server will accept request at
    profile -- file on remote host that instantiates the user's environment
        [default = '.bash_profile']
  '''
    file = '~/bin/%s.py' % server  #XXX: _should_ be on the $PATH
    #file = '%s.py' % server
    command = "source %s; %s -p %s" % (profile, file, rport)
    from LauncherSSH import LauncherSSH
    rserver = LauncherSSH('%s' % command)
    print 'executing {ssh %s "%s"}' % (rhost, command)
    rserver.stage(options='-q',
                  command=command,
                  rhost=rhost,
                  fgbg='background')
    rserver.launch()
    response = rserver.response()
    if response in ['', None]:  #XXX: other responses allowed (?)
        pass
    else:
        print response  #XXX: not really error checking...
    from time import sleep
    delay = 2.0
    sleep(delay)
    return response
Beispiel #3
0
def serve(server,rhost,rport,profile='.bash_profile'):
  '''begin serving RPC requests

Inputs:
    server  -- name of RPC server  (i.e. 'ppserver')
    rhost   -- hostname on which a server should be launched
    rport   -- port number (on rhost) that server will accept request at
    profile -- file on remote host that instantiates the user's environment
        [default = '.bash_profile']
  '''
  file = '~/bin/%s.py' % server  #XXX: _should_ be on the $PATH
  #file = '%s.py' % server
  command = "source %s; %s -p %s" % (profile,file,rport)
  from LauncherSSH import LauncherSSH
  rserver = LauncherSSH('%s' % command)
  logging.info('executing {ssh %s "%s"}', rhost, command)
  rserver.stage(options='-q', command=command, rhost=rhost, fgbg='background')
  rserver.launch()
  response = rserver.response()
  logging.info('response = %r', response)
  if response in ['', None]: #XXX: other responses allowed (?)
    pass
  else:
    logging.error('invalid response = %r', response) #XXX: not really error checking...
  from time import sleep
  delay = 2.0
  sleep(delay)
  return response
Beispiel #4
0
def randomport(host=None):
  '''select a open port on a (possibly) remote host

Inputs:
    host -- hostname on which to select a open port
  '''
  from pathos.portpicker import randomport
  if not host:
    return randomport()
  from pathos.LauncherSSH import LauncherSSH
  from pathos.portpicker import __file__ as src
  # make sure src is a .py file, not .pyc or .pyo
  src = src.rstrip('co')
  launcher = LauncherSSH() #XXX: use pox.which / which_python?
  launcher(command='python', host=host, background=False, stdin=open(src))
  logging.info('executing {python <%s} on %s', src, host)
  launcher.launch()
  try:
    rport = int(launcher.response())
  except:
    from Tunnel import TunnelException
    raise TunnelException("failure to pick remote port")
  # return remote port number
  return rport
Beispiel #5
0
def randomport(host=None):
    '''select a open port on a (possibly) remote host

Inputs:
    host -- hostname on which to select a open port
  '''
    from pathos.portpicker import randomport
    if not host:
        return randomport()
    from pathos.LauncherSSH import LauncherSSH
    from pathos.portpicker import __file__ as src
    # make sure src is a .py file, not .pyc or .pyo
    src = src.rstrip('co')
    launcher = LauncherSSH()  #XXX: use pox.which / which_python?
    launcher(command='python', host=host, background=False, stdin=open(src))
    logging.info('executing {python <%s} on %s', src, host)
    launcher.launch()
    try:
        rport = int(launcher.response())
    except:
        from Tunnel import TunnelException
        raise TunnelException("failure to pick remote port")
    # return remote port number
    return rport
Beispiel #6
0
def run(command, rhost, bg=True):  #XXX: default should be fg=True ?
    '''execute a command on a remote host

Inputs:
    command -- command string to be executed
    host    -- hostname of execution target
    bg      -- run as background process?  [default = True]
  '''
    if not bg: fgbg = 'foreground'
    else: fgbg = 'background'
    from LauncherSSH import LauncherSSH
    launcher = LauncherSSH('%s' % command)
    #print 'executing {ssh %s "%s"}' % (rhost,command)
    launcher.stage(options='-q', command=command, rhost=rhost, fgbg=fgbg)
    launcher.launch()
    return launcher.response()  #XXX: should return launcher, not just response
Beispiel #7
0
def run(command,rhost,bg=True): #XXX: default should be fg=True ?
  '''execute a command on a remote host

Inputs:
    command -- command string to be executed
    host    -- hostname of execution target
    bg      -- run as background process?  [default = True]
  '''
  if not bg: fgbg = 'foreground'
  else: fgbg = 'background'
  from LauncherSSH import LauncherSSH
  launcher = LauncherSSH('%s' % command)
  logging.info('executing {ssh %s "%s"}', rhost, command)
  launcher.stage(options='-q', command=command, rhost=rhost, fgbg=fgbg)
  launcher.launch()
  return launcher.response() #XXX: should return launcher, not just response
Beispiel #8
0
def pickport(rhost):
  '''select a open port on a remote host

Inputs:
    rhost -- hostname on which to select a open port
  '''
  from pathos.LauncherSSH import LauncherSSH
  from pathos.portpicker import __file__ as src
  # make sure src is a .py file, not .pyc or .pyo
  src = src.rstrip('co')
  launcher = LauncherSSH('pickport')
  launcher.stage(command='python', rhost=rhost, #XXX: pox.which or which_python?
          fgbg='foreground', stdin=open(src))
  logging.info('executing {python <%s} on %s', src, rhost)
  launcher.launch()
  try:
    rport = int(launcher.response())
  except:
    from Tunnel import TunnelException
    raise TunnelException, "failure to pick remote port"
  # return remote port number
  return rport
Beispiel #9
0
    class Inventory(Component.Inventory):
        import pyre.inventory

        launcher = pyre.inventory.facility('launcher',
                                           default=LauncherSSH('launcher'))