summaryrefslogtreecommitdiff
path: root/nova
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2013-10-14 15:47:03 -0700
committerDan Smith <dansmith@redhat.com>2013-10-21 14:26:25 -0700
commit106efc7a3565138dc349c716d0d437cdf09bafe2 (patch)
tree640a921161d9c2c2ae5eea32434cebe9ac56d611 /nova
parent37e143c4eb701d716dc61ba08d3b0119c82594f5 (diff)
downloadnova-106efc7a3565138dc349c716d0d437cdf09bafe2.tar.gz
Make Object FieldType take an object name instead of a class
The object infrastructure has a concept of an object name, which is what we use to determine if something implements a particular thing, and it is how we look up object classes when we deserialize them. Since many objects will eventually reference each other, we should be using their names to determine compatibility, not their classes. Related to blueprint structured-object-fields Change-Id: I2edb8b8475662ad25e9f3319ce5e44317a2d0547
Diffstat (limited to 'nova')
-rw-r--r--nova/objects/aggregate.py4
-rw-r--r--nova/objects/base.py2
-rw-r--r--nova/objects/compute_node.py4
-rw-r--r--nova/objects/fields.py15
-rw-r--r--nova/objects/instance.py17
-rw-r--r--nova/objects/instance_action.py8
-rw-r--r--nova/objects/instance_fault.py4
-rw-r--r--nova/objects/instance_group.py3
-rw-r--r--nova/objects/keypair.py4
-rw-r--r--nova/objects/migration.py4
-rw-r--r--nova/objects/pci_device.py4
-rw-r--r--nova/objects/security_group.py4
-rw-r--r--nova/objects/service.py6
-rw-r--r--nova/tests/objects/test_fields.py2
-rw-r--r--nova/tests/objects/test_objects.py10
15 files changed, 69 insertions, 22 deletions
diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py
index c9528c07b0..6e6018fa57 100644
--- a/nova/objects/aggregate.py
+++ b/nova/objects/aggregate.py
@@ -149,6 +149,10 @@ class AggregateList(base.ObjectListBase, base.NovaObject):
# Version 1.1: Added key argument to get_by_host()
VERSION = '1.1'
+ fields = {
+ 'objects': fields.ListOfObjectsField('Aggregate'),
+ }
+
@base.remotable_classmethod
def get_all(cls, context):
db_aggregates = db.aggregate_get_all(context)
diff --git a/nova/objects/base.py b/nova/objects/base.py
index d161ad5bf7..057df5e5ae 100644
--- a/nova/objects/base.py
+++ b/nova/objects/base.py
@@ -410,7 +410,7 @@ class ObjectListBase(object):
serialization of the list of objects automatically.
"""
fields = {
- 'objects': fields.ListOfObjectsField(NovaObject),
+ 'objects': fields.ListOfObjectsField('NovaObject'),
}
def __iter__(self):
diff --git a/nova/objects/compute_node.py b/nova/objects/compute_node.py
index fbdfc7be56..23a51e6a3b 100644
--- a/nova/objects/compute_node.py
+++ b/nova/objects/compute_node.py
@@ -90,6 +90,10 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject):
class ComputeNodeList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('ComputeNode'),
+ }
+
@base.remotable_classmethod
def get_all(cls, context):
db_computes = db.compute_node_get_all(context)
diff --git a/nova/objects/fields.py b/nova/objects/fields.py
index 857e3a4074..1af2824760 100644
--- a/nova/objects/fields.py
+++ b/nova/objects/fields.py
@@ -324,14 +324,19 @@ class Dict(CompoundFieldType):
class Object(FieldType):
- def __init__(self, objtype, **kwargs):
- self._objtype = objtype
+ def __init__(self, obj_name, **kwargs):
+ self._obj_name = obj_name
super(Object, self).__init__(**kwargs)
def coerce(self, obj, attr, value):
- if not isinstance(value, self._objtype):
+ try:
+ obj_name = value.obj_name()
+ except AttributeError:
+ obj_name = ""
+
+ if obj_name != self._obj_name:
raise ValueError(_('An object of type %s is required here') %
- self._objtype.obj_name())
+ self._obj_name)
return value
def to_primitive(self, obj, attr, value):
@@ -343,7 +348,7 @@ class Object(FieldType):
return obj_base.NovaObject.obj_from_primitive(value, obj._context)
def describe(self):
- return "Object<%s>" % self._objtype.obj_name()
+ return "Object<%s>" % self._obj_name
class NetworkModel(FieldType):
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index 405690deae..508a50d2e1 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -144,19 +144,16 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
'metadata': fields.DictOfStringsField(),
'system_metadata': fields.DictOfNullableStringsField(),
- 'info_cache': fields.ObjectField(
- instance_info_cache.InstanceInfoCache, nullable=True),
+ 'info_cache': fields.ObjectField('InstanceInfoCache',
+ nullable=True),
- 'security_groups': fields.ObjectField(
- security_group.SecurityGroupList),
+ 'security_groups': fields.ObjectField('SecurityGroupList'),
- 'fault': fields.ObjectField(instance_fault.InstanceFault,
- nullable=True),
+ 'fault': fields.ObjectField('InstanceFault', nullable=True),
'cleaned': fields.BooleanField(default=False),
- 'pci_devices': fields.ObjectField(pci_device.PciDeviceList,
- nullable=True),
+ 'pci_devices': fields.ObjectField('PciDeviceList', nullable=True),
}
obj_extra_fields = ['name']
@@ -490,6 +487,10 @@ def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
class InstanceList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('Instance'),
+ }
+
@base.remotable_classmethod
def get_by_filters(cls, context, filters,
sort_key='created_at', sort_dir='desc', limit=None,
diff --git a/nova/objects/instance_action.py b/nova/objects/instance_action.py
index 741b919975..63c5d1153d 100644
--- a/nova/objects/instance_action.py
+++ b/nova/objects/instance_action.py
@@ -77,6 +77,10 @@ class InstanceAction(base.NovaPersistentObject, base.NovaObject):
class InstanceActionList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('InstanceAction'),
+ }
+
@base.remotable_classmethod
def get_by_instance_uuid(cls, context, instance_uuid):
db_actions = db.actions_get(context, instance_uuid)
@@ -150,6 +154,10 @@ class InstanceActionEvent(base.NovaPersistentObject, base.NovaObject):
class InstanceActionEventList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('InstanceActionEvent'),
+ }
+
@base.remotable_classmethod
def get_by_action(cls, context, action_id):
db_events = db.action_events_get(context, action_id)
diff --git a/nova/objects/instance_fault.py b/nova/objects/instance_fault.py
index 0c4f786c93..9e853aebc8 100644
--- a/nova/objects/instance_fault.py
+++ b/nova/objects/instance_fault.py
@@ -58,6 +58,10 @@ def _make_fault_list(faultlist, db_faultlist):
class InstanceFaultList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('InstanceFault'),
+ }
+
@base.remotable_classmethod
def get_by_instance_uuids(cls, context, instance_uuids):
db_faults = db.instance_fault_get_by_instance_uuids(context,
diff --git a/nova/objects/instance_group.py b/nova/objects/instance_group.py
index 6d743ff558..768c0098cc 100644
--- a/nova/objects/instance_group.py
+++ b/nova/objects/instance_group.py
@@ -123,6 +123,9 @@ def _make_instance_group_list(context, inst_list, db_list):
class InstanceGroupList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('InstanceGroup'),
+ }
@base.remotable_classmethod
def get_by_project_id(cls, context, project_id):
diff --git a/nova/objects/keypair.py b/nova/objects/keypair.py
index 9f937106b1..83678bcd88 100644
--- a/nova/objects/keypair.py
+++ b/nova/objects/keypair.py
@@ -59,6 +59,10 @@ class KeyPair(base.NovaPersistentObject, base.NovaObject):
class KeyPairList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('KeyPair'),
+ }
+
@base.remotable_classmethod
def get_by_user(cls, context, user_id):
db_keypairs = db.key_pair_get_all_by_user(context, user_id)
diff --git a/nova/objects/migration.py b/nova/objects/migration.py
index 65adcecaa8..2bf16b4f79 100644
--- a/nova/objects/migration.py
+++ b/nova/objects/migration.py
@@ -86,6 +86,10 @@ def _make_list(context, list_obj, item_cls, db_list):
class MigrationList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('Migration'),
+ }
+
@base.remotable_classmethod
def get_unconfirmed_by_dest_compute(cls, context, confirm_window,
dest_compute):
diff --git a/nova/objects/pci_device.py b/nova/objects/pci_device.py
index 3398ceceac..8aa0cd69a4 100644
--- a/nova/objects/pci_device.py
+++ b/nova/objects/pci_device.py
@@ -251,6 +251,10 @@ def _make_pci_list(context, pci_list, db_list):
class PciDeviceList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('PciDevice'),
+ }
+
def __init__(self):
super(PciDeviceList, self).__init__()
self.objects = []
diff --git a/nova/objects/security_group.py b/nova/objects/security_group.py
index a91b7b38b3..276220344d 100644
--- a/nova/objects/security_group.py
+++ b/nova/objects/security_group.py
@@ -82,6 +82,10 @@ def _make_secgroup_list(context, secgroup_list, db_secgroup_list):
class SecurityGroupList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('SecurityGroup'),
+ }
+
def __init__(self):
super(SecurityGroupList, self).__init__()
self.objects = []
diff --git a/nova/objects/service.py b/nova/objects/service.py
index ac5b509fd8..d3c4625759 100644
--- a/nova/objects/service.py
+++ b/nova/objects/service.py
@@ -40,7 +40,7 @@ class Service(base.NovaPersistentObject, base.NovaObject):
'disabled': fields.BooleanField(),
'disabled_reason': fields.StringField(nullable=True),
'availability_zone': fields.StringField(nullable=True),
- 'compute_node': fields.ObjectField(compute_node.ComputeNode),
+ 'compute_node': fields.ObjectField('ComputeNode'),
}
@staticmethod
@@ -124,6 +124,10 @@ class Service(base.NovaPersistentObject, base.NovaObject):
class ServiceList(base.ObjectListBase, base.NovaObject):
+ fields = {
+ 'objects': fields.ListOfObjectsField('Service'),
+ }
+
@base.remotable_classmethod
def get_by_topic(cls, context, topic):
db_services = db.service_get_all_by_topic(context, topic)
diff --git a/nova/tests/objects/test_fields.py b/nova/tests/objects/test_fields.py
index 09446f4936..c6807d7782 100644
--- a/nova/tests/objects/test_fields.py
+++ b/nova/tests/objects/test_fields.py
@@ -195,7 +195,7 @@ class TestObject(TestField):
test_inst = TestableObject()
super(TestObject, self).setUp()
- self.field = fields.Field(fields.Object(TestableObject))
+ self.field = fields.Field(fields.Object('TestableObject'))
self.coerce_good_values = [(test_inst, test_inst)]
self.coerce_bad_values = [OtherTestableObject(), 1, 'foo']
self.to_primitive_values = [(test_inst, test_inst.obj_to_primitive())]
diff --git a/nova/tests/objects/test_objects.py b/nova/tests/objects/test_objects.py
index 1e46e15258..4d8194815b 100644
--- a/nova/tests/objects/test_objects.py
+++ b/nova/tests/objects/test_objects.py
@@ -240,8 +240,7 @@ class TestUtils(test.TestCase):
self.foo = foo
class MyList(base.ObjectListBase, base.NovaObject):
- fields = {'objects': fields.Field(fields.List(
- fields.Field(fields.Object(MyObjElement))))}
+ fields = {'objects': fields.ListOfObjectsField('MyObjElement')}
mylist = MyList()
mylist.objects = [MyObjElement(1), MyObjElement(2), MyObjElement(3)]
@@ -257,7 +256,7 @@ class TestUtils(test.TestCase):
def test_obj_to_primitive_recursive(self):
class MyList(base.ObjectListBase, base.NovaObject):
- pass
+ fields = {'objects': fields.ListOfObjectsField('MyObj')}
mylist = MyList()
mylist.objects = [MyObj(), MyObj()]
@@ -686,8 +685,7 @@ class TestObjectListBase(test.TestCase):
self.foo = foo
class Foo(base.ObjectListBase, base.NovaObject):
- fields = {'objects': fields.Field(fields.List(
- fields.Field(fields.Object(MyElement))))}
+ fields = {'objects': fields.ListOfObjectsField('MyElement')}
objlist = Foo()
objlist._context = 'foo'
@@ -703,7 +701,7 @@ class TestObjectListBase(test.TestCase):
def test_serialization(self):
class Foo(base.ObjectListBase, base.NovaObject):
- pass
+ fields = {'objects': fields.ListOfObjectsField('Bar')}
class Bar(base.NovaObject):
fields = {'foo': fields.Field(fields.String())}