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/db | |
| parent | 9c9c4d78530a3a1e50dd5b7496ef54e51c4b48f5 (diff) | |
| download | nova-bc0f2235d9b27e604b9264b5c19adce3cf306bc2.tar.gz nova-bc0f2235d9b27e604b9264b5c19adce3cf306bc2.tar.xz nova-bc0f2235d9b27e604b9264b5c19adce3cf306bc2.zip | |
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/db')
| -rw-r--r-- | nova/db/api.py | 16 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 32 |
2 files changed, 47 insertions, 1 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index ff72aff37..c43a48c19 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -618,6 +618,22 @@ def instance_update(context, instance_id, values): return IMPL.instance_update(context, instance_id, values) +def instance_update_and_get_original(context, instance_id, values): + """Set the given properties on an instance and update it. Return + a shallow copy of the original instance reference, as well as the + updated one. + + :param context: = request context object + :param instance_id: = instance id or uuid + :param values: = dict containing column values + + :returns: a tuple of the form (old_instance_ref, new_instance_ref) + + Raises NotFound if instance does not exist. + """ + return IMPL.instance_update_and_get_original(context, instance_id, values) + + def instance_add_security_group(context, instance_id, security_group_id): """Associate the given security group with the given instance.""" return IMPL.instance_add_security_group(context, instance_id, diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 88ddeac34..5386b0f41 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -19,6 +19,7 @@ """Implementation of SQLAlchemy backend.""" +import copy import datetime import functools import re @@ -1640,6 +1641,30 @@ def instance_test_and_set(context, instance_id, attr, ok_states, @require_context def instance_update(context, instance_id, values): + + instance_ref = _instance_update(context, instance_id, values)[1] + return instance_ref + + +@require_context +def instance_update_and_get_original(context, instance_id, values): + """Set the given properties on an instance and update it. Return + a shallow copy of the original instance reference, as well as the + updated one. + + :param context: = request context object + :param instance_id: = instance id or uuid + :param values: = dict containing column values + + :returns: a tuple of the form (old_instance_ref, new_instance_ref) + + Raises NotFound if instance does not exist. + """ + return _instance_update(context, instance_id, values, + copy_old_instance=True) + + +def _instance_update(context, instance_id, values, copy_old_instance=False): session = get_session() if utils.is_uuid_like(instance_id): @@ -1648,6 +1673,11 @@ def instance_update(context, instance_id, values): else: instance_ref = instance_get(context, instance_id, session=session) + if copy_old_instance: + old_instance_ref = copy.copy(instance_ref) + else: + old_instance_ref = None + metadata = values.get('metadata') if metadata is not None: instance_metadata_update( @@ -1663,7 +1693,7 @@ def instance_update(context, instance_id, values): instance_ref.update(values) instance_ref.save(session=session) - return instance_ref + return (old_instance_ref, instance_ref) def instance_add_security_group(context, instance_uuid, security_group_id): |
