Exemplo n.º 1
0
def exec_get_cmd(args):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.execution_get(args.id)
    if execution is None:
        print('Execution not found')
    else:
        print('Execution {} (ID: {})'.format(execution['name'], execution['id']))
        print('Status: {}'.format(execution['status']))
        if execution['status'] == 'error':
            print('Last error: {}'.format(execution['error']))
        print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))

        if execution['time_start'] is None:
            print('Time start: {}'.format('not yet'))
        else:
            print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start'])))

        if execution['time_end'] is None:
            print('Time end: {}'.format('not yet'))
        else:
            print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))

        app = execution['description']
        print('Application name: {}'.format(app['name']))
        for c_id in execution['services']:
            c = cont_api.get(c_id)
            ip = list(c['ip_address'].values())[0]  # FIXME how to decide which network is the right one?
            print('Service {} (ID: {})'.format(c['name'], c['id']))
            for p in c['ports']:
                print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'], ip, p['port_number'], p['path']))
Exemplo n.º 2
0
def exec_list_cmd(_):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    api_user = ZoeUserAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = exec_api.list()
    for e in data:
        user = api_user.get(e['owner'])
        print('Execution {} (User: {}, ID: {}): {}'.format(e['name'], user['name'], e['id'], e['status']))
Exemplo n.º 3
0
def exec_get_cmd(args):
    """Gather information about an execution."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.get(args.id)
    if execution is None:
        print('Execution not found')
    else:
        print('Execution {} (ID: {})'.format(execution['name'], execution['id']))
        print('Status: {}'.format(execution['status']))
        if execution['status'] == 'error':
            print('Last error: {}'.format(execution['error_message']))
        print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))

        if execution['time_start'] is None:
            print('Time start: {}'.format('not yet'))
        else:
            print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start'])))

        if execution['time_end'] is None:
            print('Time end: {}'.format('not yet'))
        else:
            print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))

        app = execution['description']
        print('Application name: {}'.format(app['name']))
        for c_id in execution['services']:
            service = cont_api.get(c_id)
            print('Service {} (ID: {})'.format(service['name'], service['id']))
            print(' - zoe status: {}'.format(service['status']))
            print(' - docker status: {}'.format(service['docker_status']))
            if service['docker_status'] == 'started':
                ip = service['ip_address']
                for port in service['description']['ports']:
                    print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path']))
Exemplo n.º 4
0
def app_list_cmd(_):
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    api_user = ZoeUserAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = api_query.query('application')
    for app in data:
        user = api_user.get(app['owner'])
        print('{} (User: {}, ID: {})'.format(app['name'], user['name'], app['id']))
Exemplo n.º 5
0
def user_delete_cmd(args):
    api_user = ZoeUserAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = api_query.query('user', name=args.name)
    if len(data) == 0:
        print('No such user')
    else:
        for user in data:
            print('Deleting user {}'.format(user['name']))
            api_user.delete(user['id'])
Exemplo n.º 6
0
def exec_start_cmd(args):
    """Submit an execution."""
    app_descr = json.load(args.jsonfile)
    app_validate(app_descr)
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    ret = exec_api.start(args.name, app_descr)
    print("Application scheduled successfully with ID {}, use the exec-get command to check its status".format(ret))
Exemplo n.º 7
0
def exec_list_cmd(_):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(),
                                utils.zoe_pass())
    data = exec_api.list()
    for e in data:
        print('Execution {} (User: {}, ID: {}): {}'.format(
            e['name'], e['user_id'], e['id'], e['status']))
Exemplo n.º 8
0
def info_cmd(args_):
    """Queries the info endpoint."""
    info_api = ZoeInfoAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    info = info_api.info()
    print("Zoe version: ", info['version'])
    print("Zoe API version: ", info['api_version'])
    print("ZApp format version: ", info['application_format_version'])
    print("Deployment name: ", info['deployment_name'])
Exemplo n.º 9
0
def app_get_cmd(args):
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = api_query.query('application', name=args.name)
    if len(data) == 0:
        print("no such application")
    else:
        for app in data:
            pprint(app)
Exemplo n.º 10
0
def app_get_cmd(args):
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = api_query.query('execution', name=args.name)
    if len(data) == 0:
        print("no such execution")
    else:
        execution = data[0]
        json.dump(execution['description'], sys.stdout, sort_keys=True, indent=4)
Exemplo n.º 11
0
def app_get_cmd(args):
    """Extract an application description from an execution."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.get(args.id)
    if execution is None:
        print("no such execution")
    else:
        json.dump(execution['description'], sys.stdout, sort_keys=True, indent=4)
