~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/migrate_repo/versions/042_add_volume_types_and_extradata.py

  • Committer: Tarmac
  • Author(s): vladimir.p
  • Date: 2011-08-25 16:14:44 UTC
  • mfrom: (1453.3.16 nova)
  • Revision ID: tarmac-20110825161444-oj48iwhpq7c5d6j7
Added:
- volume metadata
- volume types
- volume types extra_specs

Volume create API receives volume types & metadata.

Work in progress on Openstack APIs for volume types & extra_specs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright (c) 2011 Zadara Storage Inc.
 
4
# Copyright (c) 2011 OpenStack LLC.
 
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 Column, DateTime, Integer, MetaData, String, Table
 
19
from sqlalchemy import Text, Boolean, ForeignKey
 
20
 
 
21
from nova import log as logging
 
22
 
 
23
meta = MetaData()
 
24
 
 
25
# Just for the ForeignKey and column creation to succeed, these are not the
 
26
# actual definitions of tables .
 
27
#
 
28
 
 
29
volumes = Table('volumes', meta,
 
30
       Column('id', Integer(),  primary_key=True, nullable=False),
 
31
       )
 
32
 
 
33
volume_type_id = Column('volume_type_id', Integer(), nullable=True)
 
34
 
 
35
 
 
36
# New Tables
 
37
#
 
38
 
 
39
volume_types = Table('volume_types', meta,
 
40
       Column('created_at', DateTime(timezone=False)),
 
41
       Column('updated_at', DateTime(timezone=False)),
 
42
       Column('deleted_at', DateTime(timezone=False)),
 
43
       Column('deleted', Boolean(create_constraint=True, name=None)),
 
44
       Column('id', Integer(), primary_key=True, nullable=False),
 
45
       Column('name',
 
46
              String(length=255, convert_unicode=False, assert_unicode=None,
 
47
                     unicode_error=None, _warn_on_bytestring=False),
 
48
              unique=True))
 
49
 
 
50
volume_type_extra_specs_table = Table('volume_type_extra_specs', meta,
 
51
        Column('created_at', DateTime(timezone=False)),
 
52
        Column('updated_at', DateTime(timezone=False)),
 
53
        Column('deleted_at', DateTime(timezone=False)),
 
54
        Column('deleted', Boolean(create_constraint=True, name=None)),
 
55
        Column('id', Integer(), primary_key=True, nullable=False),
 
56
        Column('volume_type_id',
 
57
               Integer(),
 
58
               ForeignKey('volume_types.id'),
 
59
               nullable=False),
 
60
        Column('key',
 
61
               String(length=255, convert_unicode=False, assert_unicode=None,
 
62
                      unicode_error=None, _warn_on_bytestring=False)),
 
63
        Column('value',
 
64
               String(length=255, convert_unicode=False, assert_unicode=None,
 
65
                      unicode_error=None, _warn_on_bytestring=False)))
 
66
 
 
67
 
 
68
volume_metadata_table = Table('volume_metadata', meta,
 
69
        Column('created_at', DateTime(timezone=False)),
 
70
        Column('updated_at', DateTime(timezone=False)),
 
71
        Column('deleted_at', DateTime(timezone=False)),
 
72
        Column('deleted', Boolean(create_constraint=True, name=None)),
 
73
        Column('id', Integer(), primary_key=True, nullable=False),
 
74
        Column('volume_id',
 
75
               Integer(),
 
76
               ForeignKey('volumes.id'),
 
77
               nullable=False),
 
78
        Column('key',
 
79
               String(length=255, convert_unicode=False, assert_unicode=None,
 
80
                      unicode_error=None, _warn_on_bytestring=False)),
 
81
        Column('value',
 
82
               String(length=255, convert_unicode=False, assert_unicode=None,
 
83
                      unicode_error=None, _warn_on_bytestring=False)))
 
84
 
 
85
 
 
86
new_tables = (volume_types,
 
87
              volume_type_extra_specs_table,
 
88
              volume_metadata_table)
 
89
 
 
90
#
 
91
# Tables to alter
 
92
#
 
93
 
 
94
 
 
95
def upgrade(migrate_engine):
 
96
    meta.bind = migrate_engine
 
97
 
 
98
    for table in new_tables:
 
99
        try:
 
100
            table.create()
 
101
        except Exception:
 
102
            logging.info(repr(table))
 
103
            logging.exception('Exception while creating table')
 
104
            raise
 
105
 
 
106
    volumes.create_column(volume_type_id)
 
107
 
 
108
 
 
109
def downgrade(migrate_engine):
 
110
    meta.bind = migrate_engine
 
111
 
 
112
    volumes.drop_column(volume_type_id)
 
113
 
 
114
    for table in new_tables:
 
115
        table.drop()