summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2012-12-20 03:13:01 +0000
committerJoe Gordon <jogo@cloudscaling.com>2013-01-08 14:01:30 -0800
commit1ab2fc6477c402e29a95fbc93fe4a67950c083df (patch)
treeed42c15787905fe9e42ca3058bc8db3737d2fcbb /nova/db
parent9f4534ab584faeee1e24d4c1bb38a2b194f24626 (diff)
downloadnova-1ab2fc6477c402e29a95fbc93fe4a67950c083df.tar.gz
nova-1ab2fc6477c402e29a95fbc93fe4a67950c083df.tar.xz
nova-1ab2fc6477c402e29a95fbc93fe4a67950c083df.zip
Remove availability_zones from service table
This is the final step in enabling availability_zones using aggregate metadata. Previously all services had an availability_zone, but the availability_zone is only used for nova-compute. Services such as nova-scheduler, nova-network, nova-conductor have always spanned all availability_zones. After this change only compute nodes (nova-compute), will have an availability_zone. In order to preserve current APIs, when running: * nova host-list (os-hosts) * euca-describe-availability-zones verbose * nova-manage service list Internal services will appear in there own internal availability_zone (CONF.internal_service_availability_zone) Internal zone is hidden in euca-describe-availability_zones (non-verbose) CONF.node_availability_zone has been renamed to CONF.default_availability_zone and is only used by the nova-api and nova-scheduler. CONF.node_availability_zone still works but is deprecated DocImpact Completes blueprint aggregate-based-availability-zones Change-Id: Ib772df5f9ac2865f20df479f8ddce575a9ce3aff
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py6
-rw-r--r--nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py83
-rw-r--r--nova/db/sqlalchemy/models.py1
3 files changed, 87 insertions, 3 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index 8d93701c8..7f202862e 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -1546,8 +1546,10 @@ def aggregate_metadata_get_by_host(context, host, key=None):
def aggregate_host_get_by_metadata_key(context, key):
"""Get hosts with a specific metadata key metadata for all aggregates.
- Returns a dictionary where each key is a hostname and each value is the
- key value"""
+ Returns a dictionary where each key is a hostname and each value is a set
+ of the key values
+ return value: {machine: set( az1, az2 )}
+ """
return IMPL.aggregate_host_get_by_metadata_key(context, key)
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py
new file mode 100644
index 000000000..a20799fbe
--- /dev/null
+++ b/nova/db/sqlalchemy/migrate_repo/versions/147_no_service_zones.py
@@ -0,0 +1,83 @@
+# Copyright 2012 OpenStack LLC.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from sqlalchemy import String, Column, MetaData, Table, select
+
+from nova.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
+
+
+""" Remove availability_zone column from services model and replace with
+ aggregate based zone."""
+
+
+def upgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ services = Table('services', meta, autoload=True)
+ aggregates = Table('aggregates', meta, autoload=True)
+ aggregate_metadata = Table('aggregate_metadata', meta, autoload=True)
+ # migrate data
+ record_list = list(services.select().execute())
+ for rec in record_list:
+ # Only need to migrate nova-compute availability_zones
+ if rec['binary'] != 'nova-compute':
+ continue
+ # if zone doesn't exist create
+ result = aggregate_metadata.select().where(aggregate_metadata.c.key ==
+ 'availability_zone' and
+ aggregate_metadata.c.key == rec['availability_zone']).execute()
+ result = [r for r in result]
+ if len(result) > 0:
+ agg_id = result[0].aggregate_id
+ else:
+ agg = aggregates.insert()
+ result = agg.execute({'name': rec['availability_zone']})
+ agg_id = result.inserted_primary_key[0]
+ row = aggregate_metadata.insert()
+ row.execute({'created_at': rec['created_at'],
+ 'updated_at': rec['updated_at'],
+ 'deleted_at': rec['deleted_at'],
+ 'deleted': rec['deleted'],
+ 'key': 'availability_zone',
+ 'value': rec['availability_zone'],
+ 'aggregate_id': agg_id,
+ })
+ # add host to zone
+ agg_hosts = Table('aggregate_hosts', meta, autoload=True)
+ row = agg_hosts.insert()
+ row.execute({'host': rec['host'], 'aggregate_id': agg_id})
+
+ services.drop_column('availability_zone')
+
+
+def downgrade(migrate_engine):
+ meta = MetaData()
+ meta.bind = migrate_engine
+
+ services = Table('services', meta, autoload=True)
+ aggregate_metadata = Table('aggregate_metadata', meta, autoload=True)
+ agg_hosts = Table('aggregate_hosts', meta, autoload=True)
+ availability_zone = Column('availability_zone', String(255),
+ default='nova')
+ services.create_column(availability_zone)
+ # migrate data
+ services.update().values(availability_zone=select(
+ [aggregate_metadata.c.value]).
+ where(agg_hosts.c.aggregate_id == aggregate_metadata.c.aggregate_id).
+ where(aggregate_metadata.c.key == 'availability_zone').
+ where(agg_hosts.c.host == services.c.host).
+ where(services.c.binary == 'nova-compute')).execute()
diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py
index 8a161efdf..2d3e23c26 100644
--- a/nova/db/sqlalchemy/models.py
+++ b/nova/db/sqlalchemy/models.py
@@ -106,7 +106,6 @@ class Service(BASE, NovaBase):
topic = Column(String(255))
report_count = Column(Integer, nullable=False, default=0)
disabled = Column(Boolean, default=False)
- availability_zone = Column(String(255), default='nova')
class ComputeNode(BASE, NovaBase):