¡@

Home 

OpenStack Study: 3c6e57a23db4_add_multiprovider.py

OpenStack Index

**** CubicPower OpenStack Study ****

def upgrade(active_plugins=None, options=None):

    if not migration.should_run(active_plugins, migration_for_plugins):

        return

    op.create_table(

        'nvp_multi_provider_networks',

        sa.Column('network_id', sa.String(length=36), nullable=False),

        sa.ForeignKeyConstraint(['network_id'], ['networks.id'],

                                ondelete='CASCADE'),

        sa.PrimaryKeyConstraint('network_id'),

        mysql_engine='InnoDB'

    )

    op.create_table('rename_nvp_network_bindings',

                    sa.Column('network_id', sa.String(length=36),

                              primary_key=True),

                    sa.Column('binding_type',

                              sa.Enum(

                                  'flat', 'vlan', 'stt', 'gre', 'l3_ext',

                                  name=(

                                      'nvp_network_bindings_binding_type')),

                              nullable=False, primary_key=True),

                    sa.Column('phy_uuid', sa.String(36), primary_key=True,

                              nullable=True),

                    sa.Column('vlan_id', sa.Integer, primary_key=True,

                              nullable=True, autoincrement=False))

    # copy data from nvp_network_bindings into rename_nvp_network_bindings

    op.execute("INSERT INTO rename_nvp_network_bindings SELECT network_id, "

               "binding_type, phy_uuid, vlan_id from nvp_network_bindings")

    op.drop_table('nvp_network_bindings')

    op.rename_table('rename_nvp_network_bindings', 'nvp_network_bindings')

**** CubicPower OpenStack Study ****

def downgrade(active_plugins=None, options=None):

    if not migration.should_run(active_plugins, migration_for_plugins):

        return

    # Delete the multi_provider_network entries from nvp_network_bindings

    op.execute("DELETE from nvp_network_bindings WHERE network_id IN "

               "(SELECT network_id from nvp_multi_provider_networks)")

    # create table with previous contains

    op.create_table(

        'rename_nvp_network_bindings',

        sa.Column('network_id', sa.String(length=36), primary_key=True),

        sa.Column('binding_type',

                  sa.Enum('flat', 'vlan', 'stt', 'gre', 'l3_ext',

                          name=('nvp_network_bindings_binding_type')),

                  nullable=False),

        sa.Column('phy_uuid', sa.String(36), nullable=True),

        sa.Column('vlan_id', sa.Integer, nullable=True, autoincrement=False))

    # copy data from nvp_network_bindings into rename_nvp_network_bindings

    op.execute("INSERT INTO rename_nvp_network_bindings SELECT network_id, "

               "binding_type, phy_uuid, vlan_id from nvp_network_bindings")

    op.drop_table('nvp_network_bindings')

    op.rename_table('rename_nvp_network_bindings', 'nvp_network_bindings')

    op.drop_table('nvp_multi_provider_networks')