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


Python NetworkManager.is_ip_belongs_to_admin_subnet方法代码示例

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


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

示例1: admin_interface

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import is_ip_belongs_to_admin_subnet [as 别名]
    def admin_interface(self):
        """Iterate over interfaces, if admin subnet include
        ip address of current interface then return this interface.

        :raises: errors.CanNotFindInterface
        """
        from nailgun.network.manager import NetworkManager

        for interface in self.interfaces:
            ip_addr = interface.ip_addr
            if NetworkManager.is_ip_belongs_to_admin_subnet(ip_addr):
                return interface

        logger.warning(u"Cannot find admin interface for node " 'return first interface: "%s"' % self.full_name)
        return self.interfaces[0]
开发者ID:pombredanne,项目名称:fuel-web,代码行数:17,代码来源:node.py

示例2: admin_interface

# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import is_ip_belongs_to_admin_subnet [as 别名]
    def admin_interface(self):
        """Iterate over interfaces, if admin subnet include
        ip address of current interface then return this interface.

        :raises: errors.CanNotFindInterface
        """
        # TODO(enchantner): move to object
        from nailgun.network.manager import NetworkManager

        admin_ng = NetworkManager.get_admin_network_group()
        for interface in self.interfaces:
            if admin_ng in interface.assigned_networks_list:
                return interface

        for interface in self.interfaces:
            ip_addr = interface.ip_addr
            if NetworkManager.is_ip_belongs_to_admin_subnet(ip_addr):
                return interface

        logger.warning(u'Cannot find admin interface for node '
                       'return first interface: "%s"' %
                       self.full_name)
        return self.interfaces[0]
开发者ID:Mellanox,项目名称:fuel-web,代码行数:25,代码来源:node.py

示例3: Environment

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

#.........这里部分代码省略.........
        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,
                '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 set_admin_ip_for_for_single_interface(self, interfaces):
        """Set admin ip for single interface if it not setted yet."""
        ips = [interface.get('ip') for interface in interfaces]
        admin_ips = [
            ip for ip in ips
            if self.network_manager.is_ip_belongs_to_admin_subnet(ip)]

        if not admin_ips:
            admin_cidr = self.network_manager.get_admin_network().cidr
            interfaces[0]['ip'] = str(IPNetwork(admin_cidr).ip)

    def set_interfaces_in_meta(self, meta, interfaces):
        """Set interfaces in metadata."""
        meta['interfaces'] = interfaces
        self.set_admin_ip_for_for_single_interface(meta['interfaces'])
        return meta['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",
            "public",
            "management",
            "storage",
            "fixed"
        )
        net_cidrs = (
            "172.16.0.0/24",
            "172.16.1.0/24",
            "192.168.0.0/24",
            "192.168.1.0/24",
            "10.0.0.0/24"
        )
        nets = {'networks': [{
            "network_size": 256,
开发者ID:andrey-borisov,项目名称:fuel-web,代码行数:70,代码来源:base.py


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