restore.py: factor out _restore_property() helper

This commit is contained in:
Rusty Bird 2018-02-24 12:27:37 +00:00
parent 2ace32bb73
commit c86b731d3e
No known key found for this signature in database
GPG Key ID: 469D78F47AAF2ADF

View File

@ -1820,6 +1820,14 @@ class BackupRestore(object):
self.log.info("-> Please install updates for all the restored " self.log.info("-> Please install updates for all the restored "
"templates.") "templates.")
def _restore_property(self, vm, prop, value):
'''Restore a single VM property, logging exceptions'''
try:
setattr(vm, prop, value)
except Exception as err: # pylint: disable=broad-except
self.log.error('Error setting %s.%s to %s: %s',
vm.name, prop, value, err)
def _restore_vms_metadata(self, restore_info): def _restore_vms_metadata(self, restore_info):
'''Restore VM metadata '''Restore VM metadata
@ -1893,11 +1901,7 @@ class BackupRestore(object):
# restore options # restore options
if prop in ['template', 'netvm', 'default_dispvm']: if prop in ['template', 'netvm', 'default_dispvm']:
continue continue
try: self._restore_property(new_vm, prop, value)
setattr(new_vm, prop, value)
except Exception as err: # pylint: disable=broad-except
self.log.error('Error setting %s.%s to %s: %s',
vm.name, prop, value, err)
for feature, value in vm.features.items(): for feature, value in vm.features.items():
try: try: