本文整理汇总了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
示例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}
示例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}
示例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