本文整理汇总了Python中nailgun.network.manager.NetworkManager类的典型用法代码示例。如果您正苦于以下问题:Python NetworkManager类的具体用法?Python NetworkManager怎么用?Python NetworkManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NetworkManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_for_provisioning
def prepare_for_provisioning(cls, nodes):
"""Prepare environment for provisioning,
update fqdns, assign admin IPs
"""
cls.update_slave_nodes_fqdn(nodes)
for node in nodes:
NetworkManager.assign_admin_ips(node.id)
示例2: serialize_for_cluster
def serialize_for_cluster(cls, cluster):
result = {}
result['net_manager'] = cluster.net_manager
result['networks'] = map(
cls.serialize_network_group,
cluster.network_groups
)
net_manager = NetworkManager()
result['networks'].append(
cls.serialize_network_group(
net_manager.get_admin_network_group()
)
)
if cluster.dns_nameservers:
result['dns_nameservers'] = {
"nameservers": cluster.dns_nameservers
}
if cluster.is_ha_mode:
nw_metadata = cluster.release.networks_metadata["nova_network"]
for network in nw_metadata["networks"]:
if network.get("assign_vip") is not False:
result['{0}_vip'.format(
network["name"]
)] = net_manager.assign_vip(
cluster.id,
network["name"]
)
return result
示例3: get_common_attrs
def get_common_attrs(cls, cluster):
"""Common attributes for all facts
"""
common_attrs = super(
NovaOrchestratorHASerializer,
cls
).get_common_attrs(cluster)
netmanager = NetworkManager()
common_attrs['management_vip'] = netmanager.assign_vip(
cluster.id, 'management')
common_attrs['public_vip'] = netmanager.assign_vip(
cluster.id, 'public')
sorted_nodes = sorted(
common_attrs['nodes'], key=lambda node: int(node['uid']))
controller_nodes = cls.filter_by_roles(
sorted_nodes, ['controller', 'primary-controller'])
common_attrs['last_controller'] = controller_nodes[-1]['name']
# Assign primary controller in nodes list
cls.set_primary_controller(common_attrs['nodes'])
common_attrs['mp'] = [
{'point': '1', 'weight': '1'},
{'point': '2', 'weight': '2'}]
return common_attrs
示例4: update
def update(cls, cluster, network_configuration):
from nailgun.network.manager import NetworkManager
network_manager = NetworkManager()
if 'net_manager' in network_configuration:
setattr(
cluster,
'net_manager',
network_configuration['net_manager'])
if 'networks' in network_configuration:
for ng in network_configuration['networks']:
ng_db = orm().query(NetworkGroup).get(ng['id'])
for key, value in ng.iteritems():
if key == "ip_ranges":
# deleting old ip ranges
map(
orm().delete,
orm().query(IPAddrRange).filter_by(
network_group_id=ng['id']
)
)
for r in value:
new_ip_range = IPAddrRange(
first=r[0],
last=r[1],
network_group_id=ng['id']
)
orm().add(new_ip_range)
orm().commit()
else:
setattr(ng_db, key, value)
network_manager.create_networks(ng_db)
ng_db.cluster.add_pending_changes('networks')
示例5: get_default
def get_default(self, node):
nics = []
network_manager = NetworkManager()
for nic in node.interfaces:
nic_dict = {
"id": nic.id,
"name": nic.name,
"mac": nic.mac,
"max_speed": nic.max_speed,
"current_speed": nic.current_speed
}
assigned_ng_ids = network_manager.get_default_nic_networkgroups(
node.id,
nic.id
)
for ng_id in assigned_ng_ids:
ng = db().query(NetworkGroup).get(ng_id)
nic_dict.setdefault("assigned_networks", []).append(
{"id": ng_id, "name": ng.name}
)
allowed_ng_ids = network_manager.get_allowed_nic_networkgroups(
node.id,
nic.id
)
for ng_id in allowed_ng_ids:
ng = db().query(NetworkGroup).get(ng_id)
nic_dict.setdefault("allowed_networks", []).append(
{"id": ng_id, "name": ng.name}
)
nics.append(nic_dict)
return nics
示例6: render
def render(cls, instance, fields=None):
json_data = JSONHandler.render(instance, fields=cls.fields)
network_manager = NetworkManager()
json_data['network_data'] = network_manager.get_node_networks(
instance.id
)
return json_data
示例7: update
def update(cls, cluster, network_configuration):
from nailgun.network.manager import NetworkManager
network_manager = NetworkManager()
if 'net_manager' in network_configuration:
setattr(
cluster,
'net_manager',
network_configuration['net_manager'])
if 'networks' in network_configuration:
for ng in network_configuration['networks']:
ng_db = db().query(NetworkGroup).get(ng['id'])
for key, value in ng.iteritems():
if key == "ip_ranges":
cls.__set_ip_ranges(ng['id'], value)
else:
if key == 'cidr' and \
not ng['name'] in ('public', 'floating'):
network_manager.update_ranges_from_cidr(
ng_db, value)
setattr(ng_db, key, value)
network_manager.create_networks(ng_db)
ng_db.cluster.add_pending_changes('networks')
示例8: get_common_attrs
def get_common_attrs(cls, cluster):
"""Common attributes for all facts
"""
common_attrs = super(OrchestratorHASerializer, cls).get_common_attrs(
cluster)
netmanager = NetworkManager()
common_attrs['management_vip'] = netmanager.assign_vip(
cluster.id, 'management')
common_attrs['public_vip'] = netmanager.assign_vip(
cluster.id, 'public')
common_attrs['last_controller'] = sorted(
common_attrs['controller_nodes'],
key=lambda node: node['uid'])[-1]['name']
first_controller = filter(
lambda node: 'controller' in node['role'],
common_attrs['nodes'])[0]
first_controller['role'] = 'primary-controller'
common_attrs['mp'] = [
{'point': '1', 'weight': '1'},
{'point': '2', 'weight': '2'}]
common_attrs['mountpoints'] = '1 1\\n2 2\\n'
return common_attrs
示例9: get_default
def get_default(self, node):
nics = []
network_manager = NetworkManager()
for nic in node.interfaces:
nic_dict = {
"id": nic.id,
"name": nic.name,
"mac": nic.mac,
"max_speed": nic.max_speed,
"current_speed": nic.current_speed
}
assigned_ngs = network_manager.get_default_nic_networkgroups(
node, nic)
for ng in assigned_ngs:
nic_dict.setdefault('assigned_networks', []).append(
{'id': ng.id, 'name': ng.name})
allowed_ngs = network_manager.get_allowed_nic_networkgroups(
node, nic)
for ng in allowed_ngs:
nic_dict.setdefault('allowed_networks', []).append(
{'id': ng.id, 'name': ng.name})
nics.append(nic_dict)
return nics
示例10: run
def run(self):
super(FakeDeletionThread, self).run()
receiver = NailgunReceiver
kwargs = {
'task_uuid': self.task_uuid,
'nodes': self.data['args']['nodes'],
'status': 'ready'
}
nodes_to_restore = self.data['args'].get('nodes_to_restore', [])
resp_method = getattr(receiver, self.respond_to)
resp_method(**kwargs)
for node_data in nodes_to_restore:
node = Node(**node_data)
# Offline node just deleted from db
# and could not recreated with status
# discover
if not node.online:
continue
node.status = 'discover'
db().add(node)
db().commit()
node.attributes = NodeAttributes(node_id=node.id)
node.attributes.volumes = node.volume_manager.gen_volumes_info()
NetworkManager.update_interfaces_info(node)
db().commit()
ram = round(node.meta.get('ram') or 0, 1)
cores = node.meta.get('cores') or 'unknown'
notifier.notify("discover",
"New node with %s CPU core(s) "
"and %s GB memory is discovered" %
(cores, ram), node_id=node.id)
示例11: prepare_for_provisioning
def prepare_for_provisioning(self):
from nailgun.network.manager import NetworkManager
from nailgun.task.helpers import TaskHelper
netmanager = NetworkManager()
for node in TaskHelper.nodes_to_provision(self):
netmanager.assign_admin_ips(
node.id, len(node.meta.get('interfaces', [])))
示例12: prepare_for_provisioning
def prepare_for_provisioning(cls, nodes):
"""Prepare environment for provisioning,
update fqdns, assign admin ips
"""
cls.update_slave_nodes_fqdn(nodes)
for node in nodes:
NetworkManager.assign_admin_ips(
node.id, len(node.meta.get('interfaces', [])))
示例13: prepare_for_provisioning
def prepare_for_provisioning(self):
from nailgun.network.manager import NetworkManager
from nailgun.task.helpers import TaskHelper
netmanager = NetworkManager()
nodes = TaskHelper.nodes_to_provision(self)
TaskHelper.update_slave_nodes_fqdn(nodes)
for node in nodes:
netmanager.assign_admin_ips(node.id, len(node.meta.get("interfaces", [])))
示例14: get_admin_ips
def get_admin_ips(cls, node):
netmanager = NetworkManager()
admin_net_id = netmanager.get_admin_network_id()
admin_ips = set([
i.ip_addr for i in db().query(IPAddr).
filter_by(node=node.id).
filter_by(network=admin_net_id)])
return admin_ips
示例15: __format_node_for_naily
def __format_node_for_naily(cls, n):
netmanager = NetworkManager()
return {
'id': n.id, 'status': n.status, 'error_type': n.error_type,
'uid': n.id, 'ip': n.ip, 'mac': n.mac, 'role': n.role,
'fqdn': n.fqdn, 'progress': n.progress, 'meta': n.meta,
'network_data': netmanager.get_node_networks(n.id),
'online': n.online
}