"Fossies" - the Fresh Open Source Software Archive

Member "neutron-14.0.3/neutron/db/migration/alembic_migrations/versions/mitaka/contract/2b4c2465d44b_dvr_sheduling_refactoring.py" (22 Oct 2019, 2786 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 "2b4c2465d44b_dvr_sheduling_refactoring.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 """DVR sheduling refactoring
   20 
   21 Revision ID: 2b4c2465d44b
   22 Revises: 8a6d8bdae39
   23 Create Date: 2015-12-23 07:39:49.062767
   24 
   25 """
   26 
   27 # revision identifiers, used by Alembic.
   28 revision = '2b4c2465d44b'
   29 down_revision = '8a6d8bdae39'
   30 
   31 
   32 ROUTER_ATTR_TABLE = 'router_extra_attributes'
   33 ROUTER_BINDING_TABLE = 'routerl3agentbindings'
   34 CSNAT_BINDING_TABLE = 'csnat_l3_agent_bindings'
   35 
   36 
   37 def upgrade():
   38     transfer_snat_bindings()
   39     op.drop_table(CSNAT_BINDING_TABLE)
   40 
   41 
   42 def transfer_snat_bindings():
   43     router_attr_table = sa.Table(ROUTER_ATTR_TABLE,
   44                                  sa.MetaData(),
   45                                  sa.Column('router_id', sa.String(36)),
   46                                  sa.Column('distributed', sa.Boolean),)
   47 
   48     csnat_binding = sa.Table(CSNAT_BINDING_TABLE,
   49                              sa.MetaData(),
   50                              sa.Column('router_id', sa.String(36)),
   51                              sa.Column('l3_agent_id', sa.String(36)))
   52 
   53     router_binding = sa.Table(ROUTER_BINDING_TABLE,
   54                               sa.MetaData(),
   55                               sa.Column('router_id', sa.String(36)),
   56                               sa.Column('l3_agent_id', sa.String(36)))
   57 
   58     session = sa.orm.Session(bind=op.get_bind())
   59     with session.begin(subtransactions=True):
   60         # first delete all bindings for dvr routers from
   61         # routerl3agentbindings as this might be bindings with l3 agents
   62         # on compute nodes
   63         for router_attr in session.query(
   64                 router_attr_table).filter(router_attr_table.c.distributed):
   65             session.execute(router_binding.delete(
   66                 router_binding.c.router_id == router_attr.router_id))
   67 
   68         # now routerl3agentbindings will only contain bindings for snat
   69         # portion of the router
   70         for csnat_binding in session.query(csnat_binding):
   71             session.execute(
   72                 router_binding.insert().values(
   73                     router_id=csnat_binding.router_id,
   74                     l3_agent_id=csnat_binding.l3_agent_id))
   75     # this commit is necessary to allow further operations
   76     session.commit()