Пример #1
0
def list_group_pod(id_or_name):
    if id_or_name.isdigit():
        group = Group.get(int(id_or_name))
    else:
        group = Group.get_by_name(id_or_name)
    if not group:
        abort(404, 'Group %s not found' % id_or_name)
    return group.list_pods(g.start, g.limit)
Пример #2
0
def list_group_pod(id_or_name):
    if id_or_name.isdigit():
        group = Group.get(int(id_or_name))
    else:
        group = Group.get_by_name(id_or_name)
    if not group:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Group %s not found' % id_or_name)
    return group.list_pods(g.start, g.limit)
Пример #3
0
def assign_pod_to_group(pod_name):
    data = request.get_json()

    group = Group.get_by_name(data['group_name'])
    pod = Pod.get_by_name(pod_name)
    if not group or not pod:
        raise EruAbortException(code.HTTP_BAD_REQUEST)

    if not pod.assigned_to_group(group):
        raise EruAbortException(code.HTTP_BAD_REQUEST)
    return {'r':0, 'msg': code.OK}
Пример #4
0
def group_max_containers(group_name):
    pod_name = request.args.get('pod_name', type=str, default='')
    cores_per_container = request.args.get('ncore', type=int, default=1)

    group = Group.get_by_name(group_name)
    if not group:
        raise EruAbortException(code.HTTP_BAD_REQUEST)
    pod = Pod.get_by_name(pod_name)
    if not pod:
        raise EruAbortException(code.HTTP_BAD_REQUEST)

    return {'r':0, 'msg': code.OK, 'data': group.get_max_containers(pod, cores_per_container)}
Пример #5
0
def assign_pod_to_group(pod_name):
    data = request.get_json()

    group = Group.get_by_name(data['group_name'])
    pod = Pod.get_by_name(pod_name)
    if not group or not pod:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No group/pod found')

    if not pod.assigned_to_group(group):
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Assign failed')
    current_app.logger.info('Pod (name=%s) assigned to group (name=%s)',
            pod_name, data['group_name'])
    return {'r':0, 'msg': consts.OK}
Пример #6
0
def assign_pod_to_group(pod_name):
    data = request.get_json()

    group = Group.get_by_name(data['group_name'])
    pod = Pod.get_by_name(pod_name)
    if not group or not pod:
        abort(404, 'No group/pod found')

    if not pod.assigned_to_group(group):
        abort(400, 'Assign failed')
    current_app.logger.info('Pod (name=%s) assigned to group (name=%s)',
            pod_name, data['group_name'])
    return {'r':0, 'msg': consts.OK}
Пример #7
0
def group_max_containers(group_name):
    pod_name = request.args.get('pod_name', default='')
    core_require = request.args.get('ncore', type=float, default=1)

    group = Group.get_by_name(group_name)
    if not group:
        abort(400, 'No group found')
    pod = Pod.get_by_name(pod_name)
    if not pod:
        abort(400, 'No pod found')

    ncore, nshare = pod.get_core_allocation(core_require)
    return {'r':0, 'msg': consts.OK, 'data': get_max_container_count(group, pod, ncore, nshare)}
Пример #8
0
def assign_host_to_group(addr):
    data = request.get_json()

    group = Group.get_by_name(data['group_name'])
    if not group:
        raise EruAbortException(code.HTTP_BAD_REQUEST)

    host = Host.get_by_addr(addr)
    if not host:
        raise EruAbortException(code.HTTP_BAD_REQUEST)

    if not host.assigned_to_group(group):
        raise EruAbortException(code.HTTP_BAD_REQUEST)
    return {'r':0, 'msg': code.OK}
Пример #9
0
def group_max_containers(group_name):
    pod_name = request.args.get('pod_name', type=str, default='')
    core_require = request.args.get('ncore', type=float, default=1)

    group = Group.get_by_name(group_name)
    if not group:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No group found')
    pod = Pod.get_by_name(pod_name)
    if not pod:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No pod found')

    core_require = int(core_require * pod.core_share) # 是说一个容器要几个核...
    ncore = core_require / pod.core_share
    nshare = core_require % pod.core_share

    return {'r':0, 'msg': consts.OK, 'data': group.get_max_containers(pod, ncore, nshare)}
Пример #10
0
def assign_host_to_group(addr):
    data = request.get_json()

    group = Group.get_by_name(data['group_name'])
    if not group:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No group found')

    host = Host.get_by_addr(addr)
    if not host:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'No host found')

    if not host.assigned_to_group(group):
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Assign failed')
    current_app.logger.info('Host (addr=%s) assigned to group (name=%s)',
            addr, data['group_name'])
    return {'r':0, 'msg': consts.OK}
Пример #11
0
def validate_instance(group_name, pod_name, appname, version):
    group = Group.get_by_name(group_name)
    if not group:
        abort(400, 'Group `%s` not found' % group_name)

    pod = Pod.get_by_name(pod_name)
    if not pod:
        abort(400, 'Pod `%s` not found' % pod_name)

    app = App.get_by_name(appname)
    if not app:
        abort(400, 'App `%s` not found' % appname)

    version = app.get_version(version)
    if not version:
        abort(400, 'Version `%s` not found' % version)

    return group, pod, app, version
Пример #12
0
def validate_instance(group_name, pod_name, appname, version):
    group = Group.get_by_name(group_name)
    if not group:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Group `%s` not found' % group_name)

    pod = Pod.get_by_name(pod_name)
    if not pod:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Pod `%s` not found' % pod_name)

    application = App.get_by_name(appname)
    if not application:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'App `%s` not found' % appname)

    version = application.get_version(version)
    if not version:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Version `%s` not found' % version)

    return group, pod, application, version
Пример #13
0
def test_group_pod(test_db):
    g1 = Group.create('group1', 'group1')
    g2 = Group.create('group1', 'group1')
    assert g1 is not None
    assert g1.name == 'group1'
    assert g2 is None

    p1 = Pod.create('pod1', 'pod1')
    p2 = Pod.create('pod1', 'pod1')
    assert p1 is not None
    assert p1.name == 'pod1'
    assert p2 is None

    g3 = Group.get_by_name('group1')
    assert g3.id == g1.id

    p3 = Pod.get_by_name('pod1')
    assert p3.id == p1.id

    assert p3.assigned_to_group(g3)
    assert p3.get_free_public_hosts(10) == []
    assert g3.get_max_containers(p3, 1, 2) == 0
    assert g3.get_free_cores(p3, 1, 1, 2) == {}