本文整理汇总了Python中eru.models.Network.get_by_netspace方法的典型用法代码示例。如果您正苦于以下问题:Python Network.get_by_netspace方法的具体用法?Python Network.get_by_netspace怎么用?Python Network.get_by_netspace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eru.models.Network
的用法示例。
在下文中一共展示了Network.get_by_netspace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take_gateway
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_netspace [as 别名]
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)
示例2: check_addr
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_netspace [as 别名]
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}
示例3: check_addr
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_netspace [as 别名]
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}