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
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
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.secure import Pipe from pathos.portpicker import __file__ as src # make sure src is a .py file, not .pyc or .pyo src = src.rstrip('co') launcher = Pipe() #XXX: use pox.which / which_python? launcher(command='python', host=host, background=False, stdin=open(src)) pathos.logger().info('executing {python <%s} on %s', src, host) launcher.launch() try: rport = int(launcher.response()) except: from pathos.secure import TunnelException raise TunnelException("failure to pick remote port") # return remote port number return rport