本文整理汇总了Python中eru.models.Network.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Network.get_by_name方法的具体用法?Python Network.get_by_name怎么用?Python Network.get_by_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eru.models.Network
的用法示例。
在下文中一共展示了Network.get_by_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_network
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_name [as 别名]
def get_network(id_or_name):
if id_or_name.isdigit():
n = Network.get(id_or_name)
else:
n = Network.get_by_name(id_or_name)
if not n:
abort(404, 'Network %s not found' % id_or_name)
return n
示例2: macvlan
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_name [as 别名]
def macvlan(id_or_name):
host = _get_host(id_or_name)
if request.method == 'GET':
return host.list_vlans(g.start, g.limit)
data = request.get_json()
netname = data.get('network', '')
network = Network.get_by_name(netname)
if not network:
abort(404, 'Network not found')
vg = VLanGateway.get_by_host_and_network(host.id, network.id)
if request.method == 'POST':
return vg or network.acquire_gateway_ip(host)
elif request.method == 'DELETE':
if vg:
vg.release()
return {'r': 0, 'msg': consts.OK}
示例3: bind_network
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_name [as 别名]
def bind_network(cid):
data = request.get_json()
appname = data.get('appname')
c = Container.get_by_container_id(cid)
if not (c and c.is_alive):
raise EruAbortException(consts.HTTP_NOT_FOUND, 'Container %s not found' % cid)
if c.appname != appname:
raise EruAbortException(consts.HTTP_NOT_FOUND, 'Container does not belong to app')
network_names = data.get('networks', [])
networks = filter(None, [Network.get_by_name(n) for n in network_names])
if not networks:
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'network empty')
ips = filter(None, [n.acquire_ip() for n in networks])
if not ips:
raise EruAbortException(consts.HTTP_BAD_REQUEST, 'no ip available')
nid = max([ip.network_id for ip in c.ips.all()] + [-1]) + 1
bind_container_ip(c, ips, nid=nid)
for ip in ips:
ip.assigned_to_container(c)
return {'r': 0, 'msg': ips}
示例4: get_network_by_name
# 需要导入模块: from eru.models import Network [as 别名]
# 或者: from eru.models.Network import get_by_name [as 别名]
def get_network_by_name(network_name):
n = Network.get_by_name(network_name)
if not n:
raise EruAbortException(consts.HTTP_NOT_FOUND, 'Network %s not found' % network_name)
return n