예제 #1
0
파일: ssh.py 프로젝트: dmc2015/moxie
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
예제 #2
0
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
예제 #3
0
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))
예제 #4
0
파일: ssh.py 프로젝트: dmc2015/moxie
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))
예제 #5
0
파일: app.py 프로젝트: dmc2015/moxie
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)
예제 #6
0
파일: app.py 프로젝트: rshorey/moxie
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)
예제 #7
0
파일: ssh.py 프로젝트: dmc2015/moxie
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
예제 #8
0
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
예제 #9
0
파일: ssh.py 프로젝트: dmc2015/moxie
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)
예제 #10
0
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)
예제 #11
0
파일: ssh.py 프로젝트: dmc2015/moxie
    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
예제 #12
0
    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
예제 #13
0
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")
예제 #14
0
파일: ssh.py 프로젝트: dmc2015/moxie
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")
예제 #15
0
파일: email.py 프로젝트: rshorey/moxie
 def __init__(self, host, user, password):
     self.db = Service.resolve("moxie.cores.database.DatabaseService")
     self.host = host
     self.user = user
     self.password = password
예제 #16
0
파일: email.py 프로젝트: dmc2015/moxie
 def __init__(self, host, user, password):
     self.db = Service.resolve("moxie.cores.database.DatabaseService")
     self.host = host
     self.user = user
     self.password = password
예제 #17
0
파일: slack.py 프로젝트: dmc2015/moxie
 def __init__(self, bot):
     self.bot = bot
     self.db = Service.resolve("moxie.cores.database.DatabaseService")
예제 #18
0
파일: container.py 프로젝트: dmc2015/moxie
 def __init__(self):
     super(ContainerService, self).__init__()
     self._containers = weakref.WeakValueDictionary()
     self._docker = Docker()
     self._database = Service.resolve("moxie.cores.database.DatabaseService")
예제 #19
0
 def __init__(self, bot):
     self.bot = bot
     self.db = Service.resolve("moxie.cores.database.DatabaseService")
예제 #20
0
 def __init__(self):
     super(ContainerService, self).__init__()
     self._containers = weakref.WeakValueDictionary()
     self._docker = Docker()
     self._database = Service.resolve(
         "moxie.cores.database.DatabaseService")