def obj_class_from_name(cls, objname, objver): """Returns a class from the registry based on a name and version.""" if objname not in cls._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 cls._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 = cls._obj_classes[objname][0].VERSION raise exception.IncompatibleObjectVersion(objname=objname, objver=objver, supported=latest_ver)
def obj_class_from_name(cls, objname, objver): """Returns a class from the registry based on a name and version.""" if objname not in cls._obj_classes: LOG.error( _('Unable to instantiate unregistered object type ' '%(objtype)s') % dict(objtype=objname)) raise exception.UnsupportedObjectError(objtype=objname) latest = None compatible_match = None for objclass in cls._obj_classes[objname]: if objclass.VERSION == objver: return objclass version_bits = tuple([int(x) for x in objclass.VERSION.split(".")]) if latest is None: latest = version_bits elif latest < version_bits: latest = version_bits if versionutils.is_compatible(objver, objclass.VERSION): compatible_match = objclass if compatible_match: return compatible_match latest_ver = '%i.%i' % latest raise exception.IncompatibleObjectVersion(objname=objname, objver=objver, supported=latest_ver)
def obj_from_primitive(cls, primitive, context=None): """Object field-by-field hydration.""" if primitive['nova_object.namespace'] != 'nova': # NOTE(danms): We don't do anything with this now, but it's # there for "the future" raise exception.UnsupportedObjectError( objtype='%s.%s' % (primitive['nova_object.namespace'], primitive['nova_object.name'])) objname = primitive['nova_object.name'] objver = primitive['nova_object.version'] objclass = cls.obj_class_from_name(objname, objver) return objclass._obj_from_primitive(context, objver, primitive)
def obj_class_from_name(cls, objname, objver): """Returns a class from the registry based on a name and version.""" if objname not in cls._obj_classes: LOG.error(_('Unable to instantiate unregistered object type ' '%(objtype)s') % dict(objtype=objname)) raise exception.UnsupportedObjectError(objtype=objname) compatible_match = None for objclass in cls._obj_classes[objname]: if objclass.VERSION == objver: return objclass if versionutils.is_compatible(objver, objclass.VERSION): compatible_match = objclass if compatible_match: return compatible_match raise exception.IncompatibleObjectVersion(objname=objname, objver=objver)
def obj_from_primitive(cls, primitive, context=None): """Object field-by-field hydration.""" if primitive['nova_object.namespace'] != 'nova': # NOTE(danms): We don't do anything with this now, but it's # there for "the future" raise exception.UnsupportedObjectError( objtype='%s.%s' % (primitive['nova_object.namespace'], primitive['nova_object.name'])) objname = primitive['nova_object.name'] objver = primitive['nova_object.version'] objdata = primitive['nova_object.data'] objclass = cls.obj_class_from_name(objname, objver) self = objclass() self._context = context for name, field in self.fields.items(): if name in objdata: setattr(self, name, field.from_primitive(self, name, objdata[name])) changes = primitive.get('nova_object.changes', []) self._changed_fields = set([x for x in changes if x in self.fields]) return self
def obj_from_primitive(cls, primitive): """Simple base-case hydration. This calls self._attr_from_primitive() for each item in fields. """ if primitive['nova_object.namespace'] != 'nova': # NOTE(danms): We don't do anything with this now, but it's # there for "the future" raise exception.UnsupportedObjectError( objtype='%s.%s' % (primitive['nova_object.namespace'], primitive['nova_object.name'])) objname = primitive['nova_object.name'] objver = primitive['nova_object.version'] objdata = primitive['nova_object.data'] objclass = cls.obj_class_from_name(objname, objver) self = objclass() for name in self.fields: if name in objdata: setattr(self, name, self._attr_from_primitive(name, objdata[name])) changes = primitive.get('nova_object.changes', []) self._changed_fields = set([x for x in changes if x in self.fields]) return self