Beispiel #1
0
 def service_logs(self, uid, role, service_id, stream=True):
     """Retrieve the logs for the given service."""
     service = self.sql.service_list(id=service_id, only_one=True)
     if service is None:
         raise zoe_api.exceptions.ZoeNotFoundException('No such service')
     if service.user_id != uid and role != 'admin':
         raise zoe_api.exceptions.ZoeAuthException()
     if service.docker_id is None:
         raise zoe_api.exceptions.ZoeNotFoundException('Container is not running')
     swarm = SwarmClient(get_conf())
     return swarm.logs(service.docker_id, stream)
 def service_logs(self, uid, role, service_id, stream=True):
     """Retrieve the logs for the given service."""
     service = self.sql.service_list(id=service_id, only_one=True)
     if service is None:
         raise zoe_api.exceptions.ZoeNotFoundException('No such service')
     if service.user_id != uid and role != 'admin':
         raise zoe_api.exceptions.ZoeAuthException()
     if service.docker_id is None:
         raise zoe_api.exceptions.ZoeNotFoundException('Container is not running')
     swarm = SwarmClient(get_conf())
     return swarm.logs(service.docker_id, stream)
Beispiel #3
0
def main():
    """The main entrypoint function."""
    conf = load_configuration()
    config.load_configuration(conf)
    args = config.get_conf()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
    else:
        logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

    logging.getLogger('kazoo').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    logging.getLogger('docker').setLevel(logging.INFO)
    logging.getLogger("tornado").setLevel(logging.DEBUG)

    state = FakeSQLManager()

    zapp_description = json.load(args.jsonfile)

    print('Validating zapp description...')
    zoe_lib.applications.app_validate(zapp_description)

    exec_id = state.execution_new('test', 'fake_user', zapp_description)
    e = state.execution_list(only_one=True, id=exec_id)
    _digest_application_description(state, e)

    print('Zapp digested, starting containers...')
    execution_to_containers(e)

    print('Giving the containers a few seconds to start...')
    time.sleep(5)

    swarm = SwarmClient(args)
    for service in e.services:
        print("Service {}, docker ID: {}".format(service.name, service.docker_id))
        logs = swarm.logs(service.docker_id, False)
        logs = logs.decode('utf-8').split('\n')
        for log_line in logs[-10:]:
            print(log_line)

    print("Execution as been started, press CTRL-C to terminate it")
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    print('Terminating...')
    terminate_execution(e)
def save(execution: Execution):
    """Save the logs of the service specified as argument"""
    path = _init(execution)
    if path is None:
        return

    for service in execution.services:
        fname = service.name + '.txt'
        fpath = os.path.join(path, fname)

        swarm = SwarmClient(get_conf())
        log_gen = swarm.logs(service.docker_id, stream=True, follow=False)
        if log_gen is None:
            _shutdown()
            return
        try:
            with open(fpath, 'wb') as out_fp:
                for line in log_gen:
                    out_fp.write(line)
        except FileNotFoundError:
            log.error("Could not create file {}".format(fpath))

    _shutdown()