X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcollector%2Fvnf_collectors%2Fjuju.py;h=b8c8b4ef28d9328f5d29d5c06ff457822b59aa2c;hb=f54d2e406bc443e1cd6c24bbd1e595b39602fbac;hp=928b35ac7a4db5c8d29696e821e7737dfceb99a9;hpb=b525e6c8619d494d4e254def394cf5b62de4df4a;p=osm%2FMON.git diff --git a/osm_mon/collector/vnf_collectors/juju.py b/osm_mon/collector/vnf_collectors/juju.py index 928b35a..b8c8b4e 100644 --- a/osm_mon/collector/vnf_collectors/juju.py +++ b/osm_mon/collector/vnf_collectors/juju.py @@ -29,18 +29,19 @@ from osm_mon.collector.metric import Metric from osm_mon.collector.vnf_collectors.base import BaseCollector from osm_mon.collector.vnf_metric import VnfMetric from osm_mon.core.common_db import CommonDbClient +from osm_mon.core.config import Config from osm_mon.core.exceptions import VcaDeploymentInfoNotFound -from osm_mon.core.settings import Config log = logging.getLogger(__name__) class VCACollector(BaseCollector): - def __init__(self): - cfg = Config.instance() - self.common_db = CommonDbClient() + def __init__(self, config: Config): + super().__init__(config) + self.common_db = CommonDbClient(config) self.loop = asyncio.get_event_loop() - self.n2vc = N2VC(server=cfg.OSMMON_VCA_HOST, user=cfg.OSMMON_VCA_USER, secret=cfg.OSMMON_VCA_SECRET) + self.n2vc = N2VC(server=config.get('vca', 'host'), user=config.get('vca', 'user'), + secret=config.get('vca', 'secret')) def collect(self, vnfr: dict) -> List[Metric]: nsr_id = vnfr['nsr-id-ref'] @@ -56,8 +57,10 @@ class VCACollector(BaseCollector): ) if 'vdu-configuration' in vdu and 'metrics' in vdu['vdu-configuration']: try: - vca_deployment_info = self.get_vca_deployment_info(nsr_id, vnf_member_index, vdur['name']) - except VcaDeploymentInfoNotFound: + vca_deployment_info = self.get_vca_deployment_info(nsr_id, vnf_member_index, vdur['vdu-id-ref'], + vdur['count-index']) + except VcaDeploymentInfoNotFound as e: + log.warning(repr(e)) continue measures = self.loop.run_until_complete(self.n2vc.GetMetrics(vca_deployment_info['model'], vca_deployment_info['application'])) @@ -70,8 +73,9 @@ class VCACollector(BaseCollector): metrics.append(metric) if 'vnf-configuration' in vnfd and 'metrics' in vnfd['vnf-configuration']: try: - vca_deployment_info = self.get_vca_deployment_info(nsr_id, vnf_member_index, None) - except VcaDeploymentInfoNotFound: + vca_deployment_info = self.get_vca_deployment_info(nsr_id, vnf_member_index) + except VcaDeploymentInfoNotFound as e: + log.warning(repr(e)) return metrics measures = self.loop.run_until_complete(self.n2vc.GetMetrics(vca_deployment_info['model'], vca_deployment_info['application'])) @@ -83,11 +87,20 @@ class VCACollector(BaseCollector): metrics.append(metric) return metrics - def get_vca_deployment_info(self, nsr_id, vnf_member_index, vdur_name): + def get_vca_deployment_info(self, nsr_id, vnf_member_index, vdu_id=None, vdu_count=0): nsr = self.common_db.get_nsr(nsr_id) for vca_deployment in nsr["_admin"]["deployed"]["VCA"]: if vca_deployment: - if vca_deployment['member-vnf-index'] == vnf_member_index and vca_deployment['vdu_name'] == vdur_name: - return vca_deployment - raise VcaDeploymentInfoNotFound("VCA deployment info for nsr_id {}, index {} and vdur_name {} not found." - .format(nsr_id, vnf_member_index, vdur_name)) + if vdu_id is None: + if vca_deployment['member-vnf-index'] == vnf_member_index and vca_deployment['vdu_id'] is None: + return vca_deployment + else: + if vca_deployment['member-vnf-index'] == vnf_member_index and \ + vca_deployment['vdu_id'] == vdu_id and vca_deployment['vdu_count_index'] == vdu_count: + return vca_deployment + raise VcaDeploymentInfoNotFound( + "VCA deployment info for nsr_id {}, index {}, vdu_id {} and vdu_count_index {} not found.".format( + nsr_id, + vnf_member_index, + vdu_id, + vdu_count))