def __init__(self, message=None, **kwargs): self.kwargs = kwargs if "code" not in self.kwargs: try: self.kwargs["code"] = self.code except AttributeError: pass if not message: try: message = self.msg_fmt % kwargs except Exception: exc_info = sys.exc_info() # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception(_LE("Exception in string format operation")) for name, value in kwargs.items(): LOG.error("%s: %s" % (name, value)) # noqa if CONF.oslo_versionedobjects.fatal_exception_format_errors: raise six.reraise(*exc_info) else: # at least get the core message out if something happened message = self.msg_fmt super(VersionedObjectsException, self).__init__(message)
def obj_class_from_name(cls, objname, objver): """Returns a class from the registry based on a name and version.""" if objname not in VersionedObjectRegistry.obj_classes(): LOG.error(_LE('Unable to instantiate unregistered object type ' '%(objtype)s'), dict(objtype=objname)) raise exception.UnsupportedObjectError(objtype=objname) # NOTE(comstud): If there's not an exact match, return the highest # compatible version. The objects stored in the class are sorted # such that highest version is first, so only set compatible_match # once below. compatible_match = None for objclass in VersionedObjectRegistry.obj_classes()[objname]: if objclass.VERSION == objver: return objclass if (not compatible_match and versionutils.is_compatible(objver, objclass.VERSION)): compatible_match = objclass if compatible_match: return compatible_match # As mentioned above, latest version is always first in the list. latest_ver = VersionedObjectRegistry.obj_classes()[objname][0].VERSION raise exception.IncompatibleObjectVersion(objname=objname, objver=objver, supported=latest_ver)
def __init__(self, message=None, **kwargs): self.kwargs = kwargs if 'code' not in self.kwargs: try: self.kwargs['code'] = self.code except AttributeError: pass if not message: try: message = self.msg_fmt % kwargs except Exception: exc_info = sys.exc_info() # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception(_LE('Exception in string format operation')) for name, value in kwargs.items(): LOG.error("%s: %s" % (name, value)) # noqa if CONF.oslo_versionedobjects.fatal_exception_format_errors: raise six.reraise(*exc_info) else: # at least get the core message out if something happened message = self.msg_fmt super(VersionedObjectsException, self).__init__(message)
def obj_class_from_name(cls, objname, objver): """Returns a class from the registry based on a name and version.""" if objname not in VersionedObjectRegistry.obj_classes(): LOG.error( _LE('Unable to instantiate unregistered object type ' '%(objtype)s'), dict(objtype=objname)) raise exception.UnsupportedObjectError(objtype=objname) # NOTE(comstud): If there's not an exact match, return the highest # compatible version. The objects stored in the class are sorted # such that highest version is first, so only set compatible_match # once below. compatible_match = None for objclass in VersionedObjectRegistry.obj_classes()[objname]: if objclass.VERSION == objver: return objclass if (not compatible_match and vutils.is_compatible(objver, objclass.VERSION)): compatible_match = objclass if compatible_match: return compatible_match # As mentioned above, latest version is always first in the list. latest_ver = VersionedObjectRegistry.obj_classes()[objname][0].VERSION raise exception.IncompatibleObjectVersion(objname=objname, objver=objver, supported=latest_ver)
def setter(self, value, name=name, field=field): attrname = _get_attrname(name) field_value = field.coerce(self, name, value) if field.read_only and hasattr(self, attrname): # Note(yjiang5): _from_db_object() may iterate # every field and write, no exception in such situation. if getattr(self, attrname) != field_value: raise exception.ReadOnlyFieldError(field=name) else: return self._changed_fields.add(name) try: return setattr(self, attrname, field_value) except Exception: attr = "%s.%s" % (self.obj_name(), name) LOG.exception(_LE('Error setting %(attr)s'), {'attr': attr}) raise
def setter(self, value, name=name, field=field): attrname = _get_attrname(name) field_value = field.coerce(self, name, value) if field.read_only and hasattr(self, attrname): # Note(yjiang5): _from_db_object() may iterate # every field and write, no exception in such situation. if getattr(self, attrname) != field_value: raise exception.ReadOnlyFieldError(field=name) else: return self._changed_fields.add(name) try: return setattr(self, attrname, field_value) except Exception: with excutils.save_and_reraise_exception(): attr = "%s.%s" % (self.obj_name(), name) LOG.exception(_LE('Error setting %(attr)s'), {'attr': attr})
def coerce(obj, attr, value): if isinstance(value, six.string_types): lowered = value.lower().replace('-', ':') if MACAddress._REGEX.match(lowered): return lowered raise ValueError(_LE("Malformed MAC %s"), value)
def coerce(obj, attr, value): if isinstance(value, six.string_types): newvalue = value.lower() if PCIAddress._REGEX.match(newvalue): return newvalue raise ValueError(_LE("Malformed PCI address %s"), value)