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


Python Network.create方法代码示例

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


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

示例1: test_network

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

    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,代码行数:27,代码来源:test_models.py

示例2: create_network

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

示例3: create_network

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

示例4: test_network

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


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