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


Python models.Network类代码示例

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


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

示例1: get_network

def get_network(id_or_name):
    if id_or_name.isdigit():
        n = Network.get(id_or_name)
    else:
        n = Network.get_by_name(id_or_name)
    if not n:
        abort(404, 'Network %s not found' % id_or_name)
    return n
开发者ID:CMGS,项目名称:eru-core,代码行数:8,代码来源:network.py

示例2: create_public

def create_public(group_name, pod_name, appname):
    """
    ncontainer: int container nums
    version: string deploy version
    expose: bool true or false, default true
    """
    data = request.get_json()

    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, data['version'])

    networks = Network.get_multi(data.get('networks', []))
    ncontainer = int(data['ncontainer'])
    appconfig = version.appconfig
    if not data['entrypoint'] in appconfig.entrypoints:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % data['entrypoint'])

    tasks_info = []
    with rds.lock('%s:%s' % (group_name, pod_name)):
        try:
            # 轮询, 尽可能均匀部署
            hosts = pod.get_free_public_hosts(ncontainer)
            for host in itertools.islice(itertools.cycle(hosts), ncontainer):
                tasks_info.append(
                    (version, host, 1, [], networks, data['entrypoint'], data['env'])
                )
        except Exception, e:
            logger.exception(e)
            raise EruAbortException(code.HTTP_BAD_REQUEST, str(e))
开发者ID:marswon,项目名称:eru-core,代码行数:29,代码来源:deploy.py

示例3: create_public

def create_public(group_name, pod_name, appname):
    """参数同private, 只是不能指定需要的核心数量"""
    data = request.get_json()

    if data.get('raw', ''):
        vstr = consts.RAW_VERSION_PLACEHOLDER
    else:
        vstr = data['version']

    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, vstr)

    networks = Network.get_multi(data.get('networks', []))
    spec_ips = data.get('spec_ips', [])
    ncontainer = int(data['ncontainer'])
    appconfig = version.appconfig
    if not data['entrypoint'] in appconfig.entrypoints:
        current_app.logger.error('Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)',
                data['entrypoint'], appname, version.short_sha)
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % data['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(consts.TASK_CREATE, version, host, 1,
                    {}, 0, networks, spec_ips, data['entrypoint'], data['env'],
                    image=data.get('image', ''))
            if not t:
                continue
            ts.append(t.id)
            keys.append(t.result_key)

    return {'r':0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:34,代码来源:deploy.py

示例4: create_public

def create_public(group_name, pod_name, appname):
    """参数同private, 只是不能指定需要的核心数量"""
    data = request.get_json()

    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, data['version'])

    networks = Network.get_multi(data.get('networks', []))
    ncontainer = int(data['ncontainer'])
    appconfig = version.appconfig
    if not data['entrypoint'] in appconfig.entrypoints:
        raise EruAbortException(code.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % data['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(code.TASK_CREATE, version, host, 1,
                    {}, 0, networks, data['entrypoint'], data['env'])
            if not t:
                continue
            ts.append(t.id)
            keys.append(t.result_key)

    return {'r':0, 'msg': 'ok', 'tasks': ts, 'watch_keys': keys}
开发者ID:mackjoner,项目名称:eru-core,代码行数:25,代码来源:deploy.py

示例5: test_network

def test_network(test_db):
    n = Network.create('net', '10.1.0.0/16')
    assert n is not None
    assert len(n.ips.all()) == 0
    assert n.hostmask_string == '16'
    assert n.pool_size == 65436
    assert n.used_count == 0

    ip = n.acquire_ip()
    assert ip is not None
    assert ip.network_id == n.id
    assert ip.vethname == ''
    assert not ip.container_id
    assert ip.hostmask == n.hostmask_string
    assert ip.vlan_seq_id == n.id
    assert ip.address.startswith('10.1')

    assert len(n.ips.all()) == 1
    assert n.pool_size == 65435
    assert n.used_count == 1

    ip.release()
    assert len(n.ips.all()) == 0
    assert n.pool_size == 65436
    assert n.used_count == 0
开发者ID:lcsandy,项目名称:eru-core,代码行数:25,代码来源:test_models.py

示例6: take_gateway

def take_gateway(netspace, ip, host):
    net = Network.get_by_netspace(netspace)
    if not net:
        print 'net %s not found' % netspace
        return
    ipnum = IPAddress(ip).value
    rds.srem(net.gatekey, ipnum)
    VLanGateway.create(ipnum, net.id, host.id)
    print '%s on %s --> %s done' % (ip, host.ip, netspace)
开发者ID:timfeirg,项目名称:eru-core,代码行数:9,代码来源:get_gateway.py

示例7: create_private

def create_private(group_name, pod_name, appname):
    """ncore: 需要的核心数, 可以是小数, 例如1.5个"""
    data = request.get_json()

    if data.get('raw', ''):
        vstr = consts.RAW_VERSION_PLACEHOLDER
    else:
        vstr = data['version']

    group, pod, application, version = validate_instance(group_name,
            pod_name, appname, vstr)

    # TODO check if group has this pod

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

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

    # 指定的host, 如果没有则按照编排分配host
    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):
        current_app.logger.error('Host must belong to pod/group (hostname=%s, pod=%s, group=%s)',
                host, pod_name, group_name)
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Host must belong to this pod and group')

    if not data['entrypoint'] in appconfig.entrypoints:
        current_app.logger.error('Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)',
                data['entrypoint'], appname, version.short_sha)
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Entrypoint %s not in app.yaml' % data['entrypoint'])

    ts, keys = [], []
    with rds.lock('%s:%s' % (group_name, pod_name)):
        host_cores = group.get_free_cores(pod, ncontainer, ncore, nshare, spec_host=host)
        if not host_cores:
            current_app.logger.error('Not enough cores (name=%s, version=%s, ncore=%s)',
                    appname, version.short_sha, data['ncore'])
            raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Not enough core resources')

        for (host, container_count), cores in host_cores.iteritems():
            t = _create_task(consts.TASK_CREATE, version, host, container_count,
                    cores, nshare, networks, spec_ips, data['entrypoint'], data['env'],
                    image=data.get('image', ''))
            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}
