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
This commit is contained in:
parent
168ff33d10
commit
d431218f6a
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue