本文整理汇总了Python中nailgun.network.manager.NetworkManager.get_admin_network方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager.get_admin_network方法的具体用法?Python NetworkManager.get_admin_network怎么用?Python NetworkManager.get_admin_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.network.manager.NetworkManager
的用法示例。
在下文中一共展示了NetworkManager.get_admin_network方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_default_nic_networkgroups
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_admin_network [as 别名]
def test_get_default_nic_networkgroups(self):
cluster = self.env.create_cluster(api=True,
net_provider='neutron',
net_segment_type='gre')
node = self.env.create_node(api=True)
node_db = self.env.nodes[0]
admin_nic = node_db.admin_interface
other_iface = self.db.query(NodeNICInterface).filter_by(
node_id=node['id']
).filter(
not_(NodeNICInterface.id == admin_nic.id)
).first()
interfaces = deepcopy(node_db.meta['interfaces'])
# allocate ip from admin subnet
admin_ip = str(IPNetwork(NetworkManager.get_admin_network().cidr)[0])
for interface in interfaces:
if interface['mac'] == admin_nic.mac:
# reset admin ip for previous admin interface
interface['ip'] = None
elif interface['mac'] == other_iface.mac:
# set new admin interface
interface['ip'] = admin_ip
node_db.meta['interfaces'] = interfaces
self.app.put(
reverse('NodeCollectionHandler'),
json.dumps([{
'mac': admin_nic.mac,
'meta': node_db.meta,
'is_agent': True,
'cluster_id': cluster["id"]
}]),
headers=self.default_headers,
expect_errors=True
)
new_main_nic_id = node_db.admin_interface.id
admin_nets = [n.name for n in self.db.query(
NodeNICInterface).get(new_main_nic_id).assigned_networks]
other_nets = [n.name for n in other_iface.assigned_networks]
nics = NeutronManager.get_default_networks_assignment(node_db)
def_admin_nic = [n for n in nics if n['id'] == new_main_nic_id]
def_other_nic = [n for n in nics if n['id'] == other_iface.id]
self.assertEquals(len(def_admin_nic), 1)
self.assertEquals(len(def_other_nic), 1)
self.assertEquals(new_main_nic_id, other_iface.id)
self.assertEquals(
set(admin_nets),
set([n['name'] for n in def_admin_nic[0]['assigned_networks']]))
self.assertEquals(
set(other_nets),
set([n['name'] for n in def_other_nic[0]['assigned_networks']]))
示例2: get_admin_ip
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_admin_network [as 别名]
def get_admin_ip(cls, node):
"""Getting admin ip and assign prefix from admin network."""
network_manager = NetworkManager()
admin_ip = network_manager.get_admin_ips_for_interfaces(
node)[node.admin_interface.name]
admin_ip = IPNetwork(admin_ip)
# Assign prefix from admin network
admin_net = IPNetwork(network_manager.get_admin_network().cidr)
admin_ip.prefixlen = admin_net.prefixlen
return str(admin_ip)
示例3: Environment
# 需要导入模块: from nailgun.network.manager import NetworkManager [as 别名]
# 或者: from nailgun.network.manager.NetworkManager import get_admin_network [as 别名]
#.........这里部分代码省略.........
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,
"name": nd[0],
"amount": 1,
"cluster_id": cluster_id,