Exemplo n.º 12
0
def info_cmd(args_):
    """Queries the info endpoint."""
    info_api = ZoeInfoAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    info = info_api.info()
    print("Zoe version: ", info['version'])
    print("Zoe API version: ", info['api_version'])
    print("ZApp format version: ", info['application_format_version'])
    print("Deployment name: ", info['deployment_name'])
Exemplo n.º 13
0
def app_get_cmd(args):
    """Extract an application description from an execution."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.get(args.id)
    if execution is None:
        print("no such execution")
    else:
        json.dump(execution['description'], sys.stdout, sort_keys=True, indent=4)
Exemplo n.º 14
0
def user_list_cmd(_):
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    users = api_query.query('user')
    for user in users:
        print('<- User {} ->'.format(user['id']))
        print('User: {}'.format(user['name']))
        print('Role: {}'.format(user['role']))
        print('Gateway URLs: {}'.format(user['gateway_urls']))
Exemplo n.º 15
0
def log_get_cmd(args):
    cont_api = ZoeContainerAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    log = cont_api.log(args.container_id)
    if log is None:
        print("Error: No log found for container ID {}".format(args.container_id))
        return
    try:
        print(log)
    except BrokenPipeError:
        pass
Exemplo n.º 16
0
def user_new_cmd(args):
    api = ZoeUserAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    name = args.name
    password = args.password
    role = args.role
    if role not in ['admin', 'user', 'guest']:
        print("Role must be one of admin, user, guest)")
        return
    user_id = api.create(name, password, role)
    print("New user ID: {}".format(user_id))
Exemplo n.º 17
0
def app_new_cmd(args):
    app_descr = json.load(args.jsonfile)
    api = ZoeApplicationAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    try:
        app_id = api.create(app_descr)
    except ZoeAPIException as e:
        print("Invalid application description: %s" % e.message)
        return
    app = api.get(app_id)
    print("Application {} added with ID: {}".format(app['name'], app_id))
Exemplo n.º 18
0
def user_get_cmd(args):
    api = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = api.query('user', name=args.name)
    if len(data) == 0:
        print('No such user')
    else:
        user = data[0]
        print('User: {}'.format(user['name']))
        print('User ID: {}'.format(user['id']))
        print('Role: {}'.format(user['role']))
        print('Gateway URLs: {}'.format(user['gateway_urls']))
Exemplo n.º 19
0
def logs_cmd(args):
    """Retrieves and streams the logs of a service."""
    service_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    try:
        for line in service_api.get_logs(args.service_id):
            if args.timestamps:
                print(line[0], line[1])
            else:
                print(line[1])
    except KeyboardInterrupt:
        print('CTRL-C detected, exiting...')
Exemplo n.º 20
0
def exec_get_cmd(args):
    app_api = ZoeApplicationAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    cont_api = ZoeContainerAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.execution_get(args.id)
    if execution is None:
        print('Execution not found')
    else:
        print('Execution {} (ID: {})'.format(execution['name'], execution['id']))
        print('Status: {}'.format(execution['status']))
        print('Time started: {}'.format(execution['time_started']))
        print('Time scheduled: {}'.format(execution['time_scheduled']))
        print('Time finished: {}'.format(execution['time_finished']))
        app = app_api.get(execution['application_id'])
        print('Application name: {}'.format(app['name']))
        for c_id in execution['containers']:
            c = cont_api.get(c_id)
            ip = list(c['ip_address'].values())[0]  # FIXME how to decide which network is the right one?
            print('Container {} (ID: {})'.format(c['name'], c['id']))
            for p in c['ports']:
                print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'], ip, p['port_number'], p['path']))
Exemplo n.º 21
0
def _log_stream_stdout(service_id, timestamps):
    service_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    try:
        for line in service_api.get_logs(service_id):
            if timestamps:
                print(line[0], line[1])
            else:
                print(line[1])
    except KeyboardInterrupt:
        print('CTRL-C detected, exiting...')
        return 'interrupt'
    return 'stream_end'
Exemplo n.º 22
0
def app_get_cmd(args):
    api_query = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(),
                            utils.zoe_pass())
    data = api_query.query('execution', name=args.name)
    if len(data) == 0:
        print("no such execution")
    else:
        execution = data[0]
        json.dump(execution['description'],
                  sys.stdout,
                  sort_keys=True,
                  indent=4)
Exemplo n.º 23
0
def exec_get_cmd(args):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(),
                                utils.zoe_pass())
    cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(),
                             utils.zoe_pass())
    execution = exec_api.execution_get(args.id)
    if execution is None:
        print('Execution not found')
    else:
        print('Execution {} (ID: {})'.format(execution['name'],
                                             execution['id']))
        print('Status: {}'.format(execution['status']))
        if execution['status'] == 'error':
            print('Last error: {}'.format(execution['error']))
        print('Time submit: {}'.format(
            datetime.datetime.fromtimestamp(execution['time_submit'])))

        if execution['time_start'] is None:
            print('Time start: {}'.format('not yet'))
        else:
            print('Time start: {}'.format(
                datetime.datetime.fromtimestamp(execution['time_start'])))

        if execution['time_end'] is None:
            print('Time end: {}'.format('not yet'))
        else:
            print('Time end: {}'.format(
                datetime.datetime.fromtimestamp(execution['time_end'])))

        app = execution['description']
        print('Application name: {}'.format(app['name']))
        for c_id in execution['services']:
            c = cont_api.get(c_id)
            ip = list(c['ip_address'].values())[
                0]  # FIXME how to decide which network is the right one?
            print('Service {} (ID: {})'.format(c['name'], c['id']))
            for p in c['ports']:
                print(' - {}: {}://{}:{}{}'.format(p['name'], p['protocol'],
                                                   ip, p['port_number'],
                                                   p['path']))
Exemplo n.º 24
0
def exec_start_cmd(args):
    """Submit an execution."""
    app_descr = json.load(args.jsonfile)
    app_validate(app_descr)
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    exec_id = exec_api.start(args.name, app_descr)
    if not args.synchronous:
        print("Application scheduled successfully with ID {}, use the exec-get command to check its status".format(exec_id))
    else:
        print("Application scheduled successfully with ID {}, waiting for status change".format(exec_id))
        old_status = 'submitted'
        while True:
            execution = exec_api.get(exec_id)
            current_status = execution['status']
            if old_status != current_status:
                print('Execution is now {}'.format(current_status))
                old_status = current_status
            if current_status == 'running':
                break
            time.sleep(1)
        monitor_service_id = None
        service_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
        for service_id in execution['services']:
            service = service_api.get(service_id)
            if service['description']['monitor']:
                monitor_service_id = service['id']
                break

        print('\n>------ start of log streaming -------<\n')
        why_stop = _log_stream_stdout(monitor_service_id, False)
        print('\n>------ end of log streaming -------<\n')
        if why_stop == 'stream_end':
            print('Execution finished')
            exit(0)
        elif why_stop == 'interrupt':
            print('Do not worry, your execution ({}) is still running.'.format(exec_id))
            exit(1)
Exemplo n.º 25
0
def exec_get_cmd(args):
    """Gather information about an execution."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    cont_api = ZoeServiceAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    execution = exec_api.get(args.id)
    if execution is None:
        print('Execution not found')
    else:
        print('Execution {} (ID: {})'.format(execution['name'], execution['id']))
        print('Status: {}'.format(execution['status']))
        if execution['status'] == 'error':
            print('Last error: {}'.format(execution['error_message']))
        print('Time submit: {}'.format(datetime.datetime.fromtimestamp(execution['time_submit'])))

        if execution['time_start'] is None:
            print('Time start: {}'.format('not yet'))
        else:
            print('Time start: {}'.format(datetime.datetime.fromtimestamp(execution['time_start'])))

        if execution['time_end'] is None:
            print('Time end: {}'.format('not yet'))
        else:
            print('Time end: {}'.format(datetime.datetime.fromtimestamp(execution['time_end'])))

        app = execution['description']
        print('Application name: {}'.format(app['name']))
        for c_id in execution['services']:
            service = cont_api.get(c_id)
            print('Service {} (ID: {})'.format(service['name'], service['id']))
            print(' - zoe status: {}'.format(service['status']))
            print(' - docker status: {}'.format(service['docker_status']))
            if service['error_message'] is not None:
                print(' - error: {}'.format(service['error_message']))
            if service['docker_status'] == 'started':
                ip = service['ip_address']
                for port in service['description']['ports']:
                    print(' - {}: {}://{}:{}{}'.format(port['name'], port['protocol'], ip, port['port_number'], port['path']))
