1 # -*- coding: utf-8 -*-
3 # Copyright 2018 University of Bristol - High Performance Networks Research
7 # Contributors: Anderson Bravalheri, Dimitrios Gkounis, Abubakar Siddique
8 # Muqaddas, Navdeep Uniyal, Reza Nejabati and Dimitra Simeonidou
10 # Licensed under the Apache License, Version 2.0 (the "License"); you may
11 # not use this file except in compliance with the License. You may obtain
12 # a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19 # License for the specific language governing permissions and limitations
22 # For those usages not covered by the Apache License, Version 2.0 please
23 # contact with: <highperformance-networks@bristol.ac.uk>
25 # Neither the name of the University of Bristol nor the names of its
26 # contributors may be used to endorse or promote products derived from
27 # this software without specific prior written permission.
29 # This work has been performed in the context of DCMS UK 5G Testbeds
30 # & Trials Programme and in the framework of the Metro-Haul project -
31 # funded by the European Commission under Grant number 761727 through the
32 # Horizon 2020 and 5G-PPP programmes.
36 from ..db_base
import db_base_Exception
as DbBaseException
37 from ..http_tools
.errors
import (
41 Internal_Server_Error
,
46 class NoRecordFound(DbBaseException
):
47 """No record was found in the database"""
49 def __init__(self
, criteria
, table
=None):
50 table_info
= '{} - '.format(table
) if table
else ''
51 super(NoRecordFound
, self
).__init
__(
52 '{}: {}`{}`'.format(self
.__class
__.__doc
__, table_info
, criteria
),
56 class MultipleRecordsFound(DbBaseException
):
57 """More than one record was found in the database"""
59 def __init__(self
, criteria
, table
=None):
60 table_info
= '{} - '.format(table
) if table
else ''
61 super(MultipleRecordsFound
, self
).__init
__(
62 '{}: {}`{}`'.format(self
.__class
__.__doc
__, table_info
, criteria
),
66 class WimAndTenantNotAttached(DbBaseException
):
67 """Wim and Tenant are not attached"""
69 def __init__(self
, wim
, tenant
):
70 super(WimAndTenantNotAttached
, self
).__init
__(
71 '{}: `{}` <> `{}`'.format(self
.__class
__.__doc
__, wim
, tenant
),
75 class WimAndTenantAlreadyAttached(DbBaseException
):
76 """There is already a wim account attaching the given wim and tenant"""
78 def __init__(self
, wim
, tenant
):
79 super(WimAndTenantAlreadyAttached
, self
).__init
__(
80 '{}: `{}` <> `{}`'.format(self
.__class
__.__doc
__, wim
, tenant
),
84 class NoWimConnectedToDatacenters(NoRecordFound
):
85 """No WIM that is able to connect the given datacenters was found"""
88 class InvalidParameters(DbBaseException
):
89 """The given parameters are invalid"""
91 def __init__(self
, message
, http_code
=Bad_Request
):
92 super(InvalidParameters
, self
).__init
__(message
, http_code
)
95 class UndefinedAction(HttpMappedError
):
98 def __init__(self
, item_type
, action
, http_code
=Internal_Server_Error
):
99 message
= ('The action {} {} is not defined'.format(action
, item_type
))
100 super(UndefinedAction
, self
).__init
__(message
, http_code
)
103 class UndefinedWimConnector(DbBaseException
):
104 """The connector class for the specified wim type is not implemented"""
106 def __init__(self
, wim_type
, module_name
):
107 super(UndefinedWimConnector
, self
).__init
__("Cannot load a module for {t} type '{n}'. The plugin 'osm_{n}' has"
108 " not been registered".format(t
=wim_type
, n
=module_name
),
109 http_code
=Bad_Request
)
112 class WimAccountOverwrite(DbBaseException
):
113 """An attempt to overwrite an existing WIM account was identified"""
115 def __init__(self
, wim_account
, diff
=None, tip
=None):
116 message
= self
.__class
__.__doc
__
118 'Account -- name: {name}, uuid: {uuid}'.format(**wim_account
)
119 if wim_account
else '')
121 'Differing fields: ' + ', '.join(diff
.keys()) if diff
else '')
123 super(WimAccountOverwrite
, self
).__init
__(
124 '\n'.join(m
for m
in (message
, account_info
, diff_info
, tip
) if m
),
128 class UnexpectedDatabaseError(DbBaseException
):
129 """The database didn't raised an exception but also the query was not
130 executed (maybe the connection had some problems?)
134 class UndefinedUuidOrName(DbBaseException
):
135 """Trying to query for a record using an empty uuid or name"""
137 def __init__(self
, table
=None):
138 table_info
= '{} - '.format(table
.split()[0]) if table
else ''
139 super(UndefinedUuidOrName
, self
).__init
__(
140 table_info
+ self
.__class
__.__doc
__, http_status
=Bad_Request
)
143 class UndefinedWanMappingType(InvalidParameters
):
144 """The dict service_mapping_info MUST contain a `type` field"""
146 def __init__(self
, given
):
147 super(UndefinedWanMappingType
, self
).__init
__(
148 '{}. Given: `{}`'.format(self
.__class
__.__doc
__, given
))
151 class QueueFull(HttpMappedError
, queue
.Full
):
152 """Thread queue is full"""
154 def __init__(self
, thread_name
, http_code
=Internal_Server_Error
):
155 message
= ('Thread {} queue is full'.format(thread_name
))
156 super(QueueFull
, self
).__init
__(message
, http_code
)
159 class InconsistentState(HttpMappedError
):
160 """An unexpected inconsistency was find in the state of the program"""
162 def __init__(self
, arg
, http_code
=Internal_Server_Error
):
163 if isinstance(arg
, HttpMappedError
):
164 http_code
= arg
.http_code
169 super(InconsistentState
, self
).__init
__(message
, http_code
)
172 class WimAccountNotActive(HttpMappedError
, KeyError):
173 """WIM Account is not active yet (no thread is running)"""
175 def __init__(self
, message
, http_code
=Internal_Server_Error
):
176 message
+= ('\nThe thread responsible for processing the actions have '
177 'suddenly stopped, or have never being spawned')
178 super(WimAccountNotActive
, self
).__init
__(message
, http_code
)
181 class NoExternalPortFound(HttpMappedError
):
182 """No external port associated to the instance_net"""
184 def __init__(self
, instance_net
):
185 super(NoExternalPortFound
, self
).__init
__(
186 '{} uuid({})'.format(self
.__class
__.__doc
__, instance_net
['uuid']),