X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fwim%2Fwimconn_dynpac.py;h=cc9376b0eeaee49f293fed1d1c19810e4c39da27;hb=1d55a23c9cd32f17bb7a6f21e5b6c2b476c5804f;hp=c85c7a1e3b6fa4e66e022d5f18558a35333e44b1;hpb=00e29ddd2bc186460698cb2431f6751daa24eca8;p=osm%2FRO.git diff --git a/osm_ro/wim/wimconn_dynpac.py b/osm_ro/wim/wimconn_dynpac.py index c85c7a1e..cc9376b0 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): @@ -55,10 +56,11 @@ class WimAPIActions(Enum): class DynpacConnector(WimConnector): - __supported_service_types = ["ELINE (L2)"] + __supported_service_types = ["ELINE (L2)", "ELINE"] __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") @@ -183,38 +198,38 @@ class DynpacConnector(WimConnector): if enc_type not in self.__supported_encapsulation_types: self.__exception(WimError.ENCAPSULATION_TYPE, http_code=400) - bandwidth = kwargs.get(self.__BANDWIDTH_PARAM) - if not isinstance(bandwidth, int): - self.__exception(WimError.BANDWIDTH, http_code=400) + # Commented out for as long as parameter isn't implemented + # bandwidth = kwargs.get(self.__BANDWIDTH_PARAM) + # if not isinstance(bandwidth, int): + # self.__exception(WimError.BANDWIDTH, http_code=400) - backup = kwargs.get(self.__BACKUP_PARAM) - if not isinstance(backup, bool): - self.__exception(WimError.BACKUP, http_code=400) + # Commented out for as long as parameter isn't implemented + # backup = kwargs.get(self.__BACKUP_PARAM) + # if not isinstance(backup, bool): + # self.__exception(WimError.BACKUP, http_code=400) def __get_body(self, service_type, connection_points, kwargs): - port_mapping = self.__config.get("port_mapping") + port_mapping = self.__config.get("service_endpoint_mapping") selected_ports = [] for connection_point in connection_points: endpoint_id = connection_point.get(self.__SERVICE_ENDPOINT_PARAM) - port = filter(lambda x: x.get(self.__WAN_SERVICE_ENDPOINT_PARAM) - == endpoint_id, port_mapping)[0] - wsmpi_json = port.get(self.__WAN_MAPPING_INFO_PARAM) - port_info = json.loads(wsmpi_json) + port = filter(lambda x: x.get(self.__WAN_SERVICE_ENDPOINT_PARAM) == endpoint_id, port_mapping)[0] + port_info = port.get(self.__WAN_MAPPING_INFO_PARAM) selected_ports.append(port_info) - if service_type == "ELINE (L2)": + if service_type == "ELINE (L2)" or service_type == "ELINE": service_type = "L2" body = { "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), + "bandwidth": 100, # Hardcoded for as long as parameter isn't implemented "service_type": service_type, - "backup": kwargs.get(self.__BACKUP_PARAM) + "backup": False # Hardcoded for as long as parameter isn't implemented } return "body={}".format(json.dumps(body))