X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fns.py;h=c8b2b0d3afd428bac4c7a75ffb0fcdd0fb426019;hb=6509c6c40a160d05fff193ae0b761fe31b849c90;hp=48dbae3a92207c6313e1611fce66cf396eeb6400;hpb=d85490b842572610083b40922df2c7652dc11682;p=osm%2FLCM.git diff --git a/osm_lcm/ns.py b/osm_lcm/ns.py index 48dbae3..c8b2b0d 100644 --- a/osm_lcm/ns.py +++ b/osm_lcm/ns.py @@ -148,7 +148,7 @@ class NsLcm(LcmBase): fs=self.fs, log=self.logger, db=self.db, - on_update_db=None, + on_update_db=self._on_update_k8s_db, ) self.k8scluster_map = { @@ -197,7 +197,6 @@ class NsLcm(LcmBase): # self.logger.debug('_on_update_n2vc_db(table={}, filter={}, path={}, updated_data={}' # .format(table, filter, path, updated_data)) - try: nsr_id = filter.get('_id') @@ -212,6 +211,7 @@ class NsLcm(LcmBase): # vcaStatus db_dict = dict() db_dict['vcaStatus'] = status_dict + await self.n2vc.update_vca_status(db_dict['vcaStatus']) # update configurationStatus for this VCA try: @@ -278,6 +278,41 @@ class NsLcm(LcmBase): except Exception as e: self.logger.warn('Error updating NS state for ns={}: {}'.format(nsr_id, e)) + async def _on_update_k8s_db(self, cluster_uuid, kdu_instance, filter=None): + """ + Updating vca status in NSR record + :param cluster_uuid: UUID of a k8s cluster + :param kdu_instance: The unique name of the KDU instance + :param filter: To get nsr_id + :return: none + """ + + # self.logger.debug("_on_update_k8s_db(cluster_uuid={}, kdu_instance={}, filter={}" + # .format(cluster_uuid, kdu_instance, filter)) + + try: + nsr_id = filter.get('_id') + + # get vca status for NS + vca_status = await self.k8sclusterjuju.status_kdu(cluster_uuid, + kdu_instance, + complete_status=True, + yaml_format=False) + # vcaStatus + db_dict = dict() + db_dict['vcaStatus'] = {nsr_id: vca_status} + + await self.k8sclusterjuju.update_vcaStatus(db_dict['vcaStatus'], cluster_uuid, + kdu_instance) + + # write to database + self.update_db_2("nsrs", nsr_id, db_dict) + + except (asyncio.CancelledError, asyncio.TimeoutError): + raise + except Exception as e: + self.logger.warn('Error updating NS state for ns={}: {}'.format(nsr_id, e)) + @staticmethod def _parse_cloud_init(cloud_init_text, additional_params, vnfd_id, vdu_id): try: @@ -2377,7 +2412,7 @@ class NsLcm(LcmBase): db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) # for each defined NS relation, find the VCA's related - for r in ns_relations: + for r in ns_relations.copy(): from_vca_ee_id = None to_vca_ee_id = None from_vca_endpoint = None @@ -2422,7 +2457,7 @@ class NsLcm(LcmBase): pass # for each defined VNF relation, find the VCA's related - for r in vnf_relations: + for r in vnf_relations.copy(): from_vca_ee_id = None to_vca_ee_id = None from_vca_endpoint = None @@ -2548,7 +2583,7 @@ class NsLcm(LcmBase): cluster_uuid=k8s_instance_info["k8scluster-uuid"], kdu_instance=kdu_instance, primitive_name=initial_config_primitive["name"], - params=primitive_params_, db_dict={}), + params=primitive_params_, db_dict=db_dict_install), timeout=timeout) except Exception as e: @@ -3521,7 +3556,8 @@ class NsLcm(LcmBase): self._write_op_status(nslcmop_id, stage) return error_detail_list - def _map_primitive_params(self, primitive_desc, params, instantiation_params): + @staticmethod + def _map_primitive_params(primitive_desc, params, instantiation_params): """ Generates the params to be provided to charm before executing primitive. If user does not provide a parameter, The default-value is used. If it is between < > it look for a value at instantiation_params @@ -3569,7 +3605,6 @@ class NsLcm(LcmBase): if primitive_desc["name"] == "config": if "ns_config_info" in instantiation_params: calculated_params["ns_config_info"] = instantiation_params["ns_config_info"] - calculated_params["VCA"] = self.vca_config return calculated_params def _look_for_deployed_vca(self, deployed_vca, member_vnf_index, vdu_id, vdu_count_index, kdu_name=None, @@ -3644,6 +3679,29 @@ class NsLcm(LcmBase): except Exception as e: return 'FAIL', 'Error executing action {}: {}'.format(primitive, e) + async def vca_status_refresh(self, nsr_id, nslcmop_id): + """ + Updating the vca_status with latest juju information in nsrs record + :param: nsr_id: Id of the nsr + :param: nslcmop_id: Id of the nslcmop + :return: None + """ + + self.logger.debug("Task ns={} action={} Enter".format(nsr_id, nslcmop_id)) + db_nsr = self.db.get_one("nsrs", {"_id": nsr_id}) + if db_nsr['_admin']['deployed']['K8s']: + for k8s_index, k8s in enumerate(db_nsr['_admin']['deployed']['K8s']): + cluster_uuid, kdu_instance = k8s["k8scluster-uuid"], k8s["kdu-instance"] + await self._on_update_k8s_db(cluster_uuid, kdu_instance, filter={'_id': nsr_id}) + else: + for vca_index, _ in enumerate(db_nsr['_admin']['deployed']['VCA']): + table, filter = "nsrs", {"_id": nsr_id} + path = "_admin.deployed.VCA.{}.".format(vca_index) + await self._on_update_n2vc_db(table, filter, path, {}) + + self.logger.debug("Task ns={} action={} Exit".format(nsr_id, nslcmop_id)) + self.lcm_tasks.remove("ns", nsr_id, nslcmop_id, "ns_vca_status_refresh") + async def action(self, nsr_id, nslcmop_id): # Try to lock HA task here