From 0d9aae9f2c0e74babe1d474f63b877c129522a36 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Mon, 17 May 2021 18:17:36 +0200 Subject: [PATCH] Fix bug 1535 to allow url option for onos_vpls SDNC Change-Id: I81445d4fff17141beeb350ed4161baa8a0f1c9e9 Signed-off-by: garciadeblas --- osm_mon/collector/infra_collectors/onos.py | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/osm_mon/collector/infra_collectors/onos.py b/osm_mon/collector/infra_collectors/onos.py index 33a3aa4..3e94558 100644 --- a/osm_mon/collector/infra_collectors/onos.py +++ b/osm_mon/collector/infra_collectors/onos.py @@ -39,6 +39,18 @@ class OnosInfraCollector(BaseSdncInfraCollector): self.common_db = CommonDbClient(config) self.sdnc = self.common_db.get_sdnc(sdnc_id) + def _obtain_url(self, sdnc_dict): + url = sdnc_dict.get("url") + if url: + return url + else: + if not sdnc_dict.get("ip") or not sdnc_dict.get("port"): + raise Exception("You must provide a URL to contact the SDN Controller") + else: + return "http://{}:{}/onos/v1/devices".format( + sdnc_dict["ip"], sdnc_dict["port"] + ) + def collect(self) -> List[Metric]: metrics = [] sdnc_status = self.is_sdnc_ok() @@ -57,14 +69,12 @@ class OnosInfraCollector(BaseSdncInfraCollector): def is_sdnc_ok(self) -> bool: try: - ip = self.sdnc['ip'] - port = self.sdnc['port'] - user = self.sdnc['user'] - password = self.common_db.decrypt_sdnc_password(self.sdnc['password'], - self.sdnc['schema_version'], - self.sdnc['_id']) - # TODO: Add support for https - url = 'http://{}:{}/onos/v1/devices'.format(ip, port) + url = self._obtain_url(self.sdnc) + user = self.sdnc["user"] + password = self.common_db.decrypt_sdnc_password( + self.sdnc["password"], self.sdnc["schema_version"], self.sdnc["_id"] + ) + requests.get(url, auth=HTTPBasicAuth(user, password)) return True except Exception: -- 2.25.1