diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-04-30 19:04:09 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-04-30 19:04:09 +0000 |
| commit | 85f1f074b24c1f7eb7ab93f7d7bdb9cdffaeed35 (patch) | |
| tree | dc200914b384d7382567c30d65d8f4939a4144cf /nova/db | |
| parent | d04a023ec6d716a03ab98b842abb572437728a59 (diff) | |
| parent | 2cf1f39d9ea7a9436708c5458d42d4dd75717e16 (diff) | |
Merge "Add the availability_zone to the volume.usage notifications"
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/api.py | 3 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 11 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/176_add_availability_zone_to_volume_usage_cache.py | 55 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 1 |
4 files changed, 65 insertions, 5 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index 81350ec20..d294ee1d7 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -1466,12 +1466,13 @@ def vol_get_usage_by_time(context, begin): def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, - instance_id, project_id, user_id, + instance_id, project_id, user_id, availability_zone, last_refreshed=None, update_totals=False): """Update cached volume usage for a volume Creates new record if needed.""" return IMPL.vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, instance_id, project_id, user_id, + availability_zone, last_refreshed=last_refreshed, update_totals=update_totals) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index a269dd263..2b278119a 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -4300,8 +4300,8 @@ def vol_get_usage_by_time(context, begin): @require_context def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, - instance_id, project_id, user_id, last_refreshed=None, - update_totals=False, session=None): + instance_id, project_id, user_id, availability_zone, + last_refreshed=None, update_totals=False, session=None): if not session: session = get_session() @@ -4320,7 +4320,8 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, 'curr_write_bytes': wr_bytes, 'instance_uuid': instance_id, 'project_id': project_id, - 'user_id': user_id} + 'user_id': user_id, + 'availability_zone': availability_zone} else: values = {'tot_last_refreshed': last_refreshed, 'tot_reads': models.VolumeUsage.tot_reads + rd_req, @@ -4335,7 +4336,8 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, 'curr_write_bytes': 0, 'instance_uuid': instance_id, 'project_id': project_id, - 'user_id': user_id} + 'user_id': user_id, + 'availability_zone': availability_zone} rows = model_query(context, models.VolumeUsage, session=session, read_deleted="yes").\ @@ -4352,6 +4354,7 @@ def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, vol_usage.instance_uuid = instance_id vol_usage.project_id = project_id vol_usage.user_id = user_id + vol_usage.availability_zone = availability_zone if not update_totals: vol_usage.curr_reads = rd_req diff --git a/nova/db/sqlalchemy/migrate_repo/versions/176_add_availability_zone_to_volume_usage_cache.py b/nova/db/sqlalchemy/migrate_repo/versions/176_add_availability_zone_to_volume_usage_cache.py new file mode 100644 index 000000000..ff1ab45fc --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/176_add_availability_zone_to_volume_usage_cache.py @@ -0,0 +1,55 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# +# 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. + +# +# This migration adds the availability_zone to the volume_usage_cache table. +# +# This table keeps a cache of the volume usage. Every minute (or what ever +# is configured for volume_usage_poll_interval value) one row in this table +# gets updated for each attached volume. After this patch is applied, for +# any currently attached volumes, the value will immediately be null, but +# will get updated to the correct value on the next tick of the volume +# usage poll. +# +# The volume usage poll function is the only code to access this table. The +# sequence of operation in that function is to first update the field with +# the correct value and then to pass the updated data to the consumer. +# +# Hence this new column does not need to be pre-populated. +# + +from sqlalchemy import MetaData, String, Table, Column + +from nova.openstack.common import log as logging + +LOG = logging.getLogger(__name__) + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + volume_usage_cache = Table('volume_usage_cache', meta, autoload=True) + availability_zone = Column('availability_zone', String(255)) + volume_usage_cache.create_column(availability_zone) + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + volume_usage_cache = Table('volume_usage_cache', meta, autoload=True) + volume_usage_cache.drop_column('availability_zone') diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 85a13c028..c4a22f4c5 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -893,6 +893,7 @@ class VolumeUsage(BASE, NovaBase): instance_uuid = Column(String(36)) project_id = Column(String(36)) user_id = Column(String(36)) + availability_zone = Column(String(255)) tot_last_refreshed = Column(DateTime) tot_reads = Column(BigInteger, default=0) tot_read_bytes = Column(BigInteger, default=0) |