开发者ID:linzhonghong,项目名称:eru-core,代码行数:56,代码来源:deploy.py

示例8: check_addr

def check_addr(addr):
    """addr is like 10.20.0.1/16 or 10.100.3.12/24"""
    try:
        interface = IPv4Interface(addr)
    except AddressValueError:
        abort(400, 'Not valid interface')
    net = Network.get_by_netspace(interface.network.compressed)
    if not net:
        abort(400, 'Interface not found')
    return {'r': 0, 'msg': consts.OK, 'result': interface.ip in net}
开发者ID:CMGS,项目名称:eru-core,代码行数:10,代码来源:network.py

示例9: create_network

def create_network():
    data = request.get_json()
    n = Network.create(data['name'], data['netspace'])
    if not n:
        current_app.logger.info('Network create failed (name=%s, net=%s)',
                data['name'], data['netspace'])
        abort(400, 'Network create failed')
    current_app.logger.info('Network create succeeded (name=%s, net=%s)',
            data['name'], data['netspace'])
    return {'r': 0, 'msg': consts.OK}
开发者ID:CMGS,项目名称:eru-core,代码行数:10,代码来源:network.py

示例10: create_network

def create_network():
    data = request.get_json()
    n = Network.create(data['name'], data['netspace'])
    if not n:
        current_app.logger.info('Network create failed (name=%s, net=%s)',
                data['name'], data['netspace'])
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Network create failed')
    current_app.logger.info('Network create succeeded (name=%s, net=%s)',
            data['name'], data['netspace'])
    return {'r': 0, 'msg': consts.OK}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:10,代码来源:network.py

示例11: check_addr

def check_addr(addr):
    """addr is like 10.20.0.1/16 or 10.100.3.12/24"""
    try:
        interface = IPv4Interface(addr)
    except AddressValueError:
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Not valid interface')
    net = Network.get_by_netspace(interface.network.compressed)
    if not net:
        raise EruAbortException(consts.HTTP_NOT_FOUND, 'Interface not found')
    return {'r': 0, 'msg': consts.OK, 'result': interface.ip in net}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:10,代码来源:network.py

示例12: test_network

def test_network(test_db):
    n = Network.create('net', '10.1.0.0/16')
    assert n is not None
    assert len(n.ips.all()) == 0
    assert n.hostmask_string == '16'
    assert n.pool_size == 65436
    assert n.used_count == 0
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100

    ip = n.acquire_ip()
    assert ip is not None
    assert ip.network_id == n.id
    assert ip.vethname == ''
    assert not ip.container_id
    assert ip.hostmask == n.hostmask_string
    assert ip.vlan_seq_id == n.id
    assert ip.address.startswith('10.1')

    assert len(n.ips.all()) == 1
    assert n.pool_size == 65435
    assert n.used_count == 1

    ip.release()
    assert len(n.ips.all()) == 0
    assert n.pool_size == 65436
    assert n.used_count == 0

    p = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(p, random_ipv4(), random_string(prefix='host'), random_uuid(), 4, 4096)

    gate = n.acquire_gateway_ip(host)
    assert gate is not None
    assert gate.network_id == n.id
    assert gate.vlan_address.startswith('10.1.0.')
    assert gate.vlan_seq_id == n.id
    assert gate.name == 'vlan.%02d.br' % n.id

    g = VLanGateway.get_by_host_and_network(host.id, n.id)
    assert g is not None
    assert g.id == gate.id
    assert len(host.list_vlans()) == 1

    assert n.used_gate_count == 1
    assert n.gate_pool_size == 99

    gate.release()
    assert n.used_gate_count == 0
    assert n.gate_pool_size == 100
    assert VLanGateway.get_by_host_and_network(host.id, n.id) is None
    assert len(host.list_vlans()) == 0
开发者ID:timfeirg,项目名称:eru-core,代码行数:51,代码来源:test_models.py

示例13: create_public

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}
开发者ID:CMGS,项目名称:eru-core,代码行数:49,代码来源:deploy.py

示例14: macvlan

def macvlan(id_or_name):
    host = _get_host(id_or_name)
    if request.method == 'GET':
        return host.list_vlans(g.start, g.limit)

    data = request.get_json()
    netname = data.get('network', '')
    network = Network.get_by_name(netname)
    if not network:
        abort(404, 'Network not found')

    vg = VLanGateway.get_by_host_and_network(host.id, network.id)
    if request.method == 'POST':
        return vg or network.acquire_gateway_ip(host)
    elif request.method == 'DELETE':
        if vg:
            vg.release()
        return {'r': 0, 'msg': consts.OK}
开发者ID:CMGS,项目名称:eru-core,代码行数:18,代码来源:host.py

示例15: create_public

def create_public(group_name, pod_name, appname):
    """参数同private, 只是不能指定需要的核心数量"""
    data = request.get_json()

    if data.get("raw", ""):
        vstr = consts.RAW_VERSION_PLACEHOLDER
    else:
        vstr = data["version"]

    group, pod, application, version = validate_instance(group_name, pod_name, appname, vstr)

    networks = Network.get_multi(data.get("networks", []))
    spec_ips = data.get("spec_ips", [])
    ncontainer = int(data["ncontainer"])
    appconfig = version.appconfig
    if not data["entrypoint"] in appconfig.entrypoints:
        current_app.logger.error(
            "Entrypoint not in app.yaml (entry=%s, name=%s, version=%s)", data["entrypoint"], appname, version.short_sha
        )
        raise EruAbortException(consts.HTTP_BAD_REQUEST, "Entrypoint %s not in app.yaml" % data["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(
                consts.TASK_CREATE,
                version,
                host,
                1,
                {},
                0,
                networks,
                spec_ips,
                data["entrypoint"],
                data["env"],
                image=data.get("image", ""),
            )
            if not t:
                continue
            ts.append(t.id)
            keys.append(t.result_key)

    return {"r": 0, "msg": "ok", "tasks": ts, "watch_keys": keys}
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:44,代码来源:deploy.py


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