From 47ba28ecb73db8f1a07760e6803269c548323a31 Mon Sep 17 00:00:00 2001 From: Armando Migliaccio Date: Wed, 18 Jan 2012 19:47:36 +0000 Subject: [PATCH] blueprint host-aggregates: OSAPI/virt integration, via nova.compute.api This commit introduces the first cut of integration between the OSAPI Admin extensions for host aggregates and the virt layer. This is part of a series of commits that have started with change: https://review.openstack.org/#change,3035 Change-Id: I75d8b616e3b8f8cef75d40d937e0dce9f29b16db --- nova/compute/aggregate_states.py | 26 +++++++++++++++++++++----- nova/db/sqlalchemy/api.py | 13 ++++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/nova/compute/aggregate_states.py b/nova/compute/aggregate_states.py index bad7720e3..92e194027 100644 --- a/nova/compute/aggregate_states.py +++ b/nova/compute/aggregate_states.py @@ -17,12 +17,28 @@ """Possible states for host aggregates. -An aggregate may be 'building', in which case the admin has triggered its -creation, but the underlying hypervisor pool has not actually being created -yet. An aggregate may be 'active', in which case the underlying hypervisor -pool is up and running. An aggregate may be in 'error' in all other cases. +An aggregate may be 'created', in which case the admin has triggered its +creation, but the underlying hypervisor pool has not actually being set up +yet. An aggregate may be 'changing', meaning that the underlying hypervisor +pool is being setup. An aggregate may be 'active', in which case the underlying +hypervisor pool is up and running. An aggregate may be 'dismissed' when it has +no hosts and it has been deleted. An aggregate may be in 'error' in all other +cases. +A 'created' aggregate becomes 'changing' during the first request of +adding a host. During a 'changing' status no other requests will be accepted; +this is to allow the hypervisor layer to instantiate the underlying pool +without any potential race condition that may incur in master/slave-based +configurations. The aggregate goes into the 'active' state when the underlying +pool has been correctly instantiated. +All other operations (e.g. add/remove hosts) that succeed will keep the +aggregate in the 'active' state. If a number of continuous requests fail, +an 'active' aggregate goes into an 'error' state. To recover from such a state, +admin intervention is required. Currently an error state is irreversible, +that is, in order to recover from it an aggregate must be deleted. """ -BUILDING = 'building' +CREATED = 'created' +CHANGING = 'changing' ACTIVE = 'active' ERROR = 'error' +DISMISSED = 'dismissed' diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 43b386945..72ecd1f2d 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -4257,7 +4257,7 @@ def aggregate_create(context, values, metadata=None): try: aggregate = models.Aggregate() aggregate.update(values) - aggregate.operational_state = aggregate_states.BUILDING + aggregate.operational_state = aggregate_states.CREATED aggregate.save() except exception.DBError: raise exception.AggregateNameExists(aggregate_name=values['name']) @@ -4435,20 +4435,27 @@ def aggregate_host_delete(context, aggregate_id, host): @require_admin_context @require_aggregate_exists def aggregate_host_add(context, aggregate_id, host): + session = get_session() host_ref = _aggregate_get_query(context, models.AggregateHost, models.AggregateHost.aggregate_id, aggregate_id, - read_deleted='no').\ + session=session, + read_deleted='yes').\ filter_by(host=host).first() if not host_ref: try: host_ref = models.AggregateHost() values = {"host": host, "aggregate_id": aggregate_id, } host_ref.update(values) - host_ref.save() + host_ref.save(session=session) except exception.DBError: raise exception.AggregateHostConflict(host=host) + elif host_ref.deleted: + host_ref.update({'deleted': False, + 'deleted_at': None, + 'updated_at': literal_column('updated_at')}) + host_ref.save(session=session) else: raise exception.AggregateHostExists(host=host, aggregate_id=aggregate_id)