def attach(stdin, stdout, stderr, *, args=None): container = Service.resolve("moxie.cores.container.ContainerService") if len(args) != 1: stderr.write("Just give me a single job name") return name, = args try: container = yield from container.get(name) except ValueError as e: stderr.write(str(e)) return @asyncio.coroutine def writer(): logs = container.logs logs.saferun() queue = logs.listen() while logs.running: out = yield from queue.get() stdout.write(out.decode('utf-8')) # raise StopItError("Attach EOF") stdout.write("[ process complete ]\r\n") w = writer() try: yield from asyncio.gather(w, aborter(stdin, w)) except StopItError: return
def list(stdin, stdout, stderr, *, args=None): database = Service.resolve("moxie.cores.database.DatabaseService") jobs = yield from database.job.list() for job in jobs: stdout.write("[%s] - %s - %s\n\r" % (job.name, job.image, job.command))
def stream(request, name): container = Service.resolve("moxie.cores.container.ContainerService") container = yield from container.get(name) logs = container.logs logs.saferun() queue = logs.listen() while True: out = yield from queue.get() request.writer.send(out)
def running(stdin, stdout, stderr, *, args=None): container = Service.resolve("moxie.cores.container.ContainerService") database = Service.resolve("moxie.cores.database.DatabaseService") jobs = (yield from database.job.list()) running = (yield from container.list(all=True)) nmap = {z: x for x in [x._container for x in running] for z in x['Names']} for job in jobs: cname = "/{}".format(job.name) container = nmap.get(cname, {}) if container is None: pass stdout.write("{name} - {status}\n\r".format( name=job.name, status=container.get('Status', "offline") )) return
def running(stdin, stdout, stderr, *, args=None): container = Service.resolve("moxie.cores.container.ContainerService") database = Service.resolve("moxie.cores.database.DatabaseService") jobs = (yield from database.job.list()) running = (yield from container.list(all=True)) nmap = {z: x for x in [x._container for x in running] for z in x['Names']} for job in jobs: cname = "/{}".format(job.name) container = nmap.get(cname, {}) if container is None: pass stdout.write("{name} - {status}\n\r".format(name=job.name, status=container.get( 'Status', "offline"))) return
def run(stdin, stdout, stderr, *, args=None): run = Service.resolve("moxie.cores.run.RunService") if len(args) != 1: stderr.write("Just give me a single job name") return name, = args stdout.write("Starting job %s...\r\n" % (name)) try: yield from run.run(name, 'ssh') except ValueError as e: stderr.write(str(e)) return stdout.write(" Wheatley: Surprise! We're doing it now!\r\n") stdout.write("\n\r" * 3) yield from attach(stdin, stdout, stderr, args=args)
def __call__(self): database = Service.resolve("moxie.cores.database.DatabaseService") # self.alert = CronService.resolve("moxie.cores.alert.AlertService") # register an ssh callback for each thinger ssh_host_keys = asyncssh.read_private_key_list('ssh_host_keys') if MoxieSSHServer._keys is None: authorized_keys = {} for key in asyncssh.read_public_key_list('authorized_keys'): authorized_keys[key] = (yield from database.user.get_by_fingerprint( fingerprint(key))) MoxieSSHServer._keys = authorized_keys obj = yield from asyncssh.create_server( MoxieSSHServer, '0.0.0.0', 2222, server_host_keys=ssh_host_keys ) return obj
def __call__(self): database = Service.resolve("moxie.cores.database.DatabaseService") # self.alert = CronService.resolve("moxie.cores.alert.AlertService") # register an ssh callback for each thinger ssh_host_keys = asyncssh.read_private_key_list('ssh_host_keys') if MoxieSSHServer._keys is None: authorized_keys = {} for key in asyncssh.read_public_key_list('authorized_keys'): authorized_keys[key] = (yield from database.user.get_by_fingerprint( fingerprint(key))) MoxieSSHServer._keys = authorized_keys obj = yield from asyncssh.create_server(MoxieSSHServer, '0.0.0.0', 2222, server_host_keys=ssh_host_keys) return obj
def kill(stdin, stdout, stderr, *, args=None): container = Service.resolve("moxie.cores.container.ContainerService") if len(args) != 1: stderr.write("Just give me a single job name\r") return name, = args stdout.write("Killing job %s...\r\n\r\n" % (name)) stdout.write( " GLaDOS: Ah! Well, this is the part where he kills us.\r\n") try: yield from container.kill(name) except ValueError as e: stderr.write(str(e)) return stdout.write( " Wheatley: Hello! This is the part where I kill you!\r\n\r\n") stdout.write("Job terminated")
def kill(stdin, stdout, stderr, *, args=None): container = Service.resolve("moxie.cores.container.ContainerService") if len(args) != 1: stderr.write("Just give me a single job name\r") return name, = args stdout.write("Killing job %s...\r\n\r\n" % (name)) stdout.write( " GLaDOS: Ah! Well, this is the part where he kills us.\r\n" ) try: yield from container.kill(name) except ValueError as e: stderr.write(str(e)) return stdout.write( " Wheatley: Hello! This is the part where I kill you!\r\n\r\n" ) stdout.write("Job terminated")
def __init__(self, host, user, password): self.db = Service.resolve("moxie.cores.database.DatabaseService") self.host = host self.user = user self.password = password
def __init__(self, bot): self.bot = bot self.db = Service.resolve("moxie.cores.database.DatabaseService")
def __init__(self): super(ContainerService, self).__init__() self._containers = weakref.WeakValueDictionary() self._docker = Docker() self._database = Service.resolve("moxie.cores.database.DatabaseService")
def __init__(self): super(ContainerService, self).__init__() self._containers = weakref.WeakValueDictionary() self._docker = Docker() self._database = Service.resolve( "moxie.cores.database.DatabaseService")