From d431218f6aaae4541bd75e1a04a83e06f43e15bd Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 30 May 2013 09:43:34 -0700 Subject: Make xenapi use Instance object for host_maintenance_mode() This makes xenapi grab an Instance object in host_maintenance_mode() instead of calling into virtapi. This removes the one and only use of instance_get_by_uuid() in nova/virt. The existing tests for host_maintenance_mode() need no changes since they just stub out the database call that eventually gets called in the same way. Related to blueprint unified-object-model Change-Id: Iff4b5de1741653fad8c59e311341aeb3d0bb3539 --- nova/virt/xenapi/host.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 5fa2b55db..31854696f 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -72,7 +72,7 @@ class Host(object): ' ping migration to a new host') LOG.info(msg % locals()) continue - instance = self._virtapi.instance_get_by_uuid(ctxt, uuid) + instance = instance_obj.Instance.get_by_uuid(ctxt, uuid) vm_counter = vm_counter + 1 aggregate = self._virtapi.aggregate_get_by_host( @@ -84,27 +84,24 @@ class Host(object): dest = _host_find(ctxt, self._session, aggregate[0], host_ref) - self._virtapi.instance_update( - ctxt, instance['uuid'], - {'host': dest, - 'task_state': task_states.MIGRATING}) + instance.host = dest + instance.task_state = task_states.MIGRATING + instance.save() self._session.call_xenapi('VM.pool_migrate', vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 - self._virtapi.instance_update( - ctxt, instance['uuid'], - {'vm_state': vm_states.ACTIVE}) + instance.vm_state = vm_states.ACTIVE + instance.save() break except self._session.XenAPI.Failure: LOG.exception(_('Unable to migrate VM %(vm_ref)s' 'from %(host)s') % locals()) - self._virtapi.instance_update( - ctxt, instance['uuid'], - {'host': host, - 'vm_state': vm_states.ACTIVE}) + instance.host = host + instance.vm_state = vm_states.ACTIVE + instance.save() if vm_counter == migrations_counter: return 'on_maintenance' -- cgit