當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。