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):
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"
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)
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")
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))