示例#1
0
文件: manage.py 项目: iNaKoll/kevin
def main():
    """ Connect to a pty of some vm provided by falk """

    cmd = argparse.ArgumentParser()
    cmd.add_argument("--volatile", action="store_true",
                     help="don't start the VM in management mode")
    cmd.add_argument("falk_id",
                     help=("falk connection information: "
                           "unix://user@socket or ssh://user@host:port"))
    cmd.add_argument("vm_id", help="machine identification")
    cmd.add_argument("command", nargs="*",
                     help="command to execute. default: shell.")
    cmd.add_argument("-d", "--debug", action="store_true",
                     help="enable asyncio debugging")
    cmd.add_argument("-v", "--verbose", action="count", default=0,
                     help="increase program verbosity")
    cmd.add_argument("-q", "--quiet", action="count", default=0,
                     help="decrease program verbosity")

    args = cmd.parse_args()

    # set up log level
    log_setup(args.verbose - args.quiet)

    loop = asyncio.get_event_loop()

    # enable asyncio debugging
    loop.set_debug(args.debug)

    user, connection, location, key = parse_connection_entry(
        "falk_id", args.falk_id, require_key=False)

    if connection == "ssh":
        host, port = location
        falk = FalkSSH(host, port, user, key)

    elif connection == "unix":
        falk = FalkSocket(location, user)

    else:
        raise Exception("unknown falk connection type: %s" % connection)

    ret = 1
    try:
        ret = loop.run_until_complete(
            spawn_shell(falk, args.vm_id, args.volatile, args.command))

    except KeyboardInterrupt:
        print("\n")

    loop.stop()
    loop.run_forever()
    loop.close()

    exit(ret)
示例#2
0
文件: __main__.py 项目: mikonse/kevin
def main():
    """ Falk service launch """

    cmd = argparse.ArgumentParser(description="Kevin CI Falk - VM provider")

    cmd.add_argument("-c",
                     "--config",
                     default="/etc/kevin/falk.conf",
                     help="file name of the configuration to use.")
    cmd.add_argument("-d",
                     "--debug",
                     action="store_true",
                     help="enable asyncio debugging")
    cmd.add_argument("-v",
                     "--verbose",
                     action="count",
                     default=0,
                     help="increase program verbosity")
    cmd.add_argument("-q",
                     "--quiet",
                     action="count",
                     default=0,
                     help="decrease program verbosity")

    args = cmd.parse_args()

    print("\x1b[1;32mFalk machine service initializing...\x1b[m")

    log_setup(args.verbose - args.quiet)

    loop = asyncio.get_event_loop()

    # enable asyncio debugging
    loop.set_debug(args.debug)

    # parse config
    CFG.load(args.config)

    try:
        os.unlink(CFG.control_socket)
    except OSError:
        if os.path.exists(CFG.control_socket):
            raise
        else:
            sockdir = os.path.dirname(CFG.control_socket)
            if not os.path.exists(sockdir):
                try:
                    logging.info("creating socket directory '%s'", sockdir)
                    os.makedirs(sockdir, exist_ok=True)
                except PermissionError as exc:
                    raise exc from None

    logging.error("\x1b[1;32mstarting falk...\x1b[m")

    # state storage
    falk = Falk()

    logging.warning("listening on '%s'...", CFG.control_socket)

    proto_tasks = set()

    def create_proto():
        """ creates the asyncio protocol instance """
        proto = FalkProto(falk)

        # create message "worker" task
        proto_task = loop.create_task(proto.process_messages())
        proto_tasks.add(proto_task)

        proto_task.add_done_callback(
            lambda fut: proto_tasks.remove(proto_task))

        return proto

    srv_coro = loop.create_unix_server(create_proto, CFG.control_socket)
    server = loop.run_until_complete(srv_coro)

    if CFG.control_socket_group:
        # this only works if the current user is a member of the
        # target group!
        shutil.chown(CFG.control_socket, None, CFG.control_socket_group)

    if CFG.control_socket_permissions:
        mode = int(CFG.control_socket_permissions, 8)
        os.chmod(CFG.control_socket, mode)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print("\nexiting...")

    logging.warning("served %d connections", falk.handle_id)

    logging.info("cleaning up...")

    for proto_task in proto_tasks:
        proto_task.cancel()

    # execute the cancellations
    loop.run_until_complete(
        asyncio.gather(*proto_tasks, return_exceptions=True))

    # server teardown
    server.close()
    loop.run_until_complete(server.wait_closed())

    loop.stop()
    loop.run_forever()
    loop.close()

    print("cya!")
