예제 #1
0
        class TestObj(base.CinderObject):
            fields = {'foo': fields.Field(fields.Integer())}
            obj_extra_fields = ['bar']

            @property
            def bar(self):
                return 'this is bar'
예제 #2
0
class MyObj(base.CinderPersistentObject, base.CinderObject,
            base.CinderObjectDictCompat):
    VERSION = '1.6'
    fields = {
        'foo': fields.Field(fields.Integer(), default=1),
        'bar': fields.Field(fields.String()),
        'missing': fields.Field(fields.String()),
        'readonly': fields.Field(fields.Integer(), read_only=True),
        'rel_object': fields.ObjectField('MyOwnedObject', nullable=True),
        'rel_objects': fields.ListOfObjectsField('MyOwnedObject',
                                                 nullable=True),
    }

    @staticmethod
    def _from_db_object(context, obj, db_obj):
        self = MyObj()
        self.foo = db_obj['foo']
        self.bar = db_obj['bar']
        self.missing = db_obj['missing']
        self.readonly = 1
        return self

    def obj_load_attr(self, attrname):
        setattr(self, attrname, 'loaded!')

    @base.remotable_classmethod
    def query(cls, context):
        obj = cls(context=context, foo=1, bar='bar')
        obj.obj_reset_changes()
        return obj

    @base.remotable
    def marco(self, context):
        return 'polo'

    @base.remotable
    def _update_test(self, context):
        if context.project_id == 'alternate':
            self.bar = 'alternate-context'
        else:
            self.bar = 'updated'

    @base.remotable
    def save(self, context):
        self.obj_reset_changes()

    @base.remotable
    def refresh(self, context):
        self.foo = 321
        self.bar = 'refreshed'
        self.obj_reset_changes()

    @base.remotable
    def modify_save_modify(self, context):
        self.bar = 'meow'
        self.save()
        self.foo = 42
        self.rel_object = MyOwnedObject(baz=42)

    def obj_make_compatible(self, primitive, target_version):
        super(MyObj, self).obj_make_compatible(primitive, target_version)
        # NOTE(danms): Simulate an older version that had a different
        # format for the 'bar' attribute
        if target_version == '1.1' and 'bar' in primitive:
            primitive['bar'] = 'old%s' % primitive['bar']
예제 #3
0
 class Foo(base.CinderObject):
     fields = {'foobar': fields.Field(fields.Integer())}
예제 #4
0
class MyOwnedObject(base.CinderPersistentObject, base.CinderObject):
    VERSION = '1.0'
    fields = {'baz': fields.Field(fields.Integer())}