X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Fvnf_collectors%2Fvio.py;h=130b2539421e02e8803bb84d0982d8c7324f6ff7;hb=94948de24a6ff7d03cce2168be5a83c0ed97196d;hp=8413496ef008022d09481b284229981d1991b71f;hpb=73dbb4e243f47afef0d1bb61988608e256939e87;p=osm%2FMON.git diff --git a/osm_mon/collector/vnf_collectors/vio.py b/osm_mon/collector/vnf_collectors/vio.py index 8413496..130b253 100644 --- a/osm_mon/collector/vnf_collectors/vio.py +++ b/osm_mon/collector/vnf_collectors/vio.py @@ -32,61 +32,67 @@ log = logging.getLogger(__name__) class VIOCollector(BaseVimCollector): - def __init__(self, config: Config, vim_account_id: str): + def __init__(self, config: Config, vim_account_id: str, vim_session: object): 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-param' 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-param'], - vnfr=vnfr, - tags=tags - ) + return self.vrops.get_metrics( + vdu_mappings=vdu_mappings, + monitoring_params=vdu["monitoring-parameter"], + vnfr=vnfr, + tags=tags, + ) else: return []