Exemplo n.º 26
0
def stats_cmd(args_):
    """Prints statistics on Zoe internals."""
    stats_api = ZoeStatisticsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    sched = stats_api.scheduler()
    print('Scheduler queue length: {}'.format(sched['queue_length']))
    print('Termination threads count: {}'.format(sched['termination_threads_count']))
Exemplo n.º 27
0
def exec_kill_cmd(args):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(),
                                utils.zoe_pass())
    exec_api.terminate(args.id)
Exemplo n.º 28
0
def exec_list_cmd(_):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = exec_api.list()
    for e in data:
        print('Execution {} (User: {}, ID: {}): {}'.format(e['name'], e['user_id'], e['id'], e['status']))
Exemplo n.º 29
0
def exec_list_cmd(args_):
    """List executions"""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    data = exec_api.list()
    for e in sorted(data.values(), key=lambda x: x['id']):
        print('Execution {} (User: {}, ID: {}): {}'.format(e['name'], e['user_id'], e['id'], e['status']))
Exemplo n.º 30
0
def container_stats_cmd(args):
    cont_api = ZoeContainerAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    stats = cont_api.stats(args.container_id)
    print(stats)
Exemplo n.º 31
0
def stats_cmd(_):
    api = ZoeQueryAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    stats = api.query('stats swarm')
    pprint(stats)
