Feature 10937: Transport API (TAPI) WIM connector for RO
[osm/RO.git] / RO-SDN-tapi / osm_rosdn_tapi / exceptions.py
1 # -*- coding: utf-8 -*-
2
3 #######################################################################################
4 # This file is part of OSM RO module
5 #
6 # Copyright ETSI Contributors and Others.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #######################################################################################
20 # This work has been performed in the context of the TeraFlow Project -
21 # funded by the European Commission under Grant number 101015857 through the
22 # Horizon 2020 program.
23 # Contributors:
24 # - Lluis Gifre <lluis.gifre@cttc.es>
25 # - Ricard Vilalta <ricard.vilalta@cttc.es>
26 #######################################################################################
27
28 """This file contains the exception classes the Transport API (TAPI) WIM connector
29 can raise in case of error."""
30
31
32 from http import HTTPStatus
33
34 from osm_ro_plugin.sdnconn import SdnConnectorError
35
36 from .log_messages import (
37 _PREFIX,
38 )
39
40
41 class WimTapiError(SdnConnectorError):
42 """Base Exception for all WIM TAPI related errors."""
43
44 def __init__(self, message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR.value):
45 super().__init__(_PREFIX + message)
46 self.http_code = http_code
47
48
49 class WimTapiConnectionPointsBadFormat(SdnConnectorError):
50 def __init__(self, connection_points):
51 MESSAGE = "ConnectionPoints({:s}) must be a list or tuple of length 2"
52 message = MESSAGE.format(str(connection_points))
53 super().__init__(message, http_code=HTTPStatus.BAD_REQUEST)
54
55
56 class WimTapiIncongruentDirectionality(WimTapiError):
57 def __init__(self, services, service_endpoint_id):
58 MESSAGE = "Incongruent directionality: services={:s} service_endpoint_id={:s}"
59 message = MESSAGE.format(str(services), str(service_endpoint_id))
60 super().__init__(message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
61
62
63 class WimTapiIncongruentEndPoints(WimTapiError):
64 def __init__(self, services, service_endpoint_id):
65 MESSAGE = "Incongruent endpoints: services={:s} service_endpoint_id={:s}"
66 message = MESSAGE.format(str(services), str(service_endpoint_id))
67 super().__init__(message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
68
69
70 class WimTapiMissingConnPointField(WimTapiError):
71 def __init__(self, connection_point, field_name):
72 MESSAGE = "ConnectionPoint({:s}) has no field '{:s}'"
73 message = MESSAGE.format(str(connection_point), str(field_name))
74 super().__init__(message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
75
76
77 class WimTapiMissingMappingField(WimTapiError):
78 def __init__(self, mapping, field_name):
79 MESSAGE = "Mapping({:s}) has no field '{:s}'"
80 message = MESSAGE.format(str(mapping), str(field_name))
81 super().__init__(message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
82
83
84 class WimTapiServerNotAvailable(WimTapiError):
85 def __init__(self, message):
86 message = "Server not available: " + message
87 super().__init__(message, http_code=HTTPStatus.SERVICE_UNAVAILABLE)
88
89
90 class WimTapiServerRequestFailed(WimTapiError):
91 def __init__(self, message, http_code):
92 message = "Server request failed: " + message
93 super().__init__(message, http_code=http_code)
94
95
96 class WimTapiSipNotFound(WimTapiError):
97 def __init__(self, sip_id, sips):
98 MESSAGE = "SIP({:s}) not found in context SIPs({:s})"
99 message = MESSAGE.format(str(sip_id), str(sips))
100 super().__init__(message, http_code=HTTPStatus.INTERNAL_SERVER_ERROR)
101
102
103 class WimTapiConnectivityServiceCreateFailed(WimTapiError):
104 def __init__(self, name, service_id, status_code, reply):
105 MESSAGE = "Create ConnectivityService({:s}, {:s}) Failed: reply={:s}"
106 message = MESSAGE.format(str(name), str(service_id), str(reply))
107 super().__init__(message, http_code=status_code)
108
109
110 class WimTapiConnectivityServiceGetStatusFailed(WimTapiError):
111 def __init__(self, name, service_id, status_code, reply):
112 MESSAGE = "Get Status of ConnectivityService({:s}, {:s}) Failed: reply={:s}"
113 message = MESSAGE.format(str(name), str(service_id), str(reply))
114 super().__init__(message, http_code=status_code)
115
116
117 class WimTapiConnectivityServiceDeleteFailed(WimTapiError):
118 def __init__(self, name, service_id, status_code, reply):
119 MESSAGE = "Delete ConnectivityService({:s}, {:s}) Failed: reply={:s}"
120 message = MESSAGE.format(str(name), str(service_id), str(reply))
121 super().__init__(message, http_code=status_code)
122
123
124 class WimTapiUnsupportedServiceType(SdnConnectorError):
125 def __init__(self, service_type, supported_service_types):
126 MESSAGE = "Unsupported ServiceType({:s}). Supported ServiceTypes({:s})"
127 message = MESSAGE.format(str(service_type), str(supported_service_types))
128 super().__init__(message, http_code=HTTPStatus.BAD_REQUEST)