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()
def is_sdnc_ok(self) -> bool:
try:
- ip = self.sdnc["ip"]
- port = self.sdnc["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"]
)
- # TODO: Add support for https
- url = "http://{}:{}/onos/v1/devices".format(ip, port)
+
requests.get(url, auth=HTTPBasicAuth(user, password))
return True
except Exception: