- # Move this task to the end.
- task["extra"]["tries"] = task["extra"].get("tries", 0) + 1
- if task["extra"]["tries"] <= 3:
- self.pending_tasks.append(task)
- continue
- else:
- raise VimThreadException(
- "Cannot {} {}, (task {}.{}) because timeout waiting to complete {} {}, "
- "(task {}.{})".format(task["action"], task["item"],
- task["instance_action_id"], task["task_index"],
- task_dependency["instance_action_id"], task_dependency["task_index"],
- task_dependency["action"], task_dependency["item"]))
-
- if task["status"] == "SUPERSEDED":
- # not needed to do anything but update database with the new status
- result = True
- database_update = None
- elif not self.vim:
- task["status"] = "ERROR"
- task["error_msg"] = self.error_status
- result = False
- database_update = {"status": "VIM_ERROR", "error_msg": task["error_msg"]}
- elif task["item"] == 'instance_vms':
- if task["action"] == "CREATE":
- result, database_update = self.new_vm(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_vm(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- elif task["item"] == 'instance_nets':
- if task["action"] == "CREATE":
- result, database_update = self.new_net(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_net(task)
- elif task["action"] == "FIND":
- result, database_update = self.get_net(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- elif task["item"] == 'instance_sfis':
- if task["action"] == "CREATE":
- result, database_update = self.new_sfi(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_sfi(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- elif task["item"] == 'instance_sfs':
- if task["action"] == "CREATE":
- result, database_update = self.new_sf(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_sf(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- elif task["item"] == 'instance_classifications':
- if task["action"] == "CREATE":
- result, database_update = self.new_classification(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_classification(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- elif task["item"] == 'instance_sfps':
- if task["action"] == "CREATE":
- result, database_update = self.new_sfp(task)
- nb_created += 1
- elif task["action"] == "DELETE":
- result, database_update = self.del_sfp(task)
- else:
- raise vimconn.vimconnException(self.name + "unknown task action {}".format(task["action"]))
- else:
- raise vimconn.vimconnException(self.name + "unknown task item {}".format(task["item"]))
- # TODO
- except VimThreadException as e:
- result = False
- task["error_msg"] = str(e)
+ # Move this task to the time dependency is going to be modified plus 10 seconds.
+ self.db.update_rows("vim_wim_actions", modified_time=dependency_modified_at + 10,
+ UPDATE={"worker": None},
+ WHERE={"datacenter_vim_id": self.datacenter_tenant_id, "worker": self.my_id,
+ "related": task["related"],
+ })
+ # task["extra"]["tries"] = task["extra"].get("tries", 0) + 1
+ # if task["extra"]["tries"] > 3:
+ # raise VimThreadException(
+ # "Cannot {} {}, (task {}.{}) because timeout waiting to complete {} {}, "
+ # "(task {}.{})".format(task["action"], task["item"],
+ # task["instance_action_id"], task["task_index"],
+ # task_dependency["instance_action_id"], task_dependency["task_index"]
+ # task_dependency["action"], task_dependency["item"]))
+ return
+
+ database_update = None
+ if task["action"] == "DELETE":
+ deleted_needed = self._delete_task(task)
+ if not deleted_needed:
+ task["status"] = "SUPERSEDED" # with FINISHED instead of DONE it will not be refreshing
+ task["error_msg"] = None
+
+ if task["status"] == "SUPERSEDED":
+ # not needed to do anything but update database with the new status
+ database_update = None
+ elif not self.vim: