前面讲过如何在ironic中hold住计算的状态,可以通过period task定期调用,更新数据库的值,从而得到计算的状态。
添加period task,我们可以在conductor的manager中进行,例如_sync_power_status等ironic本身的周期性调用,如果是各个Driver自己的调用呢?
K版中着重加强了对period_task的部分,追踪period_task的部分前面已经讲过了,不再赘述,这里着重记录一下
decorator:@base.driver_periodic_task(spacing=60), 每个driver自己的task应该有哪些参数呢?
def check_status(self, manager, context):
xxxx
可能会比较好奇,这里的manager和context是从哪里传来的:),之前traceperiod_task的时候,我们追到:
def run_periodic_tasks(self, context, raise_on_error=False):
"""Tasks to be run at a periodic interval."""
idle_for = DEFAULT_INTERVAL
for task_name, task in self._periodic_tasks:
full_task_name = '.'.join([self.__class__.__name__, task_name])
spacing = self._periodic_spacing[task_name]
last_run = self._periodic_last_run[task_name]
# Check if due, if not skip
idle_for = min(idle_for, spacing)
if last_run is not None:
delta = last_run + spacing - time.time()
if delta > 0:
idle_for = min(idle_for, delta)
continue
LOG.debug("Running periodic task %(full_task_name)s",
{"full_task_name": full_task_name})
self._periodic_last_run[task_name] = _nearest_boundary(
last_run, spacing)
try:
task(self, context) #重点在这儿(manager继承自PeriodicTasks),self就是manager,context则是context
except Exception as e:
if raise_on_error:
raise
LOG.exception(_LE("Error during %(full_task_name)s: %(e)s"),
{"full_task_name": full_task_name, "e": e})
time.sleep(0)
return idle_for