From 19a9f8db12b159ce8454b9d7632ca62640c5b4d3 Mon Sep 17 00:00:00 2001 From: Morgan Fainberg Date: Fri, 13 Apr 2012 23:18:56 +0000 Subject: [PATCH] Fix a bug that can occur if Flavors are deleted In both cases here, we want to ensure that instance.full_flavor doesn't exist so that we get a "Not Available" message. I've also added in a direct query for the flavor if the flavor isn't in the api.nova.flavors.list() because deleted flavors don't show up there. --- .../dashboards/nova/instances_and_volumes/views.py | 11 ++++++++++- horizon/dashboards/syspanel/instances/views.py | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/horizon/dashboards/nova/instances_and_volumes/views.py b/horizon/dashboards/nova/instances_and_volumes/views.py index e10ea20..ed96582 100644 --- a/horizon/dashboards/nova/instances_and_volumes/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/views.py @@ -65,7 +65,16 @@ def get_instances_data(self): full_flavors = SortedDict([(str(flavor.id), flavor) for \ flavor in flavors]) for instance in instances: - instance.full_flavor = full_flavors[instance.flavor["id"]] + flavor_id = instance.flavor["id"] + try: + if full_flavors.has_key(instance.flavor["id"]): + instance.full_flavor = full_flavors[flavor_id] + else: + instance.full_flavor = api.flavor_get(self.request, + flavor_id) + except: + pass + except: msg = _('Unable to retrieve instance size information.') exceptions.handle(self.request, msg) diff --git a/horizon/dashboards/syspanel/instances/views.py b/horizon/dashboards/syspanel/instances/views.py index 354f784..13b16b5 100644 --- a/horizon/dashboards/syspanel/instances/views.py +++ b/horizon/dashboards/syspanel/instances/views.py @@ -65,7 +65,16 @@ def get_data(self): full_flavors = SortedDict([(f.id, f) for f in flavors]) tenant_dict = SortedDict([(t.id, t) for t in tenants]) for inst in instances: - inst.full_flavor = full_flavors.get(inst.flavor["id"], None) + try: + if full_flavors.has_key(inst.flavor["id"]): + inst.full_flavor = full_flavors[inst.flavor["id"]] + else: + flavor_id = inst.flavor["id"] + inst.full_flavor = api.nova.flavor_get(self.request, + flavor_id) + except: + pass + tenant = tenant_dict.get(inst.tenant_id, None) inst.tenant_name = getattr(tenant, "name", None) return instances -- 1.7.5.4