diff options
| author | Brian Elliott <brian.elliott@rackspace.com> | 2012-05-13 21:06:29 +0000 |
|---|---|---|
| committer | Brian Elliott <brian.elliott@rackspace.com> | 2012-05-24 16:53:40 +0000 |
| commit | bc0f2235d9b27e604b9264b5c19adce3cf306bc2 (patch) | |
| tree | f8c9b9aa9b9dbbceca9a4d5f58e52db0f98fd3cc /nova/virt | |
| parent | 9c9c4d78530a3a1e50dd5b7496ef54e51c4b48f5 (diff) | |
Added a instance state update notification
Added a instance update notification (compute.instance.update) that
will report on changes to vm_state and task_state. The goal here is
to provide useful insight into instance state transitions. (e.g.
BUILDING->ACTIVE)
The new notification has minimial dependencies and is intended for
wide use across the different layers/packages within nova. Calls
in compute api/manager, scheduler, and the virt layer that modify
the instance state have been instrumented with this notification.
Change-Id: I223eb7eccc8aa079b782f6bb17727cd0b71d18ed
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/baremetal/proxy.py | 22 | ||||
| -rw-r--r-- | nova/virt/xenapi/host.py | 30 |
2 files changed, 38 insertions, 14 deletions
diff --git a/nova/virt/baremetal/proxy.py b/nova/virt/baremetal/proxy.py index 90011f28b..ba8296127 100644 --- a/nova/virt/baremetal/proxy.py +++ b/nova/virt/baremetal/proxy.py @@ -42,6 +42,7 @@ from nova import db from nova import exception from nova import flags from nova import log as logging +from nova import notifications from nova.openstack.common import cfg from nova import utils from nova.virt.baremetal import dom @@ -253,14 +254,20 @@ class ProxyConnection(driver.ComputeDriver): try: LOG.debug(_("Key is injected but instance is not running yet"), instance=instance) - db.instance_update(context, instance['id'], - {'vm_state': vm_states.BUILDING}) + (old_ref, new_ref) = db.instance_update_and_get_original( + context, instance['id'], + {'vm_state': vm_states.BUILDING}) + notifications.send_update(context, old_ref, new_ref) + state = self._conn.create_domain(xml_dict, bpath) if state == power_state.RUNNING: LOG.debug(_('instance %s: booted'), instance['name'], instance=instance) - db.instance_update(context, instance['id'], + (old_ref, new_ref) = db.instance_update_and_get_original( + context, instance['id'], {'vm_state': vm_states.ACTIVE}) + notifications.send_update(context, old_ref, new_ref) + LOG.debug(_('~~~~~~ current state = %s ~~~~~~'), state, instance=instance) LOG.debug(_("instance %s spawned successfully"), @@ -271,9 +278,12 @@ class ProxyConnection(driver.ComputeDriver): except Exception as Exn: LOG.debug(_("Bremetal assignment is overcommitted."), instance=instance) - db.instance_update(context, instance['id'], - {'vm_state': vm_states.OVERCOMMIT, - 'power_state': power_state.SUSPENDED}) + (old_ref, new_ref) = db.instance_update_and_get_original( + context, instance['id'], + {'vm_state': vm_states.OVERCOMMIT, + 'power_state': power_state.SUSPENDED}) + notifications.send_update(context, old_ref, new_ref) + timer.stop() timer.f = _wait_for_boot diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index cceca0da0..d5f568360 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -26,6 +26,7 @@ from nova.compute import vm_states from nova import context from nova import db from nova import exception +from nova import notifications from nova.virt.xenapi import vm_utils LOG = logging.getLogger(__name__) @@ -74,21 +75,34 @@ class Host(object): vm_counter = vm_counter + 1 dest = _host_find(ctxt, self._session, host, host_ref) - db.instance_update(ctxt, instance.id, - {'host': dest, - 'vm_state': vm_states.MIGRATING}) + (old_ref, new_ref) = \ + db.instance_update_and_get_original(ctxt, + instance.id, + {'host': dest, + 'vm_state': vm_states.MIGRATING}) + notifications.send_update(ctxt, old_ref, new_ref) + self._session.call_xenapi('VM.pool_migrate', vm_ref, host_ref, {}) migrations_counter = migrations_counter + 1 - db.instance_update(ctxt, instance.id, - {'vm_state': vm_states.ACTIVE}) + + (old_ref, new_ref) = \ + db.instance_update_and_get_original(ctxt, + instance.id, + {'vm_state': vm_states.ACTIVE}) + notifications.send_update(ctxt, old_ref, new_ref) + break except self.XenAPI.Failure: LOG.exception('Unable to migrate VM %(vm_ref)s' 'from %(host)s' % locals()) - db.instance_update(ctxt, instance.id, - {'host': host, - 'vm_state': vm_states.ACTIVE}) + (old_ref, new_ref) = \ + db.instance_update_and_get_original(ctxt, + instance.id, + {'hosts': host, + 'vm_state': vm_states.ACTIVE}) + notifications.send_update(ctxt, old_ref, new_ref) + if vm_counter == migrations_counter: return 'on_maintenance' else: |
