'Cancel the given tasks that are older than the given timeout.'

def _cancel_stale_tasks(self, timeout, task):

    task_refs = self._session.call_xenapi('task.get_by_name_label', task)
    for task_ref in task_refs:
        task_rec = self._session.call_xenapi('task.get_record', task_ref)
        task_created = timeutils.parse_strtime(task_rec['created'].value, '%Y%m%dT%H:%M:%SZ')
        if timeutils.is_older_than(task_created, timeout):
            self._session.call_xenapi('task.cancel', task_ref)
