def __init__(self, session_logs, taskconf, sshkey, ipaddress=None, destroy=None, event_stop=None, launchq=None): self.pid = os.getpid() if event_stop: signal.signal(signal.SIGINT, signal.SIG_IGN) self.event_stop = event_stop self.logs = session_logs self.sshkey = sshkey self.strikes = taskconf.strikes self.strike = 0 self.timeout = taskconf.timeout self.cleanup_command = taskconf.post self.user = taskconf.user self.ipaddress = ipaddress self.instanceid = None self.hub = None self.ssh = None if destroy is None: if ipaddress: destroy = False else: destroy = True self.destroy = destroy if not ipaddress: if not taskconf.hub_apikey: raise self.Error( "can't auto launch a worker without a Hub API KEY") self.hub = Hub(taskconf.hub_apikey) if launchq: with sighandle.sigignore(signal.SIGINT, signal.SIGTERM): instance = launchq.get() else: class Bool: value = False stopped = Bool() def handler(s, f): stopped.value = True with sighandle.sighandle(handler, signal.SIGINT, signal.SIGTERM): def callback(): return not stopped.value instance = list( self.hub.launch(1, VerboseLog(session_logs.manager), callback, **taskconf.ec2_opts))[0] if not instance or (event_stop and event_stop.is_set()): raise self.Terminated self.ipaddress, self.instanceid = instance self.status("launched worker %s" % self.instanceid) else: self.status("using existing worker") self.handle_stop = self._stop_handler(event_stop) try: self.ssh = SSH(self.ipaddress, identity_file=self.sshkey.path, login_name=taskconf.user, callback=self.handle_stop) except SSH.Error, e: self.status("unreachable via ssh: " + str(e)) traceback.print_exc(file=self.logs.worker) raise self.Error(e)
raise ValueError except ValueError: usage("illegal howmany value '%s'" % howmany) if output != '-': if exists(output): fatal("'%s' already exists, refusing to overwrite" % output) output = lazyclass(file)(output, "w") else: output = sys.stdout class Bool: value = False stopped = Bool() def handler(s, f): print >> sys.stderr, "caught SIGINT, stopping launch" stopped.value = True with sighandle(handler, signal.SIGINT): def callback(): return not stopped.value for ipaddress, instanceid in Hub(hub_apikey).launch(howmany, logfh=sys.stderr, callback=callback, **kwargs): print >> output, ipaddress output.flush() if __name__ == "__main__": main()
fatal("'%s' already exists, refusing to overwrite" % output) output = lazyclass(file)(output, "w") else: output = sys.stdout class Bool: value = False stopped = Bool() def handler(s, f): print >> sys.stderr, "caught SIGINT, stopping launch" stopped.value = True with sighandle(handler, signal.SIGINT): def callback(): return not stopped.value for ipaddress, instanceid in Hub(hub_apikey).launch(howmany, logfh=sys.stderr, callback=callback, **kwargs): print >> output, ipaddress output.flush() if __name__ == "__main__": main()