"Fossies" - the Fresh Open Source Software Archive

Member "neutron-14.0.3/neutron/db/migration/alembic_migrations/versions/mitaka/contract/4ffceebfcdc_standard_desc.py" (22 Oct 2019, 2197 Bytes) of package /linux/misc/openstack/neutron-14.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "4ffceebfcdc_standard_desc.py" see the Fossies "Dox" file reference documentation.

    1 # Copyright 2015 OpenStack Foundation
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 #
   15 
   16 from alembic import op
   17 import sqlalchemy as sa
   18 
   19 from neutron.db import migration
   20 
   21 """standard_desc
   22 
   23 Revision ID: 4ffceebfcdc
   24 Revises: 5ffceebfada
   25 Create Date: 2016-02-10 23:12:04.012457
   26 
   27 """
   28 
   29 # revision identifiers, used by Alembic.
   30 revision = '4ffceebfcdc'
   31 down_revision = '5ffceebfada'
   32 depends_on = ('0e66c5227a8a',)
   33 
   34 neutron_milestone = [migration.MITAKA]
   35 
   36 
   37 # A simple model of the security groups table with only the fields needed for
   38 # the migration.
   39 securitygroups = sa.Table('securitygroups', sa.MetaData(),
   40                           sa.Column('standard_attr_id', sa.BigInteger(),
   41                                     nullable=False),
   42                           sa.Column('description', sa.String(length=255)))
   43 
   44 standardattr = sa.Table(
   45     'standardattributes', sa.MetaData(),
   46     sa.Column('id', sa.BigInteger(), primary_key=True, autoincrement=True),
   47     sa.Column('description', sa.String(length=255)))
   48 
   49 
   50 def upgrade():
   51     migrate_values()
   52     op.drop_column('securitygroups', 'description')
   53 
   54 
   55 def migrate_values():
   56     session = sa.orm.Session(bind=op.get_bind())
   57     values = []
   58     for row in session.query(securitygroups):
   59         values.append({'id': row[0],
   60                        'description': row[1]})
   61     with session.begin(subtransactions=True):
   62         for value in values:
   63             session.execute(
   64                 standardattr.update().values(
   65                     description=value['description']).where(
   66                         standardattr.c.id == value['id']))
   67     # this commit appears to be necessary to allow further operations
   68     session.commit()