Exemplo n.º 32
0
def exec_kill_cmd(args):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    exec_api.terminate(args.id)
Exemplo n.º 33
0
def exec_start_cmd(args):
    app_descr = json.load(args.jsonfile)
    app_validate(app_descr)
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    ret = exec_api.execution_start(args.name, app_descr)
    print("Application scheduled successfully with ID {}, use the exec-get command to check its status".format(ret))
Exemplo n.º 34
0
def exec_rm_cmd(args):
    """Delete an execution and kill it if necessary."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    exec_api.delete(args.id)
Exemplo n.º 35
0
def exec_start_cmd(args):
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    ret = exec_api.execution_start(args.name, args.app_name)
    print("Application scheduled successfully with ID {}, use the exec-get command to check its status".format(ret))
Exemplo n.º 36
0
def stats_cmd(args_):
    """Prints statistics on Zoe internals."""
    stats_api = ZoeStatisticsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    sched = stats_api.scheduler()
    print('Scheduler queue length: {}'.format(sched['queue_length']))
    print('Termination threads count: {}'.format(sched['termination_threads_count']))
Exemplo n.º 37
0
def exec_rm_cmd(args):
    """Delete an execution and kill it if necessary."""
    exec_api = ZoeExecutionsAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    exec_api.delete(args.id)
Exemplo n.º 38
0
def app_rm_cmd(args):
    api_app = ZoeApplicationAPI(utils.zoe_url(), utils.zoe_user(), utils.zoe_pass())
    print('Deleting app {}'.format(args.app_id))
    api_app.delete(args.app_id)