示例#3
0
文件: manage.py 项目: mikonse/kevin
def main():
    """ Connect to a pty of some vm provided by falk """

    cmd = argparse.ArgumentParser()
    cmd.add_argument("--volatile",
                     action="store_true",
                     help="don't start the VM in management mode")
    cmd.add_argument("falk_id",
                     help=("falk connection information: "
                           "unix://socketpath, unix://user@socket "
                           "or ssh://user@host:port"))
    cmd.add_argument("vm_id", help="machine identification")
    cmd.add_argument("command",
                     nargs="*",
                     help="command to execute. default: shell.")
    cmd.add_argument("-d",
                     "--debug",
                     action="store_true",
                     help="enable asyncio debugging")
    cmd.add_argument("-v",
                     "--verbose",
                     action="count",
                     default=0,
                     help="increase program verbosity")
    cmd.add_argument("-q",
                     "--quiet",
                     action="count",
                     default=0,
                     help="decrease program verbosity")

    args = cmd.parse_args()

    # set up log level
    log_setup(args.verbose - args.quiet)

    loop = asyncio.get_event_loop()

    # enable asyncio debugging
    loop.set_debug(args.debug)

    user, connection, location, key = parse_connection_entry("falk_id",
                                                             args.falk_id,
                                                             require_key=False)

    if connection == "ssh":
        host, port = location
        falk = FalkSSH("manage", host, port, user, key)

    elif connection == "unix":
        falk = FalkSocket("manage", location, user)

    else:
        raise Exception("unknown falk connection type: %s" % connection)

    ret = 1
    try:
        ret = loop.run_until_complete(
            spawn_shell(falk, args.vm_id, args.volatile, args.command))

    except KeyboardInterrupt:
        print("\n")

    loop.stop()
    loop.run_forever()
    loop.close()

    exit(ret)
示例#4
0
文件: __main__.py 项目: iNaKoll/kevin
def main():
    """ Falk service launch """

    cmd = argparse.ArgumentParser(
        description="Kevin CI Falk - VM provider")

    cmd.add_argument("-c", "--config", default="/etc/kevin/falk.conf",
                     help="file name of the configuration to use.")
    cmd.add_argument("-d", "--debug", action="store_true",
                     help="enable asyncio debugging")
    cmd.add_argument("-v", "--verbose", action="count", default=0,
                     help="increase program verbosity")
    cmd.add_argument("-q", "--quiet", action="count", default=0,
                     help="decrease program verbosity")

    args = cmd.parse_args()

    print("\x1b[1;32mFalk machine service initializing...\x1b[m")

    log_setup(args.verbose - args.quiet)

    loop = asyncio.get_event_loop()

    # enable asyncio debugging
    loop.set_debug(args.debug)

    # parse config
    CFG.load(args.config)

    try:
        os.unlink(CFG.control_socket)
    except OSError:
        if os.path.exists(CFG.control_socket):
            raise
        else:
            sockdir = os.path.dirname(CFG.control_socket)
            if not os.path.exists(sockdir):
                try:
                    logging.info("creating socket directory '%s'" % sockdir)
                    os.makedirs(sockdir, exist_ok=True)
                except PermissionError as exc:
                    raise exc from None

    logging.error("\x1b[1;32mstarting falk...\x1b[m")

    # state storage
    falk = Falk()

    logging.warn("listening on '%s'..." % CFG.control_socket)

    proto_tasks = set()

    def create_proto():
        """ creates the asyncio protocol instance """
        proto = FalkProto(falk)

        # create message "worker" task
        proto_task = loop.create_task(proto.process_messages())
        proto_tasks.add(proto_task)

        def conn_finished(fut):
            """ remove the task from the pending list """
            logging.log("[proto] done")
            proto_tasks.remove(proto_task)

        proto_task.add_done_callback(
            lambda fut: proto_tasks.remove(proto_task))

        return proto

    srv_coro = loop.create_unix_server(create_proto, CFG.control_socket)
    server = loop.run_until_complete(srv_coro)

    if CFG.control_socket_group:
        # this only works if the current user is a member of the
        # target group!
        shutil.chown(CFG.control_socket, None, CFG.control_socket_group)

    if CFG.control_socket_permissions:
        mode = int(CFG.control_socket_permissions, 8)
        os.chmod(CFG.control_socket, mode)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print("\nexiting...")

    logging.warn("served %d connections" % falk.handle_id)

    logging.info("cleaning up...")

    for proto_task in proto_tasks:
        proto_task.cancel()

    # execute the cancellations
    loop.run_until_complete(asyncio.gather(*proto_tasks,
                                           return_exceptions=True))

    # server teardown
    server.close()
    loop.run_until_complete(server.wait_closed())

    loop.stop()
    loop.run_forever()
    loop.close()

    print("cya!")