本文整理汇总了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]
示例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]
示例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,