Fix error when appliance template is broken (missing fields). Fixes #1287.

This commit is contained in:
grossmj 2018-02-06 16:07:23 +08:00
parent abbe3d3a31
commit fff593b358

View File

@ -82,7 +82,8 @@ class Controller:
if appliance.status != 'broken': if appliance.status != 'broken':
self._appliance_templates[appliance.id] = appliance self._appliance_templates[appliance.id] = appliance
except (ValueError, OSError, KeyError) as e: except (ValueError, OSError, KeyError) as e:
log.warning("Can't load %s: %s", path, str(e)) log.warning("Cannot load appliance template file '%s': %s", path, str(e))
continue
self._appliances = {} self._appliances = {}
vms = [] vms = []
@ -125,10 +126,11 @@ class Controller:
vm.setdefault("appliance_id", str(uuid.uuid4())) vm.setdefault("appliance_id", str(uuid.uuid4()))
try: try:
appliance = Appliance(vm["appliance_id"], vm) appliance = Appliance(vm["appliance_id"], vm)
appliance.__json__() # Check if loaded without error
self._appliances[appliance.id] = appliance self._appliances[appliance.id] = appliance
except KeyError as e: except KeyError as e:
# appliance data is not complete (missing name or type) # appliance data is not complete (missing name or type)
log.warning("Could not load appliance template {} ('{}'): {}".format(vm["appliance_id"], vm.get("name", "unknown"), e)) log.warning("Cannot load appliance template {} ('{}'): missing key {}".format(vm["appliance_id"], vm.get("name", "unknown"), e))
continue continue
# Add builtins # Add builtins