Debian Codegraph @

neutron_lib/objects/logapi/event_types.py

raw
1 # All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from oslo_versionedobjects import fields as obj_fields
16
17 from neutron_lib._i18n import _
18 from neutron_lib.services.logapi import constants as log_const
19
20
21 class SecurityEvent(obj_fields.String):
22 def __init__(self, valid_values, **kwargs):
23 self._valid_values = valid_values
24 super().__init__(**kwargs)
25
26 def coerce(self, obj, attr, value):
27 if value not in self._valid_values:
28 msg = (
29 _("Field value %(value)s is not in the list "
30 "of valid values: %(values)s") %
31 {'value': value, 'values': self._valid_values}
32 )
33 raise ValueError(msg)
34 return super().coerce(obj, attr, value)
35
36
37 class SecurityEventField(obj_fields.AutoTypedField):
38 AUTO_TYPE = SecurityEvent(valid_values=log_const.LOG_EVENTS)