Fix object code direct use of other object modules
The object code itself should not explicitly reference its own objects, as objects could be subclassed. Also: There were a few objects that had their own __init__()s that didn't support accepting 'context' or kwargs. At some point here, we should also require that context is passed when instantiating the objects. So, I added the (currently optional) context argument on some object instantiations near the places I was touching. Partial-Blueprint: object-subclassing Change-Id: Icf631c770e347b4bb32999c4ba2431d1db49e11c
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
|
||||
@@ -165,11 +166,11 @@ class AggregateList(base.ObjectListBase, base.NovaObject):
|
||||
@base.remotable_classmethod
|
||||
def get_all(cls, context):
|
||||
db_aggregates = db.aggregate_get_all(context)
|
||||
return base.obj_make_list(context, AggregateList(), Aggregate,
|
||||
return base.obj_make_list(context, cls(context), objects.Aggregate,
|
||||
db_aggregates)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get_by_host(cls, context, host, key=None):
|
||||
db_aggregates = db.aggregate_get_by_host(context, host, key=key)
|
||||
return base.obj_make_list(context, AggregateList(), Aggregate,
|
||||
return base.obj_make_list(context, cls(context), objects.Aggregate,
|
||||
db_aggregates)
|
||||
|
||||
@@ -18,6 +18,7 @@ from nova.cells import opts as cells_opts
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
from nova.openstack.common.gettextutils import _LE
|
||||
@@ -106,5 +107,5 @@ class InstanceFaultList(base.ObjectListBase, base.NovaObject):
|
||||
db_faultdict = db.instance_fault_get_by_instance_uuids(context,
|
||||
instance_uuids)
|
||||
db_faultlist = itertools.chain(*db_faultdict.values())
|
||||
return base.obj_make_list(context, InstanceFaultList(), InstanceFault,
|
||||
return base.obj_make_list(context, cls(context), objects.InstanceFault,
|
||||
db_faultlist)
|
||||
|
||||
@@ -72,7 +72,7 @@ class InstanceGroup(base.NovaPersistentObject, base.NovaObject):
|
||||
# db.api method for this yet. Come back and optimize this by
|
||||
# adding a new query by name. This is unnecessarily expensive if a
|
||||
# tenant has lots of groups.
|
||||
igs = InstanceGroupList.get_by_project_id(context,
|
||||
igs = objects.InstanceGroupList.get_by_project_id(context,
|
||||
context.project_id)
|
||||
for ig in igs:
|
||||
if ig.name == name:
|
||||
@@ -181,11 +181,11 @@ class InstanceGroupList(base.ObjectListBase, base.NovaObject):
|
||||
@base.remotable_classmethod
|
||||
def get_by_project_id(cls, context, project_id):
|
||||
groups = db.instance_group_get_all_by_project_id(context, project_id)
|
||||
return base.obj_make_list(context, InstanceGroupList(), InstanceGroup,
|
||||
return base.obj_make_list(context, cls(context), objects.InstanceGroup,
|
||||
groups)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get_all(cls, context):
|
||||
groups = db.instance_group_get_all(context)
|
||||
return base.obj_make_list(context, InstanceGroupList(), InstanceGroup,
|
||||
return base.obj_make_list(context, cls(context), objects.InstanceGroup,
|
||||
groups)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import objects
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
|
||||
@@ -79,7 +80,8 @@ class KeyPairList(base.ObjectListBase, base.NovaObject):
|
||||
@base.remotable_classmethod
|
||||
def get_by_user(cls, context, user_id):
|
||||
db_keypairs = db.key_pair_get_all_by_user(context, user_id)
|
||||
return base.obj_make_list(context, KeyPairList(), KeyPair, db_keypairs)
|
||||
return base.obj_make_list(context, cls(context), objects.KeyPair,
|
||||
db_keypairs)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get_count_by_user(cls, context, user_id):
|
||||
|
||||
Reference in New Issue
Block a user