X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Fvnf_collectors%2Fvio.py;fp=osm_mon%2Fcollector%2Fvnf_collectors%2Fvio.py;h=4f7d55a190f9be308adca2532bdccbed4aec6451;hb=8e4179facf22c8096992f0a83caeec9f2f4996c7;hp=e84f5e77682ddf3d1db36616d00060f89451aaad;hpb=a2eeb474200b8f9ebcaee6fa68fe52b6e1a5e337;p=osm%2FMON.git diff --git a/osm_mon/collector/vnf_collectors/vio.py b/osm_mon/collector/vnf_collectors/vio.py index e84f5e7..4f7d55a 100644 --- a/osm_mon/collector/vnf_collectors/vio.py +++ b/osm_mon/collector/vnf_collectors/vio.py @@ -36,57 +36,63 @@ class VIOCollector(BaseVimCollector): super().__init__(config, vim_account_id) self.common_db = CommonDbClient(config) cfg = self.get_vim_account(vim_account_id) - self.vrops = vROPS_Helper(vrops_site=cfg['vrops_site'], - vrops_user=cfg['vrops_user'], - vrops_password=cfg['vrops_password']) + self.vrops = vROPS_Helper( + vrops_site=cfg["vrops_site"], + vrops_user=cfg["vrops_user"], + vrops_password=cfg["vrops_password"], + ) def get_vim_account(self, vim_account_id: str): vim_account_info = self.common_db.get_vim_account(vim_account_id) - return vim_account_info['config'] + return vim_account_info["config"] def collect(self, vnfr: dict): - vnfd = self.common_db.get_vnfd(vnfr['vnfd-id']) + vnfd = self.common_db.get_vnfd(vnfr["vnfd-id"]) vdu_mappings = {} # Populate extra tags for metrics - nsr_id = vnfr['nsr-id-ref'] + nsr_id = vnfr["nsr-id-ref"] tags = {} - tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name'] - if vnfr['_admin']['projects_read']: - tags['project_id'] = vnfr['_admin']['projects_read'][0] + tags["ns_name"] = self.common_db.get_nsr(nsr_id)["name"] + if vnfr["_admin"]["projects_read"]: + tags["project_id"] = vnfr["_admin"]["projects_read"][0] else: - tags['project_id'] = '' + tags["project_id"] = "" # Fetch the list of all known resources from vROPS. resource_list = self.vrops.get_vm_resource_list_from_vrops() - for vdur in vnfr['vdur']: + for vdur in vnfr["vdur"]: # This avoids errors when vdur records have not been completely filled - if 'name' not in vdur: + if "name" not in vdur: continue - vdu = next( - filter(lambda vdu: vdu['id'] == vdur['vdu-id-ref'], vnfd['vdu']) - ) - if 'monitoring-parameter' not in vdu: + vdu = next(filter(lambda vdu: vdu["id"] == vdur["vdu-id-ref"], vnfd["vdu"])) + if "monitoring-parameter" not in vdu: continue - vim_id = vdur['vim-id'] - vdu_mappings[vim_id] = {'name': vdur['name']} + vim_id = vdur["vim-id"] + vdu_mappings[vim_id] = {"name": vdur["name"]} # Map the vROPS instance id to the vim-id so we can look it up. for resource in resource_list: - for resourceIdentifier in resource['resourceKey']['resourceIdentifiers']: - if resourceIdentifier['identifierType']['name'] == 'VMEntityInstanceUUID': - if resourceIdentifier['value'] != vim_id: + for resourceIdentifier in resource["resourceKey"][ + "resourceIdentifiers" + ]: + if ( + resourceIdentifier["identifierType"]["name"] + == "VMEntityInstanceUUID" + ): + if resourceIdentifier["value"] != vim_id: continue - vdu_mappings[vim_id]['vrops_id'] = resource['identifier'] + vdu_mappings[vim_id]["vrops_id"] = resource["identifier"] if len(vdu_mappings) != 0: - return self.vrops.get_metrics(vdu_mappings=vdu_mappings, - monitoring_params=vdu['monitoring-parameter'], - vnfr=vnfr, - tags=tags - ) + return self.vrops.get_metrics( + vdu_mappings=vdu_mappings, + monitoring_params=vdu["monitoring-parameter"], + vnfr=vnfr, + tags=tags, + ) else: return []