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

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/044_update_instance_states.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 2010 OpenStack LLC.
4
 
#
5
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
6
 
#    not use this file except in compliance with the License. You may obtain
7
 
#    a copy of the License at
8
 
#
9
 
#         http://www.apache.org/licenses/LICENSE-2.0
10
 
#
11
 
#    Unless required by applicable law or agreed to in writing, software
12
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
 
#    License for the specific language governing permissions and limitations
15
 
#    under the License.
16
 
 
17
 
from sqlalchemy import MetaData, Table, Column, String
18
 
 
19
 
from nova.compute import task_states
20
 
from nova.compute import vm_states
21
 
 
22
 
 
23
 
_upgrade_translations = {
24
 
    "stopping": {
25
 
        "state_description": vm_states.ACTIVE,
26
 
        "task_state": task_states.STOPPING,
27
 
    },
28
 
    "stopped": {
29
 
        "state_description": vm_states.STOPPED,
30
 
        "task_state": None,
31
 
    },
32
 
    "terminated": {
33
 
        "state_description": vm_states.DELETED,
34
 
        "task_state": None,
35
 
    },
36
 
    "terminating": {
37
 
        "state_description": vm_states.ACTIVE,
38
 
        "task_state": task_states.DELETING,
39
 
    },
40
 
    "running": {
41
 
        "state_description": vm_states.ACTIVE,
42
 
        "task_state": None,
43
 
    },
44
 
    "scheduling": {
45
 
        "state_description": vm_states.BUILDING,
46
 
        "task_state": task_states.SCHEDULING,
47
 
    },
48
 
    "migrating": {
49
 
        "state_description": vm_states.MIGRATING,
50
 
        "task_state": None,
51
 
    },
52
 
    "pending": {
53
 
        "state_description": vm_states.BUILDING,
54
 
        "task_state": task_states.SCHEDULING,
55
 
    },
56
 
}
57
 
 
58
 
 
59
 
_downgrade_translations = {
60
 
    vm_states.ACTIVE: {
61
 
        None: "running",
62
 
        task_states.DELETING: "terminating",
63
 
        task_states.STOPPING: "stopping",
64
 
    },
65
 
    vm_states.BUILDING: {
66
 
        None: "pending",
67
 
        task_states.SCHEDULING: "scheduling",
68
 
    },
69
 
    vm_states.STOPPED: {
70
 
        None: "stopped",
71
 
    },
72
 
    vm_states.REBUILDING: {
73
 
        None: "pending",
74
 
    },
75
 
    vm_states.DELETED: {
76
 
        None: "terminated",
77
 
    },
78
 
    vm_states.MIGRATING: {
79
 
        None: "migrating",
80
 
    },
81
 
}
82
 
 
83
 
 
84
 
def upgrade(migrate_engine):
85
 
    meta = MetaData()
86
 
    meta.bind = migrate_engine
87
 
 
88
 
    instance_table = Table('instances', meta, autoload=True)
89
 
 
90
 
    c_state = instance_table.c.state
91
 
    c_state.alter(name='power_state')
92
 
 
93
 
    c_vm_state = instance_table.c.state_description
94
 
    c_vm_state.alter(name='vm_state')
95
 
 
96
 
    c_task_state = Column('task_state',
97
 
                          String(length=255, convert_unicode=False,
98
 
                                 assert_unicode=None, unicode_error=None,
99
 
                                 _warn_on_bytestring=False),
100
 
                          nullable=True)
101
 
    instance_table.create_column(c_task_state)
102
 
 
103
 
    for old_state, values in _upgrade_translations.iteritems():
104
 
        instance_table.update().\
105
 
            values(**values).\
106
 
            where(c_vm_state == old_state).\
107
 
            execute()
108
 
 
109
 
 
110
 
def downgrade(migrate_engine):
111
 
    meta = MetaData()
112
 
    meta.bind = migrate_engine
113
 
 
114
 
    instance_table = Table('instances', meta, autoload=True)
115
 
 
116
 
    c_task_state = instance_table.c.task_state
117
 
 
118
 
    c_state = instance_table.c.power_state
119
 
    c_state.alter(name='state')
120
 
 
121
 
    c_vm_state = instance_table.c.vm_state
122
 
    c_vm_state.alter(name='state_description')
123
 
 
124
 
    for old_vm_state, old_task_states in _downgrade_translations.iteritems():
125
 
        for old_task_state, new_state_desc in old_task_states.iteritems():
126
 
            instance_table.update().\
127
 
                where(c_task_state == old_task_state).\
128
 
                where(c_vm_state == old_vm_state).\
129
 
                values(vm_state=new_state_desc).\
130
 
                execute()
131
 
 
132
 
    instance_table.drop_column('task_state')