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


Python Task.create方法代码示例

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


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

示例1: rm_containers

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def rm_containers():
    cids = request.get_json()['cids']

    if not all(len(cid) >= 7 for cid in cids):
        abort(400, 'must given at least 7 chars for container_id')

    version_dict = {}
    for cid in cids:
        container = Container.get_by_container_id(cid)
        if not container:
            continue
        version_dict.setdefault((container.version, container.host), []).append(container)

    ts, watch_keys = [], []
    for (version, host), containers in version_dict.iteritems():
        cids = [c.id for c in containers]
        task = Task.create(consts.TASK_REMOVE, version, host, {'container_ids': cids})

        all_host_cids = [c.id for c in Container.get_multi_by_host(host) if c and c.version_id == version.id]
        need_to_delete_image = set(cids) == set(all_host_cids)

        remove_containers.apply_async(
            args=(task.id, cids, need_to_delete_image),
            task_id='task:%d' % task.id
        )
        ts.append(task.id)
        watch_keys.append(task.result_key)
    return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': watch_keys}
开发者ID:CMGS,项目名称:eru-core,代码行数:30,代码来源:deploy.py

示例2: _create_task

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def _create_task(type_, version, host, ncontainer, cores, nshare, networks, spec_ips, entrypoint, env, image=""):
    network_ids = [n.id for n in networks]
    task_props = {
        "ncontainer": ncontainer,
        "entrypoint": entrypoint,
        "env": env,
        "full_cores": [c.label for c in cores.get("full", [])],
        "part_cores": [c.label for c in cores.get("part", [])],
        "nshare": nshare,
        "networks": network_ids,
        "image": image,
    }
    task = Task.create(type_, version, host, task_props)
    if not task:
        return None

    try:
        create_containers_with_macvlan.apply_async(
            args=(task.id, ncontainer, nshare, cores, network_ids, spec_ips), task_id="task:%d" % task.id
        )
    except Exception as e:
        logger.exception(e)
        host.release_cores(cores)

    return task
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:27,代码来源:deploy.py

示例3: build_image_v2

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def build_image_v2():
    # form post
    appname = request.form.get('appname', default='')
    version = request.form.get('version', default='')
    base = request.form.get('base', default='')
    if not base:
        abort(400, 'base image must be set')
    _, version = _get_app_and_version(appname, version)

    if ':' not in base:
        base = base + ':latest'

    host = Host.get_random_public_host()
    if not host:
        abort(406, 'no host is available')

    # if no artifacts.zip is set
    # ignore and just do the cloning and building
    file_path = None
    if 'artifacts.zip' in request.files:
        f = request.files['artifacts.zip']
        file_path = os.path.join(tempfile.mkdtemp(), secure_filename(f.filename))
        f.save(file_path)

    task = Task.create(TASK_BUILD, version, host, {'base': base})
    build_docker_image.apply_async(
        args=(task.id, base, file_path),
        task_id='task:%d' % task.id
    )
    return {'task': task.id, 'watch_key': task.result_key}
开发者ID:timfeirg,项目名称:eru-core,代码行数:32,代码来源:deploy.py

示例4: _create_task

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def _create_task(type_, version, host, ncontainer,
    cores, nshare, networks, spec_ips, entrypoint, env, image=''):
    network_ids = [n.id for n in networks]
    task_props = {
        'ncontainer': ncontainer,
        'entrypoint': entrypoint,
        'env': env,
        'full_cores': [c.label for c in cores.get('full', [])],
        'part_cores': [c.label for c in cores.get('part', [])],
        'nshare': nshare,
        'networks': network_ids,
        'image': image,
    }
    task = Task.create(type_, version, host, task_props)
    if not task:
        return None

    try:
        create_containers_with_macvlan.apply_async(
            args=(task.id, ncontainer, nshare, cores, network_ids, spec_ips),
            task_id='task:%d' % task.id
        )
    except Exception as e:
        logger.exception(e)
        host.release_cores(cores)

    return task
开发者ID:linzhonghong,项目名称:eru-core,代码行数:29,代码来源:deploy.py

