import logging
import uuid
from enum import Enum
-from requests import RequestException
-
+from requests import RequestException, ConnectionError, ConnectTimeout, Timeout
from cvprac.cvp_client import CvpClient
from cvprac.cvp_api import CvpApi
from cvprac.cvp_client_errors import CvpLoginError, CvpSessionLogOutError, CvpApiError
class SdnError(Enum):
- UNREACHABLE = 'Unable to reach the WIM.',
+ UNREACHABLE = 'Unable to reach the WIM url, connect error.',
+ TIMEOUT = 'Unable to reach the WIM url, timeout.',
VLAN_INCONSISTENT = \
'VLAN value inconsistent between the connection points',
VLAN_NOT_PROVIDED = 'VLAN value not provided',
CONNECTION_POINTS_SIZE = \
'Unexpected number of connection points: 2 expected.',
ENCAPSULATION_TYPE = \
- 'Unexpected service_endpoint_encapsulation_type. \
- Only "dotq1" is accepted.',
+ 'Unexpected service_endpoint_encapsulation_type. ' \
+ 'Only "dotq1" is accepted.',
BANDWIDTH = 'Unable to get the bandwidth.',
STATUS = 'Unable to get the status for the service.',
DELETE = 'Unable to delete service.',
try:
self.__load_topology()
self.__load_switches()
+ except (ConnectTimeout, Timeout) as ct:
+ raise SdnConnectorError(message=SdnError.TIMEOUT + " " + str(ct), http_code=408)
+ except ConnectionError as ce:
+ raise SdnConnectorError(message=SdnError.UNREACHABLE + " " + str(ce), http_code=404)
except SdnConnectorError as sc:
raise sc
+ except CvpLoginError as le:
+ raise SdnConnectorError(message=le.msg, http_code=500) from le
except Exception as e:
- raise SdnConnectorError(message="Unable to load switches from CVP",
+ raise SdnConnectorError(message="Unable to load switches from CVP" + " " + str(e),
http_code=500) from e
self.logger.debug("Using topology {} in Arista Leaf switches: {}".format(
self.topology,
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except Exception as ex:
self.client = None
self.logger.error(str(ex))
- raise SdnConnectorError(message=SdnError.INTERNAL_ERROR,
+ raise SdnConnectorError(message=SdnError.INTERNAL_ERROR + " " + str(ex),
http_code=500) from ex
def get_connectivity_service_status(self, service_uuid, conn_info=None):
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except Exception as ex:
self.client = None
self.logger.error(str(ex), exc_info=True)
- raise SdnConnectorError(message=str(ex),
+ raise SdnConnectorError(message=str(ex) + " " + str(ex),
http_code=500) from ex
def create_connectivity_service(self, service_type, connection_points,
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except SdnConnectorError as sde:
raise sde
if not (cls_perSw.get(s) and cls_perSw[s][0].get('config')):
# when there is no configuration, means that there is no interface
# in the switch to be connected, so the configLet has to be removed from CloudVision
- # after removing the ConfigLet fron the switch if it was already there
+ # after removing the ConfigLet from the switch if it was already there
# get config let name and key
cl = cls_perSw[s]
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except SdnConnectorError as sde:
raise sde
self.logger.error(ex)
if self.raiseException:
raise ex
- raise SdnConnectorError(message=SdnError.INTERNAL_ERROR,
+ raise SdnConnectorError(message=SdnError.INTERNAL_ERROR + " " + str(ex),
http_code=500) from ex
def __addMetadata(self, service_uuid, service_type, vlan_id):
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except SdnConnectorError as sde:
raise sde
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except SdnConnectorError as sde:
raise sde
self.logger.error(ex)
if self.raiseException:
raise ex
- raise SdnConnectorError(message=SdnError.INTERNAL_ERROR,
+ raise SdnConnectorError(message=SdnError.INTERNAL_ERROR + " " + str(ex),
http_code=500) from ex
def get_all_active_connectivity_services(self):
except CvpLoginError as e:
self.logger.info(str(e))
self.client = None
- raise SdnConnectorError(message=SdnError.UNAUTHORIZED,
+ raise SdnConnectorError(message=SdnError.UNAUTHORIZED + " " + str(e),
http_code=401) from e
except SdnConnectorError as sde:
raise sde