本文整理匯總了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}