Clean up duplicated change-building code in objects

Almost every object thus far has done this:

  changes = {}
  for key in self.obj_what_changed():
      changes[key] = self[key]

to get a dict of updates to apply to the database. This patch adds
that as part of the base object and makes every place that does
the above to just use that.

Change-Id: I847f5d35181b0305668b107f86faa164e71c3375
This commit is contained in:
Dan Smith
2013-09-05 16:37:22 -07:00
parent 45b28ecb4f
commit 2f981fe643
11 changed files with 34 additions and 47 deletions

View File

@@ -55,9 +55,7 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
@base.remotable
def create(self, context):
self._assert_no_hosts('create')
updates = {}
for key in self.obj_what_changed():
updates[key] = self[key]
updates = self.obj_get_changes()
payload = dict(updates)
if 'metadata' in updates:
# NOTE(danms): For some reason the notification format is weird
@@ -76,9 +74,7 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
@base.remotable
def save(self, context):
self._assert_no_hosts('save')
updates = {}
for key in self.obj_what_changed():
updates[key] = self[key]
updates = self.obj_get_changes()
payload = {'aggregate_id': self.id}
if 'metadata' in updates: