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


Python NetworkManager.get_all_cluster_networkgroups方法代码示例

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


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

示例1: Environment

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_all_cluster_networkgroups [as 别名]

#.........这里部分代码省略.........
        return notification

    def default_metadata(self):
        item = self.find_item_by_pk_model(
            self.read_fixtures(("sample_environment",)),
            1, 'nailgun.node')
        return item.get('fields').get('meta')

    def _generate_random_mac(self):
        mac = [randint(0x00, 0x7f) for _ in xrange(6)]
        return ':'.join(map(lambda x: "%02x" % x, mac)).upper()

    def generate_interfaces_in_meta(self, amount):
        nics = []
        for i in xrange(amount):
            nics.append(
                {
                    'name': 'eth{0}'.format(i),
                    'mac': self._generate_random_mac(),
                    'current_speed': 100,
                    'max_speed': 1000
                }
            )
        return {'interfaces': nics}

    def _set_interfaces_if_not_set_in_meta(self, node_id, meta):
        if not meta or not 'interfaces' in meta:
            self._add_interfaces_to_node(node_id)

    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        allowed_networks = list(self.db.query(NetworkGroup).filter(
            NetworkGroup.id.in_(
                self.network_manager.get_all_cluster_networkgroups(node_id)
            )
        ))

        for i in xrange(count):
            nic_dict = {
                'node_id': node_id,
                'name': 'eth{0}'.format(i),
                'mac': self._generate_random_mac(),
                'current_speed': 100,
                'max_speed': 1000,
                'allowed_networks': allowed_networks,
                'assigned_networks': allowed_networks
            }

            interface = NodeNICInterface()
            for k, v in nic_dict.iteritems():
                setattr(interface, k, v)

            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)

        return interfaces

    def generate_ui_networks(self, cluster_id):
        start_id = self.db.query(NetworkGroup.id).order_by(
            NetworkGroup.id
        ).first()
        start_id = 0 if not start_id else start_id[-1] + 1
        net_names = (
            "floating",
开发者ID:ilyinon,项目名称:fuelweb,代码行数:70,代码来源:base.py

示例2: Environment

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_all_cluster_networkgroups [as 别名]

#.........这里部分代码省略.........
        for i in xrange(amount):
            nics.append(
                {
                    'name': 'eth{0}'.format(i),
                    'mac': self._generate_random_mac(),
                    'current_speed': 100,
                    'max_speed': 1000
                }
            )
        self.set_admin_ip_for_for_single_interface(nics)
        return {'interfaces': nics}

    def _set_interfaces_if_not_set_in_meta(self, node_id, meta):
        if not meta or not 'interfaces' in meta:
            self._add_interfaces_to_node(node_id)

    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(
                mac=interface.get('mac'),
                name=interface.get('name'),
                ip_addr=interface.get('ip'),
                netmask=interface.get('netmask'))

            self.db.add(interface)
            node.interfaces.append(interface)

        # If node in a cluster then add
        # allowed_networks for all interfaces
        # and assigned_networks for first interface
        if node.cluster_id:
            ng_ids = [ng.id for ng in
                      self.network_manager.get_all_cluster_networkgroups(node)]
            allowed_networks = list(self.db.query(NetworkGroup).filter(
                NetworkGroup.id.in_(ng_ids)))

            for interface in node.interfaces:
                interface.allowed_networks = allowed_networks

            node.interfaces[0].assigned_networks = allowed_networks

        self.db.commit()
        # At least one interface should have
        # same ip as mac in meta
        if node.interfaces and not \
           filter(lambda i: node.mac == i.mac, node.interfaces):

            node.interfaces[0].mac = node.mac
            self.db.commit()

    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        node = self.db.query(Node).get(node_id)
        ng_ids = [ng.id for ng in
                  self.network_manager.get_all_cluster_networkgroups(node)]
        allowed_networks = list(self.db.query(NetworkGroup).filter(
            NetworkGroup.id.in_(ng_ids)))

        for i in xrange(count):
            nic_dict = {
                'node_id': node_id,
                'name': 'eth{0}'.format(i),
                'mac': self._generate_random_mac(),
                'current_speed': 100,
                'max_speed': 1000,
开发者ID:andrey-borisov,项目名称:fuel-web,代码行数:70,代码来源:base.py


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