本文整理汇总了Python中nailgun.task.helpers.TaskHelper.update_verify_networks方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHelper.update_verify_networks方法的具体用法?Python TaskHelper.update_verify_networks怎么用?Python TaskHelper.update_verify_networks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.task.helpers.TaskHelper
的用法示例。
在下文中一共展示了TaskHelper.update_verify_networks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_dhcp_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import update_verify_networks [as 别名]
def check_dhcp_resp(cls, **kwargs):
"""Receiver method for check_dhcp task
For example of kwargs check FakeCheckingDhcpThread
"""
logger.info(
"RPC method check_dhcp_resp received: %s",
json.dumps(kwargs)
)
messages = []
result = collections.defaultdict(list)
message_template = (
u"Node {node_name} discovered DHCP server "
u"via {iface} with following parameters: IP: {server_id}, "
u"MAC: {mac}. This server will conflict with the installation.")
task_uuid = kwargs.get('task_uuid')
nodes = kwargs.get('nodes', [])
error_msg = kwargs.get('error')
status = kwargs.get('status')
progress = kwargs.get('progress')
nodes_uids = [node['uid'] for node in nodes]
nodes_db = db().query(Node).filter(Node.id.in_(nodes_uids)).all()
nodes_map = dict((str(node.id), node) for node in nodes_db)
macs = [item['addr'] for item in cls._get_master_macs()]
logger.debug('Mac addr on master node %s', macs)
for node in nodes:
if node['status'] == 'ready':
for row in node.get('data', []):
if row['mac'] not in macs:
node_db = nodes_map.get(node['uid'])
if node_db:
row['node_name'] = node_db.name
message = message_template.format(**row)
messages.append(message)
result[node['uid']].append(row)
else:
logger.warning(
'Received message from nonexistent node. '
'Message %s', row)
status = status if not messages else "error"
error_msg = '\n'.join(messages) if messages else error_msg
logger.debug('Check dhcp message %s', error_msg)
TaskHelper.update_verify_networks(task_uuid, status, progress,
error_msg, result)
示例2: verify_networks_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import update_verify_networks [as 别名]
#.........这里部分代码省略.........
).all()
absent_node_names = []
for n in absent_nodes:
if n.name:
absent_node_names.append(n.name)
else:
absent_node_names.append('id: %s' % n.id)
if not error_msg:
error_msg = 'Node(s) {0} didn\'t return data.'.format(
', '.join(absent_node_names)
)
status = 'error'
elif len(nodes) < 2:
status = 'error'
if not error_msg:
error_msg = 'At least two nodes are required to be in '\
'the environment for network verification.'
else:
error_nodes = []
for node in nodes:
cached_nodes_filtered = filter(
lambda n: str(n['uid']) == str(node['uid']),
cached_nodes
)
if not cached_nodes_filtered:
logger.warning(
"verify_networks_resp: arguments contain node "
"data which is not in the task cache: %r",
node
)
continue
cached_node = cached_nodes_filtered[0]
for cached_network in cached_node['networks']:
received_networks_filtered = filter(
lambda n: n['iface'] == cached_network['iface'],
node.get('networks', [])
)
if received_networks_filtered:
received_network = received_networks_filtered[0]
absent_vlans = list(
set(cached_network['vlans']) -
set(received_network['vlans'])
)
else:
logger.warning(
"verify_networks_resp: arguments don't contain"
" data for interface: uid=%s iface=%s",
node['uid'], cached_network['iface']
)
absent_vlans = cached_network['vlans']
if absent_vlans:
data = {'uid': node['uid'],
'interface': cached_network['iface'],
'absent_vlans': absent_vlans}
node_db = db().query(Node).get(node['uid'])
if node_db:
data['name'] = node_db.name
db_nics = filter(
lambda i:
i.name == cached_network['iface'],
node_db.interfaces
)
if db_nics:
data['mac'] = db_nics[0].mac
else:
logger.warning(
"verify_networks_resp: can't find "
"interface %r for node %r in DB",
cached_network['iface'], node_db.id
)
data['mac'] = 'unknown'
else:
logger.warning(
"verify_networks_resp: can't find node "
"%r in DB",
node['uid']
)
error_nodes.append(data)
if error_nodes:
result = error_nodes
status = 'error'
else:
error_msg = (error_msg or
'verify_networks_resp: argument "nodes"'
' have incorrect type')
status = 'error'
logger.error(error_msg)
if status not in ('ready', 'error'):
TaskHelper.update_task_status(task_uuid, status, progress,
error_msg, result)
else:
TaskHelper.update_verify_networks(task_uuid, status, progress,
error_msg, result)