Debian Codegraph @

neutron_lib/objects/exceptions.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from oslo_utils import reflection
14
15 from neutron_lib._i18n import _
16 from neutron_lib import exceptions
17
18
19 class NeutronObjectUpdateForbidden(exceptions.NeutronException):
20 message = _("Unable to update the following object fields: %(fields)s")
21
22
23 class NeutronDbObjectDuplicateEntry(exceptions.Conflict):
24 """Duplicate entry at unique column error.
25
26 Raised when made an attempt to write to a unique column the same entry as
27 existing one. :attr: `columns` available on an instance of the exception
28 and could be used at error handling::
29
30 try:
31 obj_ref.save()
32 except NeutronDbObjectDuplicateEntry as e:
33 if 'colname' in e.columns:
34 # Handle error.
35 """
36 message = _("Failed to create a duplicate %(object_type)s: "
37 "for attribute(s) %(attributes)s with value(s) %(values)s")
38
39 def __init__(self, object_class, db_exception):
40 super().__init__(
41 object_type=reflection.get_class_name(object_class,
42 fully_qualified=False),
43 attributes=db_exception.columns,
44 values=db_exception.value)
45 self.columns = db_exception.columns
46 self.value = db_exception.value
47
48
49 class NeutronDbObjectNotFoundByModel(exceptions.NotFound):
50 message = _("NeutronDbObject not found by model %(model)s.")
51
52
53 class NeutronPrimaryKeyMissing(exceptions.BadRequest):
54 message = _("For class %(object_type)s missing primary keys: "
55 "%(missing_keys)s")
56
57 def __init__(self, object_class, missing_keys):
58 super().__init__(
59 object_type=reflection.get_class_name(object_class,
60 fully_qualified=False),
61 missing_keys=missing_keys
62 )
63
64
65 class NeutronRangeConstrainedIntegerInvalidLimit(exceptions.NeutronException):
66 message = _("Incorrect range limits specified: "
67 "start = %(start)s, end = %(end)s")
68
69
70 class NeutronSyntheticFieldMultipleForeignKeys(exceptions.NeutronException):
71 message = _("Synthetic field %(field)s shouldn't have more than one "
72 "foreign key")
73
74
75 class NeutronSyntheticFieldsForeignKeysNotFound(exceptions.NeutronException):
76 message = _("%(child)s does not define a foreign key for %(parent)s")
77
78
79 class NeutronObjectValidatorException(exceptions.NeutronException):
80 message = _("Synthetic field(s) %(fields)s undefined, misspelled, or "
81 "otherwise invalid")