~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/074_change_flavor_local_gb.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2011 OpenStack LLC.
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
 
18
 
from sqlalchemy import select, Column, Integer, MetaData, Table
19
 
 
20
 
from nova import exception
21
 
from nova import flags
22
 
 
23
 
FLAGS = flags.FLAGS
24
 
 
25
 
 
26
 
def upgrade_libvirt(instances, instance_types):
27
 
    # Update instance_types first
28
 
    tiny = None
29
 
    for inst_type in instance_types.select().execute():
30
 
        if inst_type['name'] == 'm1.tiny':
31
 
            tiny = inst_type['id']
32
 
            root_gb = 0
33
 
        else:
34
 
            root_gb = 10
35
 
 
36
 
        instance_types.update()\
37
 
                      .values(root_gb=root_gb,
38
 
                              ephemeral_gb=inst_type['local_gb'])\
39
 
                      .where(instance_types.c.id == inst_type['id'])\
40
 
                      .execute()
41
 
 
42
 
    # then update instances following same pattern
43
 
    instances.update()\
44
 
             .values(root_gb=10,
45
 
                     ephemeral_gb=instances.c.local_gb)\
46
 
             .execute()
47
 
 
48
 
    if tiny is not None:
49
 
        instances.update()\
50
 
                 .values(root_gb=0,
51
 
                         ephemeral_gb=instances.c.local_gb)\
52
 
                 .where(instances.c.instance_type_id == tiny)\
53
 
                 .execute()
54
 
 
55
 
 
56
 
def upgrade_other(instances, instance_types):
57
 
    for table in (instances, instance_types):
58
 
        table.update().values(root_gb=table.c.local_gb,
59
 
                              ephemeral_gb=0).execute()
60
 
 
61
 
 
62
 
def check_instance_presence(migrate_engine, instances_table):
63
 
    result = migrate_engine.execute(instances_table.select().limit(1))
64
 
    return result.fetchone() is not None
65
 
 
66
 
 
67
 
def upgrade(migrate_engine):
68
 
    meta = MetaData()
69
 
    meta.bind = migrate_engine
70
 
    instances = Table('instances', meta, autoload=True)
71
 
 
72
 
    data_present = check_instance_presence(migrate_engine, instances)
73
 
 
74
 
    if data_present and not FLAGS.connection_type:
75
 
        msg = ("Found instance records in database. You must specify "
76
 
               "connection_type to run migration migration")
77
 
        raise exception.Error(msg)
78
 
 
79
 
    instance_types = Table('instance_types', meta, autoload=True)
80
 
 
81
 
    for table in (instances, instance_types):
82
 
        root_gb = Column('root_gb', Integer)
83
 
        root_gb.create(table)
84
 
        ephemeral_gb = Column('ephemeral_gb', Integer)
85
 
        ephemeral_gb.create(table)
86
 
 
87
 
    # Since this migration is part of the work to get all drivers
88
 
    # working the same way, we need to treat the new root_gb and
89
 
    # ephemeral_gb columns differently depending on what the
90
 
    # driver implementation used to behave like.
91
 
    if FLAGS.connection_type == 'libvirt':
92
 
        upgrade_libvirt(instances, instance_types)
93
 
    else:
94
 
        upgrade_other(instances, instance_types)
95
 
 
96
 
    default_local_device = instances.c.default_local_device
97
 
    default_local_device.alter(name='default_ephemeral_device')
98
 
 
99
 
    for table in (instances, instance_types):
100
 
        table.drop_column('local_gb')
101
 
 
102
 
 
103
 
def downgrade(migrate_engine):
104
 
    meta = MetaData()
105
 
    meta.bind = migrate_engine
106
 
    instances = Table('instances', meta, autoload=True)
107
 
    instance_types = Table('instance_types', meta, autoload=True)
108
 
 
109
 
    for table in (instances, instance_types):
110
 
        local_gb = Column('local_gb', Integer)
111
 
        local_gb.create(table)
112
 
 
113
 
    try:
114
 
        for table in (instances, instance_types):
115
 
            if FLAGS.connection_type == 'libvirt':
116
 
                column = table.c.ephemeral_gb
117
 
            else:
118
 
                column = table.c.root_gb
119
 
            table.update().values(local_gb=column).execute()
120
 
    except Exception:
121
 
        for table in (instances, instance_types):
122
 
            table.drop_column('local_gb')
123
 
        raise
124
 
 
125
 
    default_ephemeral_device = instances.c.default_ephemeral_device
126
 
    default_ephemeral_device.alter(name='default_local_device')
127
 
 
128
 
    for table in (instances, instance_types):
129
 
        table.drop_column('root_gb')
130
 
        table.drop_column('ephemeral_gb')