Ejemplo n.º 1
0
def create_private():
    data = request.get_json()
    pod, _, version = _get_instances(**data)

    ncore, nshare = pod.get_core_allocation(float(data['ncore']))
    ports = data.get('ports', [])
    args = data.get('args', [])
    strategy = data.get('strategy', 'average')

    callback_url = data.get('callback_url', '')
    if callback_url and not is_strict_url(callback_url):
        abort(400, 'callback_url must start with http:// or https://')

    ncontainer = int(data['ncontainer'])
    if not ncontainer:
        abort(400, 'ncontainer must be > 0')

    networks = [ipam.get_pool(n) for n in data.get('networks', [])]
    spec_ips = data.get('spec_ips', [])
    appconfig = version.appconfig

    entrypoint = data['entrypoint']
    if entrypoint not in appconfig.entrypoints:
        abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)

    hostname = data.get('hostname', '')
    host = hostname and Host.get_by_name(hostname) or None

    task_ids, watch_keys = [], []
    host_cores = _get_strategy(strategy)(pod, ncontainer, ncore, nshare, host)
    if not host_cores:
        abort(400, 'Not enough core resources')

    for (host, container_count), cores in host_cores.iteritems():
        t = _create_task(
            version,
            host,
            container_count,
            cores,
            nshare,
            networks,
            ports,
            args,
            spec_ips,
            entrypoint,
            data['env'],
            image=data.get('image', ''),
            callback_url=callback_url,
        )
        if not t:
            continue

        host.occupy_cores(cores, nshare)
        task_ids.append(t.id)
        watch_keys.append(t.result_key)

    return {'tasks': task_ids, 'watch_keys': watch_keys}
Ejemplo n.º 2
0
def create_public(group_name, pod_name, appname):
    data = request.get_json()
    vstr = data['version']
    group, pod, _, version = validate_instance(group_name, pod_name, appname, vstr)

    ports = data.get('ports', [])
    args = data.get('args', [])

    callback_url = data.get('callback_url', '')
    if callback_url and not is_strict_url(callback_url):
        abort(400, 'callback_url must starts with http:// or https://')

    networks = Network.get_multi(data.get('networks', []))
    spec_ips = data.get('spec_ips', [])
    appconfig = version.appconfig

    ncontainer = int(data['ncontainer'])
    if not ncontainer:
        abort(400, 'ncontainer must be > 0')

    entrypoint = data['entrypoint']
    if entrypoint not in appconfig.entrypoints:
        abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)

    ts, keys = [], []
    with rds.lock('%s:%s' % (group_name, pod_name)):
        hosts = pod.get_free_public_hosts(ncontainer)
        for host in itertools.islice(itertools.cycle(hosts), ncontainer):
            t = _create_task(
                version,
                host,
                1,
                {},
                0,
                networks,
                ports,
                args,
                spec_ips,
                data['entrypoint'],
                data['env'],
                image=data.get('image', ''),
                callback_url=callback_url,
            )
            if not t:
                continue
            ts.append(t.id)
            keys.append(t.result_key)

    return {'r':0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
Ejemplo n.º 3
0
def create_public():
    data = request.get_json()
    pod, _, version = _get_instances(**data)

    ports = data.get('ports', [])
    args = data.get('args', [])

    callback_url = data.get('callback_url', '')
    if callback_url and not is_strict_url(callback_url):
        abort(400, 'callback_url must starts with http:// or https://')

    networks = [ipam.get_pool(n) for n in data.get('networks', [])]
    spec_ips = data.get('spec_ips', [])
    appconfig = version.appconfig

    ncontainer = int(data['ncontainer'])
    if not ncontainer:
        abort(400, 'ncontainer must be > 0')

    entrypoint = data['entrypoint']
    if entrypoint not in appconfig.entrypoints:
        abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)

    task_ids, watch_keys = [], []
    hosts = pod.get_free_public_hosts(ncontainer)
    for host in itertools.islice(itertools.cycle(hosts), ncontainer):
        t = _create_task(
            version,
            host,
            1,
            {},
            0,
            networks,
            ports,
            args,
            spec_ips,
            data['entrypoint'],
            data['env'],
            image=data.get('image', ''),
            callback_url=callback_url,
        )
        if not t:
            continue
        task_ids.append(t.id)
        watch_keys.append(t.result_key)

    return {'tasks': task_ids, 'watch_keys': watch_keys}
Ejemplo n.º 4
0
def create_private(group_name, pod_name, appname):
    data = request.get_json()
    vstr = data['version']
    group, pod, _, version = validate_instance(group_name, pod_name, appname, vstr)

    # TODO check if group has this pod
    ncore, nshare = pod.get_core_allocation(float(data['ncore']))
    ports = data.get('ports', [])
    args = data.get('args', [])
    strategy = data.get('strategy', 'average')

    callback_url = data.get('callback_url', '')
    if callback_url and not is_strict_url(callback_url):
        abort(400, 'callback_url must start with http:// or https://')

    ncontainer = int(data['ncontainer'])
    if not ncontainer:
        abort(400, 'ncontainer must be > 0')

    networks = Network.get_multi(data.get('networks', []))
    spec_ips = data.get('spec_ips', [])
    appconfig = version.appconfig

    entrypoint = data['entrypoint']
    if entrypoint not in appconfig.entrypoints:
        abort(400, 'Entrypoint %s not in app.yaml' % entrypoint)

    hostname = data.get('hostname', '')
    host = hostname and Host.get_by_name(hostname) or None
    if host and not (host.group_id == group.id and host.pod_id == pod.id):
        abort(400, 'Host must belong to this pod and group')

    ts, keys = [], []
    with rds.lock('%s:%s' % (group_name, pod_name)):
        host_cores = _get_strategy(strategy)(group, pod, ncontainer, ncore, nshare, host)
        if not host_cores:
            abort(400, 'Not enough core resources')

        for (host, container_count), cores in host_cores.iteritems():
            t = _create_task(
                version,
                host,
                container_count,
                cores,
                nshare,
                networks,
                ports,
                args,
                spec_ips,
                entrypoint,
                data['env'],
                image=data.get('image', ''),
                callback_url=callback_url,
            )
            if not t:
                continue

            host.occupy_cores(cores, nshare)
            ts.append(t.id)
            keys.append(t.result_key)

    return {'r': 0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}