本文整理汇总了Python中nailgun.task.helpers.TaskHelper.recalculate_provisioning_task_progress方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHelper.recalculate_provisioning_task_progress方法的具体用法?Python TaskHelper.recalculate_provisioning_task_progress怎么用?Python TaskHelper.recalculate_provisioning_task_progress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nailgun.task.helpers.TaskHelper
的用法示例。
在下文中一共展示了TaskHelper.recalculate_provisioning_task_progress方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: provision_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def provision_resp(cls, **kwargs):
logger.info(
"RPC method provision_resp received: %s" % jsonutils.dumps(kwargs))
task_uuid = kwargs.get('task_uuid')
message = kwargs.get('error')
status = kwargs.get('status')
progress = kwargs.get('progress')
nodes = kwargs.get('nodes', [])
task = objects.Task.get_by_uuid(
task_uuid, fail_if_not_found=True, lock_for_update=True)
# if task was failed on master node then we should
# mark all cluster's nodes in error state
master = next((n for n in nodes if n['uid'] == consts.MASTER_ROLE), {})
# we should remove master node from the nodes since it requires
# special handling and won't work with old code
if master:
nodes.remove(master)
if master.get('status') == consts.TASK_STATUSES.error:
status = consts.TASK_STATUSES.error
progress = 100
# lock nodes for updating
q_nodes = objects.NodeCollection.filter_by_id_list(
None, [n['uid'] for n in nodes])
q_nodes = objects.NodeCollection.order_by(q_nodes, 'id')
objects.NodeCollection.lock_for_update(q_nodes).all()
for node in nodes:
uid = node.get('uid')
node_db = objects.Node.get_by_uid(node['uid'])
if not node_db:
logger.warn('Node with uid "{0}" not found'.format(uid))
continue
if node.get('status') == consts.TASK_STATUSES.error:
node_db.status = consts.TASK_STATUSES.error
node_db.progress = 100
node_db.error_type = 'provision'
node_db.error_msg = node.get('error_msg', 'Unknown error')
else:
node_db.status = node.get('status')
node_db.progress = node.get('progress')
db().flush()
if nodes and not progress:
progress = TaskHelper.recalculate_provisioning_task_progress(task)
data = {'status': status, 'progress': progress, 'message': message}
objects.Task.update(task, data)
cls._update_action_log_entry(status, task.name, task_uuid, nodes)
示例2: provision_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def provision_resp(cls, **kwargs):
logger.info(
"RPC method provision_resp received: %s" %
jsonutils.dumps(kwargs))
task_uuid = kwargs.get('task_uuid')
message = kwargs.get('error')
status = kwargs.get('status')
progress = kwargs.get('progress')
nodes = kwargs.get('nodes', [])
task = objects.Task.get_by_uuid(
task_uuid,
fail_if_not_found=True,
lock_for_update=True
)
# we should remove master node from the nodes since it requires
# special handling and won't work with old code
# lock nodes for updating
nodes_by_id = {str(n['uid']): n for n in nodes}
master = nodes_by_id.pop(consts.MASTER_NODE_UID, {})
if master.get('status') == consts.TASK_STATUSES.error:
status = consts.TASK_STATUSES.error
progress = 100
q_nodes = objects.NodeCollection.filter_by_id_list(
None, nodes_by_id
)
q_nodes = objects.NodeCollection.order_by(q_nodes, 'id')
db_nodes = objects.NodeCollection.lock_for_update(q_nodes).all()
for node_db in db_nodes:
node = nodes_by_id[node_db.uid]
if node.get('status') == consts.TASK_STATUSES.error:
node_db.status = consts.TASK_STATUSES.error
node_db.progress = 100
node_db.error_type = consts.TASK_NAMES.provision
node_db.error_msg = node.get('error_msg', 'Unknown error')
else:
node_db.status = node.get('status')
node_db.progress = node.get('progress')
db().flush()
if nodes_by_id:
logger.warning("The following nodes is not found: %s",
",".join(sorted(six.moves.map(str, nodes_by_id))))
if nodes and not progress:
progress = TaskHelper.recalculate_provisioning_task_progress(task)
cls._update_task_status(task, status, progress, message, db_nodes)
cls._update_action_log_entry(status, task.name, task_uuid, nodes)
示例3: provision_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def provision_resp(cls, **kwargs):
logger.info(
"RPC method provision_resp received: %s" %
jsonutils.dumps(kwargs))
task_uuid = kwargs.get('task_uuid')
message = kwargs.get('error')
status = kwargs.get('status')
progress = kwargs.get('progress')
nodes = kwargs.get('nodes', [])
#如果返回error,那么将没有返回nodes参数
#导致如果返回安装失败,那么前台node状态将不会更新
task = objects.Task.get_by_uuid(
task_uuid,
fail_if_not_found=True,
lock_for_update=True
)
# lock nodes for updating
q_nodes = objects.NodeCollection.filter_by_id_list(
None,
[n['uid'] for n in nodes],
)
q_nodes = objects.NodeCollection.order_by(q_nodes, 'id')
objects.NodeCollection.lock_for_update(q_nodes).all()
for node in nodes:
uid = node.get('uid')
node_db = objects.Node.get_by_uid(node['uid'])
if not node_db:
logger.warn('Node with uid "{0}" not found'.format(uid))
continue
if node.get('status') == 'error':
node_db.status = 'error'
node_db.progress = 100
node_db.error_type = 'provision'
node_db.error_msg = node.get('error_msg', 'Unknown error')
else:
node_db.status = node.get('status')
node_db.progress = node.get('progress')
db().flush()
if nodes and not progress:
progress = TaskHelper.recalculate_provisioning_task_progress(task)
data = {'status': status, 'progress': progress, 'message': message}
objects.Task.update(task, data)
cls._update_action_log_entry(status, task_uuid, nodes)
示例4: test_recalculate_provisioning_task_progress
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def test_recalculate_provisioning_task_progress(self):
cluster = self.create_env([
{'roles': ['controller'],
'status': 'provisioned',
'progress': 100},
{'roles': ['compute'],
'status': 'provisioning',
'progress': 0}])
task = Task(name='provision', cluster_id=cluster.id)
self.db.add(task)
self.db.commit()
progress = TaskHelper.recalculate_provisioning_task_progress(task)
self.assertEquals(progress, 50)
示例5: provision_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def provision_resp(cls, **kwargs):
logger.info("RPC method provision_resp received: %s" % jsonutils.dumps(kwargs))
task_uuid = kwargs.get("task_uuid")
message = kwargs.get("error")
status = kwargs.get("status")
progress = kwargs.get("progress")
nodes = kwargs.get("nodes", [])
# 如果返回error,那么将没有返回nodes参数
# 导致如果返回安装失败,那么前台node状态将不会更新
task = objects.Task.get_by_uuid(task_uuid, fail_if_not_found=True, lock_for_update=True)
# lock nodes for updating
q_nodes = objects.NodeCollection.filter_by_id_list(None, [n["uid"] for n in nodes])
q_nodes = objects.NodeCollection.order_by(q_nodes, "id")
objects.NodeCollection.lock_for_update(q_nodes).all()
for node in nodes:
uid = node.get("uid")
node_db = objects.Node.get_by_uid(node["uid"])
if not node_db:
logger.warn('Node with uid "{0}" not found'.format(uid))
continue
if node.get("status") == "error":
node_db.status = "error"
node_db.progress = 100
node_db.error_type = "provision"
node_db.error_msg = node.get("error_msg", "Unknown error")
elif node.get("status") == "provisioned":
node_db.status = node.get("status")
node_db.progress = node.get("progress")
node_db.power_ip = node_db.ip
logger.info("change the node {0} new power_ip is {1}".format(node_db.id, node_db.power_ip))
else:
node_db.status = node.get("status")
node_db.progress = node.get("progress")
db().flush()
if nodes and not progress:
progress = TaskHelper.recalculate_provisioning_task_progress(task)
data = {"status": status, "progress": progress, "message": message}
objects.Task.update(task, data)
cls._update_action_log_entry(status, task_uuid, nodes)
示例6: provision_resp
# 需要导入模块: from nailgun.task.helpers import TaskHelper [as 别名]
# 或者: from nailgun.task.helpers.TaskHelper import recalculate_provisioning_task_progress [as 别名]
def provision_resp(cls, **kwargs):
logger.info(
"RPC method provision_resp received: %s" %
json.dumps(kwargs))
task_uuid = kwargs.get('task_uuid')
message = kwargs.get('error')
status = kwargs.get('status')
progress = kwargs.get('progress')
nodes = kwargs.get('nodes', [])
task = TaskHelper.get_task_by_uuid(task_uuid)
for node in nodes:
uid = node.get('uid')
node_db = db().query(Node).get(uid)
if not node_db:
logger.warn('Node with uid "{0}" not found'.format(uid))
continue
if node.get('status') == 'error':
node_db.status = 'error'
node_db.progress = 100
node_db.error_type = 'provision'
node_db.error_msg = node.get('error_msg', 'Unknown error')
else:
node_db.status = node.get('status')
node_db.progress = node.get('progress')
db().commit()
task = TaskHelper.get_task_by_uuid(task_uuid)
if nodes and not progress:
progress = TaskHelper.recalculate_provisioning_task_progress(task)
TaskHelper.update_task_status(task.uuid, status, progress, message)