当前位置: 首页>>代码示例>>Python>>正文


Python NetworkManager.get_node_networkgroups_ids方法代码示例

本文整理汇总了Python中nailgun.network.manager.NetworkManager.get_node_networkgroups_ids方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.get_node_networkgroups_ids方法的具体用法?Python NetworkManager.get_node_networkgroups_ids怎么用?Python NetworkManager.get_node_networkgroups_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nailgun.network.manager.NetworkManager的用法示例。


在下文中一共展示了NetworkManager.get_node_networkgroups_ids方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verify_data_correctness

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_node_networkgroups_ids [as 别名]
    def verify_data_correctness(cls, node):
        db_node = db().query(Node).filter_by(id=node['id']).first()
        if not db_node:
            raise errors.InvalidData(
                "There is no node with ID '{0}' in DB".format(node['id']),
                log_message=True
            )
        interfaces = node['interfaces']
        db_interfaces = db_node.nic_interfaces
        network_group_ids = NetworkManager.get_node_networkgroups_ids(db_node)

        bonded_eth_ids = set()
        for iface in interfaces:
            if iface['type'] == NETWORK_INTERFACE_TYPES.ether:
                db_iface = filter(
                    lambda i: i.id == iface['id'],
                    db_interfaces
                )
                if not db_iface:
                    raise errors.InvalidData(
                        "Node '{0}': there is no interface with ID '{1}'"
                        " in DB".format(node['id'], iface['id']),
                        log_message=True
                    )
            elif iface['type'] == NETWORK_INTERFACE_TYPES.bond:
                for slave in iface['slaves']:
                    iface_id = [i.id for i in db_interfaces
                                if i.name == slave['name']]
                    if iface_id:
                        if iface_id[0] in bonded_eth_ids:
                            raise errors.InvalidData(
                                "Node '{0}': interface '{1}' is used in bonds "
                                "more than once".format(
                                    node['id'], iface_id[0]),
                                log_message=True
                            )
                        bonded_eth_ids.add(iface_id[0])
                    else:
                        raise errors.InvalidData(
                            "Node '{0}': there is no interface '{1}' found "
                            "for bond '{2}' in DB".format(
                                node['id'], slave['name'], iface['name']),
                            log_message=True
                        )

            for net in iface['assigned_networks']:
                if net['id'] not in network_group_ids:
                    raise errors.InvalidData(
                        "Network '{0}' doesn't exist for node {1}".format(
                            net['id'], node['id']),
                        log_message=True
                    )
                network_group_ids.remove(net['id'])

        if network_group_ids:
            str_ng_ids = ["'" + str(ng_id) + "'"
                          for ng_id in network_group_ids]
            raise errors.InvalidData(
                "Node '{0}': {1} network(s) are left unassigned".format(
                    node['id'], ",".join(str_ng_ids)),
                log_message=True
            )

        for iface in interfaces:
            if iface['type'] == NETWORK_INTERFACE_TYPES.ether \
                    and iface['id'] in bonded_eth_ids \
                    and len(iface['assigned_networks']) > 0:
                raise errors.InvalidData(
                    "Node '{0}': interface '{1}' cannot have "
                    "assigned networks as it is used in "
                    "bond".format(node['id'], iface['id']),
                    log_message=True
                )
开发者ID:stamak,项目名称:fuel-web,代码行数:75,代码来源:network.py


注:本文中的nailgun.network.manager.NetworkManager.get_node_networkgroups_ids方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。