X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=NG-RO%2Fosm_ng_ro%2Fns_thread.py;h=03255e3f329469dceb7319068960bbc8f8d376a2;hb=d5d92ec343a9f61485c565c9f2ffb12afb85d67a;hp=23622f718c8bb2d73d035af369af341218307484;hpb=21c55d66c67cce097adab2f237356388b1a16077;p=osm%2FRO.git diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index 23622f71..03255e3f 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -347,7 +347,6 @@ class VimInteractionVdu(VimInteractionBase): created = False created_items = {} target_vim = self.my_vims[ro_task["target_id"]] - try: created = True params = task["params"] @@ -389,7 +388,6 @@ class VimInteractionVdu(VimInteractionBase): ) affinity_group["affinity_group_id"] = affinity_group_id - vim_vm_id, created_items = target_vim.new_vminstance(**params_copy) interfaces = [iface["vim_id"] for iface in params_copy["net_list"]] @@ -691,6 +689,102 @@ class VimInteractionImage(VimInteractionBase): return "FAILED", ro_vim_item_update +class VimInteractionSharedVolume(VimInteractionBase): + def delete(self, ro_task, task_index): + task = ro_task["tasks"][task_index] + task_id = task["task_id"] + shared_volume_vim_id = ro_task["vim_info"]["vim_id"] + ro_vim_item_update_ok = { + "vim_status": "DELETED", + "created": False, + "vim_message": "DELETED", + "vim_id": None, + } + try: + if shared_volume_vim_id: + target_vim = self.my_vims[ro_task["target_id"]] + target_vim.delete_shared_volumes(shared_volume_vim_id) + except vimconn.VimConnNotFoundException: + ro_vim_item_update_ok["vim_message"] = "already deleted" + except vimconn.VimConnException as e: + self.logger.error( + "ro_task={} vim={} del-shared-volume={}: {}".format( + ro_task["_id"], ro_task["target_id"], shared_volume_vim_id, e + ) + ) + ro_vim_item_update = { + "vim_status": "VIM_ERROR", + "vim_message": "Error while deleting: {}".format(e), + } + + return "FAILED", ro_vim_item_update + + self.logger.debug( + "task={} {} del-shared-volume={} {}".format( + task_id, + ro_task["target_id"], + shared_volume_vim_id, + ro_vim_item_update_ok.get("vim_message", ""), + ) + ) + + return "DONE", ro_vim_item_update_ok + + def new(self, ro_task, task_index, task_depends): + task = ro_task["tasks"][task_index] + task_id = task["task_id"] + created = False + created_items = {} + target_vim = self.my_vims[ro_task["target_id"]] + + try: + shared_volume_name = None + shared_volume_vim_id = None + shared_volume_data = None + + if task.get("params"): + shared_volume_data = task["params"] + + if shared_volume_data: + self.logger.info( + f"Creating the new shared_volume for {shared_volume_data}\n" + ) + ( + shared_volume_name, + shared_volume_vim_id, + ) = target_vim.new_shared_volumes(shared_volume_data) + created = True + created_items[shared_volume_vim_id] = shared_volume_name + + ro_vim_item_update = { + "vim_id": shared_volume_vim_id, + "vim_status": "DONE", + "created": created, + "created_items": created_items, + "vim_details": None, + "vim_message": None, + } + self.logger.debug( + "task={} {} new-shared-volume={} created={}".format( + task_id, ro_task["target_id"], shared_volume_vim_id, created + ) + ) + + return "DONE", ro_vim_item_update + except (vimconn.VimConnException, NsWorkerException) as e: + self.logger.error( + "task={} vim={} new-shared-volume:" + " {}".format(task_id, ro_task["target_id"], e) + ) + ro_vim_item_update = { + "vim_status": "VIM_ERROR", + "created": created, + "vim_message": str(e), + } + + return "FAILED", ro_vim_item_update + + class VimInteractionFlavor(VimInteractionBase): def delete(self, ro_task, task_index): task = ro_task["tasks"][task_index] @@ -739,7 +833,6 @@ class VimInteractionFlavor(VimInteractionBase): created = False created_items = {} target_vim = self.my_vims[ro_task["target_id"]] - try: # FIND vim_flavor_id = None @@ -1540,6 +1633,9 @@ class NsWorker(threading.Thread): self.db = db self.item2class = { "net": VimInteractionNet(self.db, self.my_vims, self.db_vims, self.logger), + "shared-volumes": VimInteractionSharedVolume( + self.db, self.my_vims, self.db_vims, self.logger + ), "vdu": VimInteractionVdu(self.db, self.my_vims, self.db_vims, self.logger), "image": VimInteractionImage( self.db, self.my_vims, self.db_vims, self.logger @@ -2089,18 +2185,15 @@ class NsWorker(threading.Thread): return ro_task_dependency, task_index raise NsWorkerException("Cannot get depending task {}".format(task_id)) - def update_vm_refresh(self): + def update_vm_refresh(self, ro_task): """Enables the VM status updates if self.refresh_config.active parameter - is not -1 and than updates the DB accordingly + is not -1 and then updates the DB accordingly """ try: self.logger.debug("Checking if VM status update config") next_refresh = time.time() - if self.refresh_config.active == -1: - next_refresh = -1 - else: - next_refresh += self.refresh_config.active + next_refresh = self._get_next_refresh(ro_task, next_refresh) if next_refresh != -1: db_ro_task_update = {} @@ -2135,6 +2228,23 @@ class NsWorker(threading.Thread): except Exception as e: self.logger.error(f"Error updating tasks to enable VM status updates: {e}") + def _get_next_refresh(self, ro_task: dict, next_refresh: float): + """Decide the next_refresh according to vim type and refresh config period. + Args: + ro_task (dict): ro_task details + next_refresh (float): next refresh time as epoch format + + Returns: + next_refresh (float) -1 if vm updates are disabled or vim type is openstack. + """ + target_vim = ro_task["target_id"] + vim_type = self.db_vims[target_vim]["vim_type"] + if self.refresh_config.active == -1 or vim_type == "openstack": + next_refresh = -1 + else: + next_refresh += self.refresh_config.active + return next_refresh + def _process_pending_tasks(self, ro_task): ro_task_id = ro_task["_id"] now = time.time() @@ -2156,10 +2266,7 @@ class NsWorker(threading.Thread): elif new_status == "BUILD": next_refresh += self.refresh_config.build elif new_status == "DONE": - if self.refresh_config.active == -1: - next_refresh = -1 - else: - next_refresh += self.refresh_config.active + next_refresh = self._get_next_refresh(ro_task, next_refresh) else: next_refresh += self.refresh_config.error @@ -2174,7 +2281,7 @@ class NsWorker(threading.Thread): self._log_ro_task(ro_task, None, None, "TASK_WF", "GET_TASK") """ # Check if vim status refresh is enabled again - self.update_vm_refresh() + self.update_vm_refresh(ro_task) # 0: get task_status_create lock_object = None task_status_create = None @@ -2290,7 +2397,6 @@ class NsWorker(threading.Thread): lock_object = LockRenew.add_lock_object( "ro_tasks", ro_task, self ) - if task["action"] == "DELETE": ( new_status, @@ -2338,7 +2444,6 @@ class NsWorker(threading.Thread): new_status, db_vim_info_update = self.item2class[ task["item"] ].new(ro_task, task_index, task_depends) - # self._create_task(ro_task, task_index, task_depends, db_ro_task_update) _update_refresh(new_status) else: refresh_at = ro_task["vim_info"]["refresh_at"]