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


Python Pod.create方法代码示例

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


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

示例1: test_group_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [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

示例2: _create_data

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def _create_data(core_share, max_share_core, host_count):
    group = Group.create('group', 'group')
    pod = Pod.create('pod', 'pod', core_share, max_share_core)
    for _ in range(host_count):
        host = Host.create(pod, random_ipv4(), random_string(), random_uuid(), 16, 4096)
        host.assigned_to_group(group)
    return group, pod
开发者ID:DoubleSpout,项目名称:eru-core,代码行数:9,代码来源:test_scheduler.py

示例3: test_container_release_cores

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_container_release_cores(test_db):
    a = App.get_or_create('app', 'http://git.hunantv.com/group/app.git')
    v = a.add_version(random_sha1())
    p = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(p, random_ipv4(), random_string(), random_uuid(), 200, 0)

    for core in host.cores:
        assert core.host_id == host.id
        assert core.remain == 10

    containers = []
    
    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        used_cores = {'full': fcores, 'part': pcores}
        host.occupy_cores(used_cores, 5)
        c = Container.create(random_sha1(), host, v, random_string(), 'entrypoint', used_cores, 'env', nshare=5)
        containers.append(c)

    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        for core in fcores:
            assert core.remain == 0
        for core in pcores:
            assert core.remain == 5

    for c in containers:
        c.delete()

    cores = sorted(host.cores, key=operator.attrgetter('label'))
    for fcores, pcores in zip(chunked(cores[:100], 10), chunked(cores[100:], 10)):
        for core in fcores:
            assert core.remain == 10
        for core in pcores:
            assert core.remain == 10
开发者ID:timfeirg,项目名称:eru-core,代码行数:37,代码来源:test_models.py

示例4: create_local_test_data

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def create_local_test_data(private=False):
    appyaml = {
        'appname': 'blueberry',
        'entrypoints': {
            'web': {
                'cmd': 'python app.py',
                'ports': ['5000/tcp'],
            },
            'daemon': {
                'cmd': 'python daemon.py',
            },
            'service': {
                'cmd': 'python service.py'
            },
        },
        'build': 'pip install -r ./requirements.txt',
    }
    app = App.get_or_create('blueberry', 'http://git.hunantv.com/tonic/blueberry.git', 'token')
    version = app.add_version('abe23812aeb50a17a2509c02a28423462161d306')
    appconfig = version.appconfig
    appconfig.update(**appyaml)
    appconfig.save()

    group = Group.create('group', 'group')
    pod = Pod.create('pod', 'pod')
    pod.assigned_to_group(group)

    c = docker.Client(**kwargs_from_env(assert_hostname=False))
    r = c.info()
    host = Host.create(pod, '192.168.59.103:2376', r['Name'], r['ID'], r['NCPU'], r['MemTotal'])

    if private:
        host.assigned_to_group(group)

    return app, version, group, pod, host
开发者ID:lcsandy,项目名称:eru-core,代码行数:37,代码来源:prepare.py

示例5: test_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_pod(test_db):
    p1 = Pod.create('p1', 'p1', core_share=10)
    assert p1 is not None
    assert p1.get_core_allocation(1) == (1, 0)
    assert p1.get_core_allocation(1.5) == (1, 5)
    assert p1.get_core_allocation(2) == (2, 0)
    assert p1.get_core_allocation(2.8) == (2, 8)
    assert p1.get_core_allocation(0.8) == (0, 8)
    assert p1.get_core_allocation(0.1) == (0, 1)

    p2 = Pod.create('p2', 'p2', core_share=100)
    assert p2 is not None
    assert p2.get_core_allocation(1) == (1, 0)
    assert p2.get_core_allocation(1.5) == (1, 50)
    assert p2.get_core_allocation(2) == (2, 0)
    assert p2.get_core_allocation(2.8) == (2, 80)
    assert p2.get_core_allocation(0.81) == (0, 81)
    assert p2.get_core_allocation(0.14) == (0, 14)
开发者ID:timfeirg,项目名称:eru-core,代码行数:20,代码来源:test_models.py

示例6: create_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def create_pod():
    data = request.get_json()
    if not Pod.create(
            data['name'],
            data.get('description', ''),
            data.get('core_share', DEFAULT_CORE_SHARE),
            data.get('max_share_core', DEFAULT_MAX_SHARE_CORE),
    ):
        raise EruAbortException(code.HTTP_BAD_REQUEST)
    return {'r':0, 'msg': code.OK}
开发者ID:lcsandy,项目名称:eru-core,代码行数:12,代码来源:sys.py

示例7: test_get_max_container_count_single_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_get_max_container_count_single_host(test_db):
    pod = Pod.create('pod', 'pod', 10, -1)
    Host.create(pod, random_ipv4(), random_string(), random_uuid(), 64, 4096)

    assert get_max_container_count(pod, ncore=1, nshare=0) == 64
    assert get_max_container_count(pod, ncore=2, nshare=0) == 32
    assert get_max_container_count(pod, ncore=3, nshare=0) == 21
    assert get_max_container_count(pod, ncore=4, nshare=0) == 16
    assert get_max_container_count(pod, ncore=5, nshare=0) == 12
    assert get_max_container_count(pod, ncore=1, nshare=5) == 42
    assert get_max_container_count(pod, ncore=2, nshare=5) == 25
开发者ID:timfeirg,项目名称:eru-core,代码行数:13,代码来源:test_scheduler.py

示例8: create_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def create_pod():
    data = request.get_json()
    if not Pod.create(
            data['name'],
            data.get('description', ''),
            data.get('core_share', DEFAULT_CORE_SHARE),
            data.get('max_share_core', DEFAULT_MAX_SHARE_CORE),
    ):
        abort(400, 'Pod create failed')
    _log.info('Pod create succeeded (name=%s, desc=%s)', data['name'], data.get('description', ''))
    return 201, DEFAULT_RETURN_VALUE
开发者ID:timfeirg,项目名称:eru-core,代码行数:13,代码来源:pod.py

示例9: create_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def create_pod():
    data = request.get_json()
    if not Pod.create(
            data['name'],
            data.get('description', ''),
            data.get('core_share', DEFAULT_CORE_SHARE),
            data.get('max_share_core', DEFAULT_MAX_SHARE_CORE),
    ):
        raise EruAbortException(consts.HTTP_BAD_REQUEST, 'Pod create failed')
    current_app.logger.info('Pod create succeeded (name=%s, desc=%s)',
            data['name'], data.get('description', ''))
    return consts.HTTP_CREATED, {'r':0, 'msg': consts.OK}
开发者ID:BlueKarl,项目名称:eru-core,代码行数:14,代码来源:sys.py

示例10: create_pod

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def create_pod():
    data = request.get_json()
    if not Pod.create(
            data['name'],
            data.get('description', ''),
            data.get('core_share', DEFAULT_CORE_SHARE),
            data.get('max_share_core', DEFAULT_MAX_SHARE_CORE),
    ):
        abort(400, 'Pod create failed')
    current_app.logger.info('Pod create succeeded (name=%s, desc=%s)',
            data['name'], data.get('description', ''))
    return 201, {'r':0, 'msg': consts.OK}
开发者ID:CMGS,项目名称:eru-core,代码行数:14,代码来源:sys.py

示例11: test_container_transform

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_container_transform(test_db):
    a = App.get_or_create('app', 'http://git.hunantv.com/group/app.git', '')
    assert a is not None

    v = a.add_version(random_sha1())
    v2 = a.add_version(random_sha1())
    assert v is not None
    assert v.app.id == a.id
    assert v.name == a.name
    assert len(v.containers.all()) == 0
    assert len(v.tasks.all()) == 0

    g = Group.create('group', 'group')
    p = Pod.create('pod', 'pod')
    assert p.assigned_to_group(g)
    hosts = [Host.create(p, random_ipv4(), random_string(prefix='host'),
        random_uuid(), 4, 4096) for i in range(6)]

    for host in hosts[:3]:
        host.assigned_to_group(g)

    assert g.get_max_containers(p, 3, 0) == 3
    host_cores = g.get_free_cores(p, 3, 3, 0)
    assert len(host_cores) == 3

    containers = []
    for (host, count), cores in host_cores.iteritems():
        cores_per_container = len(cores) / count
        for i in range(count):
            cid = random_sha1()
            used_cores = {'full': cores['full'][i*cores_per_container:(i+1)*cores_per_container]}
            c = Container.create(cid, host, v, random_string(), 'entrypoint', used_cores, 'env')
            assert c is not None
            containers.append(c)
        host.occupy_cores(cores, 0)

    for host in g.private_hosts.all():
        assert len(host.get_free_cores()[0]) == 1
        assert len(host.containers.all()) == 1
        assert host.count == 1

    assert len(containers) == 3
    assert len(v.containers.all()) == 3

    cids = [c.container_id for c in containers]
    for c in containers:
        host = c.host
        cid = c.container_id
        c.transform(v2, random_sha1(), random_string())
        assert c.container_id != cid

    new_cids = [c.container_id for c in containers]
    assert new_cids != cids
开发者ID:lcsandy,项目名称:eru-core,代码行数:55,代码来源:test_models.py

示例12: test_get_max_container_count_single_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_get_max_container_count_single_host(test_db):
    group = Group.create('group', 'group')
    pod = Pod.create('pod', 'pod', 10, -1)
    host = Host.create(pod, random_ipv4(), random_string(), random_uuid(), 64, 4096)
    host.assigned_to_group(group)

    assert get_max_container_count(group, pod, ncore=1, nshare=0) == 64
    assert get_max_container_count(group, pod, ncore=2, nshare=0) == 32
    assert get_max_container_count(group, pod, ncore=3, nshare=0) == 21
    assert get_max_container_count(group, pod, ncore=4, nshare=0) == 16
    assert get_max_container_count(group, pod, ncore=5, nshare=0) == 12
    assert get_max_container_count(group, pod, ncore=1, nshare=5) == 42
    assert get_max_container_count(group, pod, ncore=2, nshare=5) == 25
开发者ID:CMGS,项目名称:eru-core,代码行数:15,代码来源:test_scheduler.py

示例13: test_network

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
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,代码行数:53,代码来源:test_models.py

示例14: test_group_pod

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

示例15: test_host

# 需要导入模块: from eru.models import Pod [as 别名]
# 或者: from eru.models.Pod import create [as 别名]
def test_host(test_db):
    g = Group.create('group', 'group')
    p = Pod.create('pod', 'pod')
    assert p.assigned_to_group(g)
    hosts = [Host.create(p, random_ipv4(), random_string(prefix='host'),
        random_uuid(), 4, 4096) for i in range(6)]
    for host in hosts:
        assert host is not None
        assert len(host.cores.all()) == 4
        assert len(host.get_free_cores()) == 4

    assert len(g.private_hosts.all()) == 0
    assert g.get_max_containers(p, 1) == 0
    assert g.get_free_cores(p, 1, 1) == {}

    for host in hosts[:3]:
        host.assigned_to_group(g)
    host_ids1 = {h.id for h in hosts[:3]}
    host_ids2 = {h.id for h in hosts[3:]}

    assert len(g.private_hosts.all()) == 3
    assert g.get_max_containers(p, 1) == 12
    host_cores = g.get_free_cores(p, 12, 1)
    assert len(host_cores) == 3
    
    for (host, count), cores in host_cores.iteritems():
        assert host.id in host_ids1
        assert host.id not in host_ids2
        assert count == 4
        assert len(cores) == 4

    assert g.get_max_containers(p, 3) == 3
    host_cores = g.get_free_cores(p, 3, 3)
    assert len(host_cores) == 3

    for (host, count), cores in host_cores.iteritems():
        assert host.id in host_ids1
        assert host.id not in host_ids2
        assert count == 1
        assert len(cores) == 3

    assert g.get_max_containers(p, 2) == 6
    host_cores = g.get_free_cores(p, 4, 2)
    assert len(host_cores) == 2

    for (host, count), cores in host_cores.iteritems():
        assert host.id in host_ids1
        assert host.id not in host_ids2
        assert count == 2
        assert len(cores) == 4
开发者ID:marswon,项目名称:eru-core,代码行数:52,代码来源:test_models.py


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