Generalize the _make_list() function for objects
Each object with a list duplicated the _make_list() method in its own module. This removes that duplication and adds a generalized helper in objects/base.py. The instance object still uses its own because it has to do a bunch of other stuff in the loop for efficiency. Change-Id: Ic910f39087ebc167b2b930979f7951116caf8598
This commit is contained in:
@@ -144,22 +144,15 @@ class Aggregate(base.NovaObject):
|
||||
return self.metadata.get('availability_zone', None)
|
||||
|
||||
|
||||
def _make_list(context, list_obj, item_cls, db_list):
|
||||
list_obj.objects = []
|
||||
for db_item in db_list:
|
||||
item = item_cls._from_db_object(context, item_cls(), db_item)
|
||||
list_obj.objects.append(item)
|
||||
list_obj.obj_reset_changes()
|
||||
return list_obj
|
||||
|
||||
|
||||
class AggregateList(base.ObjectListBase, base.NovaObject):
|
||||
@base.remotable_classmethod
|
||||
def get_all(cls, context):
|
||||
db_aggregates = db.aggregate_get_all(context)
|
||||
return _make_list(context, AggregateList(), Aggregate, db_aggregates)
|
||||
return base.obj_make_list(context, AggregateList(), Aggregate,
|
||||
db_aggregates)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def get_by_host(cls, context, host):
|
||||
db_aggregates = db.aggregate_get_by_host(context, host)
|
||||
return _make_list(context, AggregateList(), Aggregate, db_aggregates)
|
||||
return base.obj_make_list(context, AggregateList(), Aggregate,
|
||||
db_aggregates)
|
||||
|
Reference in New Issue
Block a user