Remove pci_device.update_device helper function
This function is an exact copy of the PciDevice.update_device object method, and we use it only in the PciDevTracker that has been objectified a long time ago (likely by mistake). This patch removes this useless duplication of code. Change-Id: I3a2e49a79feef71bd606ae50fb02cede25a43d62
This commit is contained in:
parent
4b1951622e
commit
6bae688c97
|
@ -95,29 +95,3 @@ def free(devobj, instance=None):
|
||||||
instance['pci_devices'].remove(existed)
|
instance['pci_devices'].remove(existed)
|
||||||
else:
|
else:
|
||||||
instance.pci_devices.objects.remove(existed)
|
instance.pci_devices.objects.remove(existed)
|
||||||
|
|
||||||
|
|
||||||
def update_device(devobj, dev_dict):
|
|
||||||
"""Sync the content from device dictionary to device object.
|
|
||||||
|
|
||||||
The resource tracker updates the available devices periodically.
|
|
||||||
To avoid meaningless syncs with the database, we update the device
|
|
||||||
object only if a value changed.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Note(yjiang5): status/instance_uuid should only be updated by
|
|
||||||
# functions like claim/allocate etc. The id is allocated by
|
|
||||||
# database. The extra_info is created by the object.
|
|
||||||
no_changes = ('status', 'instance_uuid', 'id', 'extra_info')
|
|
||||||
map(lambda x: dev_dict.pop(x, None),
|
|
||||||
[key for key in no_changes])
|
|
||||||
|
|
||||||
for k, v in dev_dict.items():
|
|
||||||
if k in devobj.fields.keys():
|
|
||||||
devobj[k] = v
|
|
||||||
else:
|
|
||||||
# Note (yjiang5) extra_info.update does not update
|
|
||||||
# obj_what_changed, set it explicitely
|
|
||||||
extra_info = devobj.extra_info
|
|
||||||
extra_info.update({k: v})
|
|
||||||
devobj.extra_info = extra_info
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ class PciDevTracker(object):
|
||||||
# by force in future.
|
# by force in future.
|
||||||
self.stale[new_value['address']] = new_value
|
self.stale[new_value['address']] = new_value
|
||||||
else:
|
else:
|
||||||
device.update_device(existed, new_value)
|
existed.update_device(new_value)
|
||||||
|
|
||||||
for dev in [dev for dev in devices if
|
for dev in [dev for dev in devices if
|
||||||
dev['address'] in new_addrs - exist_addrs]:
|
dev['address'] in new_addrs - exist_addrs]:
|
||||||
|
@ -185,7 +185,7 @@ class PciDevTracker(object):
|
||||||
device.free(dev, instance)
|
device.free(dev, instance)
|
||||||
stale = self.stale.pop(dev['address'], None)
|
stale = self.stale.pop(dev['address'], None)
|
||||||
if stale:
|
if stale:
|
||||||
device.update_device(dev, stale)
|
dev.update_device(stale)
|
||||||
self.stats.add_device(dev)
|
self.stats.add_device(dev)
|
||||||
|
|
||||||
def _free_instance(self, instance):
|
def _free_instance(self, instance):
|
||||||
|
|
Loading…
Reference in New Issue