From: David García Date: Thu, 10 Jan 2019 22:31:03 +0000 (+0100) Subject: WIM dynpac: Add credentials X-Git-Tag: v5.0.3~4^2~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=0ce24dccfbbc28e48551a2a89086aa923016fd9f;p=osm%2FRO.git WIM dynpac: Add credentials Change-Id: Iae69fda14d9ffab43af47084b596ba4a5bc8c7a7 Signed-off-by: David García --- diff --git a/osm_ro/wim/wimconn_dynpac.py b/osm_ro/wim/wimconn_dynpac.py index c85c7a1e..18169370 100644 --- a/osm_ro/wim/wimconn_dynpac.py +++ b/osm_ro/wim/wimconn_dynpac.py @@ -43,7 +43,8 @@ class WimError(Enum): CLEAR_ALL = 'Unable to clear all the services', UNKNOWN_ACTION = 'Unknown action invoked.', BACKUP = 'Unable to get the backup parameter.', - UNSUPPORTED_FEATURE = "Unsupported feature" + UNSUPPORTED_FEATURE = "Unsupported feature", + UNAUTHORIZED = "Failed while authenticating" class WimAPIActions(Enum): @@ -59,6 +60,7 @@ class DynpacConnector(WimConnector): __supported_encapsulation_types = ["dot1q"] __WIM_LOGGER = 'openmano.wimconn.dynpac' __ENCAPSULATION_TYPE_PARAM = "service_endpoint_encapsulation_type" + __ENCAPSULATION_INFO_PARAM = "service_endpoint_encapsulation_info" __BACKUP_PARAM = "backup" __BANDWIDTH_PARAM = "bandwidth" __SERVICE_ENDPOINT_PARAM = "service_endpoint_id" @@ -149,10 +151,9 @@ class DynpacConnector(WimConnector): def check_connectivity(self): endpoint = "{}/checkConnectivity".format(self.__wim_url) - auth = (self.__user, self.__passwd) try: - response = requests.get(endpoint, auth=auth) + response = requests.get(endpoint) http_code = response.status_code except requests.exceptions.RequestException as e: self.__exception(e.message, http_code=503) @@ -161,6 +162,20 @@ class DynpacConnector(WimConnector): self.__exception(WimError.UNREACHABLE, http_code=http_code) self.logger.info("Connectivity checked") + def check_credentials(self): + endpoint = "{}/checkCredentials".format(self.__wim_url) + auth = (self.__user, self.__passwd) + + try: + response = requests.get(endpoint, auth=auth) + http_code = response.status_code + except requests.exceptions.RequestException as e: + self.__exception(e.message, http_code=503) + + if http_code != 200: + self.__exception(WimError.UNAUTHORIZED, http_code=http_code) + self.logger.info("Credentials checked") + # Private functions def __exception(self, x, **kwargs): http_code = kwargs.get("http_code") @@ -207,11 +222,11 @@ class DynpacConnector(WimConnector): "connection_points": [{ "wan_switch_dpid": selected_ports[0].get(self.__SW_ID_PARAM), "wan_switch_port": selected_ports[0].get(self.__SW_PORT_PARAM), - "wan_vlan": connection_points[0].get(self.__VLAN_PARAM) + "wan_vlan": connection_points[0].get(self.__ENCAPSULATION_INFO_PARAM).get(self.__VLAN_PARAM) }, { "wan_switch_dpid": selected_ports[1].get(self.__SW_ID_PARAM), "wan_switch_port": selected_ports[1].get(self.__SW_PORT_PARAM), - "wan_vlan": connection_points[1].get(self.__VLAN_PARAM) + "wan_vlan": connection_points[1].get(self.__ENCAPSULATION_INFO_PARAM).get(self.__VLAN_PARAM) }], "bandwidth": kwargs.get(self.__BANDWIDTH_PARAM), "service_type": service_type,