From eaa5b5994891eee0280b750dff221a4b54932eb9 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 7 Jan 2011 10:23:48 -0600 Subject: getting ready to push for merge prop --- nova/virt/xenapi/vmops.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 5f1654a49..3df561e7c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -137,13 +137,17 @@ class VMOps(object): return instance_or_vm else: # Must be the instance name - instance_name = instance_or_vm - except AttributeError: - # Not a string; must be a vm instance - instance_name = instance_or_vm.name - vm = VMHelper.lookup(self._session, instance_name) + instance = instance_or_vm + except (AttributeError, KeyError): + # Note the the KeyError will only happen with fakes.py + # Not a string; must be an ID or a vm instance + if isinstance(instance_or_vm, (int, long)): + instance = instance_or_vm + else: + instance = instance_or_vm.name + vm = VMHelper.lookup(self._session, instance) if vm is None: - raise Exception(_('Instance not present %s') % instance_name) + raise Exception(_('Instance not present %s') % instance) return vm def snapshot(self, instance, name): -- cgit