X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fpmjobs_topics.py;h=f8d7714e90cd8c0eb01a754fe85db38aa51f159e;hp=7fa203562e280ca29d811c02d9555d4402ea64fb;hb=4568a372eb5a204e04d917213de03ec51f9110c1;hpb=0952a48159c11b6d31fff6617f04f06351ed79f3 diff --git a/osm_nbi/pmjobs_topics.py b/osm_nbi/pmjobs_topics.py index 7fa2035..f8d7714 100644 --- a/osm_nbi/pmjobs_topics.py +++ b/osm_nbi/pmjobs_topics.py @@ -22,31 +22,49 @@ from osm_nbi.base_topic import EngineException __author__ = "Vijay R S " -class PmJobsTopic(): +class PmJobsTopic: def __init__(self, db, host=None, port=None): self.db = db - self.url = 'http://{}:{}'.format(host, port) - self.nfvi_metric_list = ['cpu_utilization', 'average_memory_utilization', 'disk_read_ops', - 'disk_write_ops', 'disk_read_bytes', 'disk_write_bytes', - 'packets_dropped', 'packets_sent', 'packets_received'] + self.url = "http://{}:{}".format(host, port) + self.nfvi_metric_list = [ + "cpu_utilization", + "average_memory_utilization", + "disk_read_ops", + "disk_write_ops", + "disk_read_bytes", + "disk_write_bytes", + "packets_dropped", + "packets_sent", + "packets_received", + ] def _get_vnf_metric_list(self, ns_id): metric_list = self.nfvi_metric_list.copy() vnfr_desc = self.db.get_list("vnfrs", {"nsr-id-ref": ns_id}) if not vnfr_desc: - raise EngineException("NS not found with id {}".format(ns_id), http_code=HTTPStatus.NOT_FOUND) + raise EngineException( + "NS not found with id {}".format(ns_id), http_code=HTTPStatus.NOT_FOUND + ) else: for vnfr in vnfr_desc: - vnfd_desc = self.db.get_one("vnfds", {"_id": vnfr["vnfd-id"]}, fail_on_empty=True, fail_on_more=False) - if vnfd_desc.get("vdu"): - for vdu in vnfd_desc['vdu']: - # Checks for vdu metric in vdu-configuration - if 'vdu-configuration' in vdu and 'metrics' in vdu['vdu-configuration']: - metric_list.extend([quote(metric['name']) - for metric in vdu["vdu-configuration"]["metrics"]]) - # Checks for vnf metric in vnf-configutaion - if 'vnf-configuration' in vnfd_desc and 'metrics' in vnfd_desc['vnf-configuration']: - metric_list.extend([quote(metric['name']) for metric in vnfd_desc["vnf-configuration"]["metrics"]]) + vnfd_desc = self.db.get_one( + "vnfds", + {"_id": vnfr["vnfd-id"]}, + fail_on_empty=True, + fail_on_more=False, + ) + try: + configs = vnfd_desc.get("df")[0]["lcm-operations-configuration"][ + "operate-vnf-op-config" + ]["day1-2"] + except Exception: + configs = [] + + for config in configs: + if "metrics" in config: + metric_list.extend( + [quote(metric["name"]) for metric in config["metrics"]] + ) metric_list = list(set(metric_list)) return metric_list @@ -55,36 +73,50 @@ class PmJobsTopic(): async with aiohttp.ClientSession() as session: data = [] for metlist in metrics_list: - request_url = self.url+'/api/v1/query?query=osm_'+metlist+"{ns_id='"+ns_id+"'}" + request_url = ( + self.url + + "/api/v1/query?query=osm_" + + metlist + + "{ns_id='" + + ns_id + + "'}" + ) async with session.get(request_url) as resp: resp = await resp.json() - resp = resp['data']['result'] + resp = resp["data"]["result"] if resp: data.append(resp) return data except aiohttp.client_exceptions.ClientConnectorError as e: raise EngineException("Connection to '{}'Failure: {}".format(self.url, e)) - def show(self, session, ns_id): + def show(self, session, ns_id, api_req=False): metrics_list = self._get_vnf_metric_list(ns_id) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - prom_metric = loop.run_until_complete(self._prom_metric_request(ns_id, metrics_list)) + prom_metric = loop.run_until_complete( + self._prom_metric_request(ns_id, metrics_list) + ) metric = {} metric_temp = [] for index_list in prom_metric: for index in index_list: - process_metric = {'performanceValue': {'performanceValue': {}}} - process_metric['objectInstanceId'] = index['metric']['ns_id'] - process_metric['performanceMetric'] = index['metric']['__name__'] - process_metric['performanceValue']['timestamp'] = index['value'][0] - process_metric['performanceValue']['performanceValue']['performanceValue'] = index['value'][1] - process_metric['performanceValue']['performanceValue']['vnfMemberIndex'] \ - = index['metric']['vnf_member_index'] - if 'vdu_name' not in index['metric']: + process_metric = {"performanceValue": {"performanceValue": {}}} + process_metric["objectInstanceId"] = index["metric"]["ns_id"] + process_metric["performanceMetric"] = index["metric"]["__name__"] + process_metric["performanceValue"]["timestamp"] = index["value"][0] + process_metric["performanceValue"]["performanceValue"][ + "performanceValue" + ] = index["value"][1] + process_metric["performanceValue"]["performanceValue"][ + "vnfMemberIndex" + ] = index["metric"]["vnf_member_index"] + if "vdu_name" not in index["metric"]: pass else: - process_metric['performanceValue']['performanceValue']['vduName'] = index['metric']['vdu_name'] + process_metric["performanceValue"]["performanceValue"][ + "vduName" + ] = index["metric"]["vdu_name"] metric_temp.append(process_metric) - metric['entries'] = metric_temp + metric["entries"] = metric_temp return metric