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