components/openstack/neutron/files/evs/migrate/neutron-kilo-migration.py
changeset 5405 66fd59fecd68
equal deleted inserted replaced
5404:55e409ba4e72 5405:66fd59fecd68
       
     1 #!/usr/bin/python2.7
       
     2 #
       
     3 # Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
       
     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 #
       
    18 # This script updates the schema for networks, subnets and agents table.
       
    19 # This is needed since we do not run Juno to Kilo alembic migrations.
       
    20 #
       
    21 
       
    22 from alembic.migration import MigrationContext
       
    23 from alembic.operations import Operations
       
    24 import ConfigParser
       
    25 import sqlalchemy as sa
       
    26 
       
    27 
       
    28 def main():
       
    29     print "Start Kilo migrations."
       
    30     print "Add new parameters to networks, subnets and agents table."
       
    31 
       
    32     config = ConfigParser.RawConfigParser()
       
    33     config.readfp(open("/etc/neutron/neutron.conf"))
       
    34     if config.has_option("database", 'connection'):
       
    35         SQL_CONNECTION = config.get("database", 'connection')
       
    36         neutron_engine = sa.create_engine(SQL_CONNECTION)
       
    37         conn = neutron_engine.connect()
       
    38         ctx = MigrationContext.configure(conn)
       
    39         op = Operations(ctx)
       
    40 
       
    41         op.add_column('networks', sa.Column('mtu', sa.Integer(),
       
    42                       nullable=True))
       
    43         op.add_column('networks', sa.Column('vlan_transparent', sa.Boolean(),
       
    44                       nullable=True))
       
    45         op.add_column('agents', sa.Column('load', sa.Integer(),
       
    46                       server_default='0', nullable=False))
       
    47         op.add_column('subnets',
       
    48                       sa.Column('subnetpool_id',
       
    49                                 sa.String(length=36),
       
    50                                 nullable=True,
       
    51                                 index=True))
       
    52     else:
       
    53         print "\nNo database connection found."
       
    54 
       
    55     print "\nEnd Migration."
       
    56 
       
    57 
       
    58 if __name__ == '__main__':
       
    59     main()