diff options
| author | Dan Smith <danms@us.ibm.com> | 2012-11-13 10:53:06 -0800 |
|---|---|---|
| committer | Dan Smith <danms@us.ibm.com> | 2013-01-29 11:30:55 -0500 |
| commit | fed19822f89ce7f6542d8ea6a4a8b85cfa6065d6 (patch) | |
| tree | 2797f68b66a8888156dcc0da9b6fb8f662e7940f /nova/db | |
| parent | 3c64e6ca4cfe4e61348ef1438787fb61d04d5ec7 (diff) | |
Keep flavor information in system_metadata
This patch copies the instance_type information into an
instance's system_metadata on creation. This provides a way
for us to recall the attributes used to create the instance
even after the type may have been deleted.
This adds db migration 153, which generates flavor information in
system_metadata for existing instances in the database, as well as
brings a test to make sure that works.
Change-Id: Iad9d640b44df5f3831de58f9e800bcf42bc0610e
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/153_instance_type_in_system_metadata.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nova/db/sqlalchemy/migrate_repo/versions/153_instance_type_in_system_metadata.py b/nova/db/sqlalchemy/migrate_repo/versions/153_instance_type_in_system_metadata.py new file mode 100644 index 000000000..20e75a6eb --- /dev/null +++ b/nova/db/sqlalchemy/migrate_repo/versions/153_instance_type_in_system_metadata.py @@ -0,0 +1,49 @@ +# Copyright 2013 IBM Corp. +# +# 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 MetaData, select, Table + + +def upgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + instances = Table('instances', meta, autoload=True) + instance_types = Table('instance_types', meta, autoload=True) + sys_meta = Table('instance_system_metadata', meta, autoload=True) + + # Taken from nova/compute/api.py + instance_type_props = ['id', 'name', 'memory_mb', 'vcpus', + 'root_gb', 'ephemeral_gb', 'flavorid', + 'swap', 'rxtx_factor', 'vcpu_weight'] + + select_columns = [instances.c.uuid] + select_columns += [getattr(instance_types.c, name) + for name in instance_type_props] + + q = select(select_columns, from_obj=instances.join( + instance_types, + instances.c.instance_type_id == instance_types.c.id)) + + i = sys_meta.insert() + for values in q.execute(): + for index in range(0, len(instance_type_props)): + i.execute({"key": "instance_type_%s" % instance_type_props[index], + "value": str(values[index + 1]), + "instance_uuid": values[0]}) + + +def downgrade(migration_engine): + # This migration only touches data, and only metadata at that. No need + # to go through and delete old metadata items. + pass |
