From 55f007be2c6d23b960e41feecbd4b3773d10e229 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 26 Aug 2013 11:39:44 -0700 Subject: [PATCH] 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 --- nova/objects/aggregate.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index bbb35e4f8..382082290 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -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)