示例5: build_image

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def build_image(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, application, version = validate_instance(group_name, pod_name, appname, data["version"])
    # TODO
    # 这个group可以用这个pod不?
    # 这个group可以build这个version不?
    base = data["base"]
    host = pod.get_random_host()
    task = Task.create(consts.TASK_BUILD, version, host, {"base": base})
    build_docker_image.apply_async(args=(task.id, base), task_id="task:%d" % task.id)
    return {"r": 0, "msg": "ok", "task": task.id, "watch_key": task.result_key}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:13,代码来源:deploy.py

示例6: build_image

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def build_image(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, _, version = validate_instance(group_name, pod_name, appname, data['version'])

    base = data['base']
    if ':' not in base:
        base = base + ':latest'

    host = Host.get_random_public_host() or pod.get_random_host()
    task = Task.create(consts.TASK_BUILD, version, host, {'base': base})
    build_docker_image.apply_async(
        args=(task.id, base),
        task_id='task:%d' % task.id
    )
    return {'r': 0, 'msg': 'ok', 'task': task.id, 'watch_key': task.result_key}
开发者ID:CMGS,项目名称:eru-core,代码行数:17,代码来源:deploy.py

示例7: offline_version

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def offline_version(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, application, version = validate_instance(group_name, pod_name, appname, data["version"])
    d = {}
    ts, keys = [], []
    for container in version.containers.all():
        d.setdefault(container.host, []).append(container)
    for host, containers in d.iteritems():
        cids = [c.id for c in containers]
        task_props = {"container_ids": cids}
        task = Task.create(consts.TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(args=(task.id, cids, True), task_id="task:%d" % task.id)
        ts.append(task.id)
        keys.append(task.result_key)
    return {"r": 0, "msg": "ok", "tasks": ts, "watch_keys": keys}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:17,代码来源:deploy.py

示例8: build_image

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def build_image(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, data['version'])
    # TODO
    # 这个group可以用这个pod不?
    # 这个group可以build这个version不?
    base = data['base']
    host = pod.get_random_host()
    task = Task.create(consts.TASK_BUILD, version, host, {'base': base})
    build_docker_image.apply_async(
        args=(task.id, base),
        task_id='task:%d' % task.id
    )
    return {'r': 0, 'msg': 'ok', 'task': task.id, 'watch_key': task.result_key}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:17,代码来源:deploy.py

示例9: rm_containers

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def rm_containers():
    cids = request.get_json()["cids"]
    version_dict = {}
    ts, watch_keys = [], []
    for cid in cids:
        container = Container.get_by_container_id(cid)
        if not container:
            continue
        version_dict.setdefault((container.version, container.host), []).append(container)
    for (version, host), containers in version_dict.iteritems():
        cids = [c.id for c in containers]
        task_props = {"container_ids": cids}
        task = Task.create(consts.TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(args=(task.id, cids, False), task_id="task:%d" % task.id)
        ts.append(task.id)
        watch_keys.append(task.result_key)
    return {"r": 0, "msg": "ok", "tasks": ts, "watch_keys": watch_keys}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:19,代码来源:deploy.py

示例10: _create_task

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def _create_task(version, host, ncontainer,
    cores, nshare, networks, ports, args, spec_ips, route, entrypoint, env, image=''):
    network_ids = [n.id for n in networks]

    # host 模式不允许绑定 vlan
    entry = version.appconfig['entrypoints'][entrypoint]
    if entry.get('network_mode') == 'host':
        network_ids = []

    task_props = {
        'ncontainer': ncontainer,
        'entrypoint': entrypoint,
        'env': env,
        'full_cores': [c.label for c in cores.get('full', [])],
        'part_cores': [c.label for c in cores.get('part', [])],
        'ports': ports,
        'args': args,
        'nshare': nshare,
        'networks': network_ids,
        'image': image,
        'route': route,
    }
    task = Task.create(consts.TASK_CREATE, version, host, task_props)
    if not task:
        return None

    if cores:
        try:
            create_containers_with_macvlan.apply_async(
                args=(task.id, ncontainer, nshare, cores, network_ids, spec_ips),
                task_id='task:%d' % task.id
            )
        except Exception as e:
            logger.exception(e)
            host.release_cores(cores)
    else:
        try:
            create_containers_with_macvlan_public.apply_async(
                args=(task.id, ncontainer, nshare, network_ids, spec_ips),
                task_id='task:%d' % task.id
            )
        except Exception as e:
            logger.exception(e)

    return task
开发者ID:sdgdsffdsfff,项目名称:eru-core,代码行数:47,代码来源:deploy.py

示例11: build_image

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def build_image():
    data = request.get_json()
    _, version = _get_app_and_version(**data)

    base = data['base']
    if ':' not in base:
        base = base + ':latest'

    host = Host.get_random_public_host()
    if not host:
        abort(406, 'no host is available')

    task = Task.create(TASK_BUILD, version, host, {'base': base})
    build_docker_image.apply_async(
        args=(task.id, base, None),
        task_id='task:%d' % task.id
    )
    return {'task': task.id, 'watch_key': task.result_key}
开发者ID:timfeirg,项目名称:eru-core,代码行数:20,代码来源:deploy.py

示例12: rm_containers

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def rm_containers(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, data['version'])
    host = Host.get_by_name(data['host'])
    # 直接拿前ncontainer个吧, 反正他们都等价的
    containers = host.get_containers_by_version(version)[:int(data['ncontainer'])]
    try:
        cids = [c.id for c in containers]
        task_props = {'container_ids': cids}
        task = Task.create(code.TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(
            args=(task.id, cids, False),
            task_id='task:%d' % task.id
        )
        return {'r': 0, 'msg': 'ok', 'task': task.id, 'watch_key': task.result_key}
    except Exception, e:
        logger.exception(e)
        return {'r': 1, 'msg': str(e), 'task': None, 'watch_key': None}
开发者ID:marswon,项目名称:eru-core,代码行数:21,代码来源:deploy.py

示例13: offline_version

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def offline_version(group_name, pod_name, appname):
    data = request.get_json()
    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, data['version'])
    d = {}
    ts, keys = [], []
    for container in version.containers.all():
        d.setdefault(container.host, []).append(container)
    for host, containers in d.iteritems():
        cids = [c.id for c in containers]
        task_props = {'container_ids': cids}
        task = Task.create(consts.TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(
            args=(task.id, cids, True),
            task_id='task:%d' % task.id
        )
        ts.append(task.id)
        keys.append(task.result_key)
    return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:21,代码来源:deploy.py

示例14: offline_version

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def offline_version():
    data = request.get_json()
    pod, _, version = _get_instances(**data)

    d = {}
    for container in version.containers.all():
        d.setdefault(container.host, []).append(container)

    task_ids, watch_keys = [], []
    for host, containers in d.iteritems():
        cids = [c.id for c in containers]
        task = Task.create(TASK_REMOVE, version, host, {'container_ids': cids})
        remove_containers.apply_async(
            args=(task.id, cids, True),
            task_id='task:%d' % task.id
        )
        task_ids.append(task.id)
        watch_keys.append(task.result_key)
    return {'tasks': task_ids, 'watch_keys': watch_keys}
开发者ID:timfeirg,项目名称:eru-core,代码行数:21,代码来源:deploy.py

示例15: rm_containers

# 需要导入模块: from eru.models import Task [as 别名]
# 或者: from eru.models.Task import create [as 别名]
def rm_containers():
    cids = request.get_json()['cids']
    version_dict = {}
    ts, watch_keys = [], []
    for cid in cids:
        container = Container.get_by_container_id(cid)
        if not container:
            continue
        version_dict.setdefault((container.version, container.host), []).append(container)
    for (version, host), containers in version_dict.iteritems():
        cids = [c.id for c in containers]
        task_props = {'container_ids': cids}
        task = Task.create(consts.TASK_REMOVE, version, host, task_props)
        remove_containers.apply_async(
            args=(task.id, cids, False),
            task_id='task:%d' % task.id
        )
        ts.append(task.id)
        watch_keys.append(task.result_key)
    return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': watch_keys}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:22,代码来源:deploy.py


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