当前位置: 首页>>代码示例>>Python>>正文


Python Pod.get_by_name方法代码示例

本文整理汇总了Python中eru.models.Pod.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Pod.get_by_name方法的具体用法?Python Pod.get_by_name怎么用?Python Pod.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eru.models.Pod的用法示例。


在下文中一共展示了Pod.get_by_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def create_host():
    """为了文件, 只好不用json了"""
    addr = request.form.get('addr', default='')
    pod_name = request.form.get('pod_name', default='')
    if not (addr and pod_name):
        abort(400, 'Need addr and pod_name')

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

    # 存证书, 没有就算了
    if all(k in request.files for k in ['ca', 'cert', 'key']):
        try:
            ca, cert, key = request.files['ca'], request.files['cert'], request.files['key']
            save_docker_certs(addr.split(':', 1)[0], ca.read(), cert.read(), key.read())
        finally:
            ca.close()
            cert.close()
            key.close()

    try:
        client = get_docker_client(addr, force_flush=True)
        info = client.info()
    except Exception as e:
        abort(400, 'Docker daemon error on host %s, error: %s' % (addr, e.message))

    if not Host.create(pod, addr, info['Name'], info['ID'], info['NCPU'], info['MemTotal']):
        abort(400, 'Host create error.')
    return 201, {'r':0, 'msg': consts.OK}
开发者ID:CMGS,项目名称:eru-core,代码行数:32,代码来源:sys.py

示例2: create_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def create_host():
    """为了文件, 只好不用json了"""
    addr = request.form.get('addr', default='')
    ip = addr.split(':', 1)[0]
    podname = request.form.get('podname', default='')
    is_public = request.form.get('is_public', default=False, type=bool)
    if not (addr and podname):
        abort(400, 'Bad addr or podname: addr="{}", podname="{}"'.format(addr, podname))

    pod = Pod.get_by_name(podname)
    if not pod:
        abort(400, 'Pod {} not found'.format(podname))

    # 存证书, 没有就算了
    certs = ['ca', 'cert', 'key']
    if all(k in request.files for k in certs):
        certs_contents = tuple(request.files[f].read() for f in certs)
        save_docker_certs(ip, *certs_contents)

    try:
        client = get_docker_client(addr, force_flush=True)
        info = client.info()
    except Exception as e:
        abort(400, 'Docker daemon error on host %s, error: %s' % (addr, e.message))

    if not Host.create(pod, addr, info['Name'], info['ID'], info['NCPU'],
                       info['MemTotal'], is_public=is_public):
        abort(400, 'Error while creating host')

    return 201, DEFAULT_RETURN_VALUE
开发者ID:timfeirg,项目名称:eru-core,代码行数:32,代码来源:host.py

示例3: create_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def create_host():
    """为了文件, 只好不用json了"""
    addr = request.form.get('addr', type=str, default='')
    pod_name = request.form.get('pod_name', type=str, default='')
    if not (addr and pod_name):
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'need addr and pod_name')

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

    # 存证书, 没有就算了
    try:
        ca, cert, key = request.files['ca'], request.files['cert'], request.files['key']
        save_docker_certs(addr.split(':', 1)[0], ca.read(), cert.read(), key.read())
    finally:
        ca.close()
        cert.close()
        key.close()

    try:
        client = get_docker_client(addr, force_flush=True)
        info = client.info()
    except Exception:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Docker daemon error on host %s' % addr)

    if not Host.create(pod, addr, info['Name'], info['ID'], info['NCPU'], info['MemTotal']):
        raise EruAbortException(consts.HTTP_BAD_REQUEST)
    return consts.HTTP_CREATED, {'r':0, 'msg': consts.OK}
开发者ID:BlueKarl,项目名称:eru-core,代码行数:31,代码来源:sys.py

示例4: _get_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def _get_pod(id_or_name):
    if id_or_name.isdigit():
        pod = Pod.get(int(id_or_name))
    else:
        pod = Pod.get_by_name(id_or_name)
    if not pod:
        abort(404, 'Pod %s not found' % id_or_name)
    return pod
开发者ID:CMGS,项目名称:eru-core,代码行数:10,代码来源:pod.py

示例5: get_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def get_pod(id_or_name):
    if id_or_name.isdigit():
        pod = Pod.get(int(id_or_name))
    else:
        pod = Pod.get_by_name(id_or_name)
    if not pod:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Pod %s not found' % id_or_name)
    return pod
开发者ID:linzhonghong,项目名称:eru-core,代码行数:10,代码来源:pod.py

示例6: list_pod_hosts

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def list_pod_hosts(id_or_name):
    if id_or_name.isdigit():
        pod = Pod.get(int(id_or_name))
    else:
        pod = Pod.get_by_name(id_or_name)
    if not pod:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Pod %s not found' % id_or_name)
    show_all = request.args.get('all', type=bool, default=False)
    return pod.list_hosts(g.start, g.limit, show_all=show_all)
开发者ID:linzhonghong,项目名称:eru-core,代码行数:11,代码来源:pod.py

示例7: assign_pod_to_group

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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}
开发者ID:lcsandy,项目名称:eru-core,代码行数:13,代码来源:sys.py

示例8: group_max_containers

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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)}
开发者ID:marswon,项目名称:eru-core,代码行数:14,代码来源:sys.py

示例9: assign_pod_to_group

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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}
开发者ID:BlueKarl,项目名称:eru-core,代码行数:15,代码来源:sys.py

示例10: assign_pod_to_group

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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}
开发者ID:CMGS,项目名称:eru-core,代码行数:15,代码来源:sys.py

示例11: group_max_containers

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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)}
开发者ID:CMGS,项目名称:eru-core,代码行数:15,代码来源:sys.py

示例12: test_group_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def test_group_pod(test_db):
    p1 = Pod.create('pod1', 'pod1')
    p2 = Pod.create('pod1', 'pod1')
    assert p1 is not None
    assert p1.name == 'pod1'
    assert p2 is None

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

    assert p3.get_free_public_hosts(10) == []
    assert get_max_container_count(p3, 1, 2) == 0
    assert centralized_schedule(p3, 1, 1, 2) == {}
开发者ID:timfeirg,项目名称:eru-core,代码行数:15,代码来源:test_models.py

示例13: create_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def create_host():
    data = request.get_json()
    addr = data['addr']

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

    client = get_docker_client(addr)
    info = client.info()
    if not Host.create(pod, addr, info['Name'], info['ID'], info['NCPU'], info['MemTotal']):
        raise EruAbortException(code.HTTP_BAD_REQUEST)
    return {'r':0, 'msg': code.OK}
开发者ID:lcsandy,项目名称:eru-core,代码行数:15,代码来源:sys.py

示例14: group_max_containers

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
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)}
开发者ID:BlueKarl,项目名称:eru-core,代码行数:18,代码来源:sys.py

示例15: create_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import get_by_name [as 别名]
def create_host():
    data = request.get_json()
    addr = data['addr']

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

    try:
        client = get_docker_client(addr)
        info = client.info()
    except Exception:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Docker daemon error on host %s' % addr)

    if not Host.create(pod, addr, info['Name'], info['ID'], info['NCPU'], info['MemTotal']):
        raise EruAbortException(consts.HTTP_BAD_REQUEST)
    return consts.HTTP_CREATED, {'r':0, 'msg': consts.OK}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:19,代码来源:sys.py


注:本文中的eru.models.Pod.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。