當前位置: 首頁>>代碼示例>>Python>>正文


Python Network.get_by_name方法代碼示例

本文整理匯總了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
開發者ID:CMGS,項目名稱:eru-core,代碼行數:10,代碼來源:network.py

示例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}
開發者ID:CMGS,項目名稱:eru-core,代碼行數:20,代碼來源:host.py

示例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}
開發者ID:sdgdsffdsfff,項目名稱:eru-core,代碼行數:25,代碼來源:container.py

示例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
開發者ID:DoubleSpout,項目名稱:eru-core,代碼行數:7,代碼來源:network.py


注:本文中的eru.models.Network.get_by_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。