diff --git a/neutron/db/migration/alembic_migrations/versions/EXPAND_HEAD b/neutron/db/migration/alembic_migrations/versions/EXPAND_HEAD index 67d8fc4faeb..5a2c8af42dc 100644 --- a/neutron/db/migration/alembic_migrations/versions/EXPAND_HEAD +++ b/neutron/db/migration/alembic_migrations/versions/EXPAND_HEAD @@ -1 +1 @@ -86274d77933e +f4b9654dd40c diff --git a/neutron/db/migration/alembic_migrations/versions/ussuri/expand/f4b9654dd40c_ovn_backend.py b/neutron/db/migration/alembic_migrations/versions/ussuri/expand/f4b9654dd40c_ovn_backend.py new file mode 100644 index 00000000000..57e5761f03e --- /dev/null +++ b/neutron/db/migration/alembic_migrations/versions/ussuri/expand/f4b9654dd40c_ovn_backend.py @@ -0,0 +1,74 @@ +# Copyright 2019 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.engine import reflection + + +"""ovn backend + +Revision ID: f4b9654dd40c +Revises: 86274d77933e +Create Date: 2019-11-25 13:09:31.367837 + +""" + +# revision identifiers, used by Alembic. +revision = 'f4b9654dd40c' +down_revision = '86274d77933e' + +OVN_REVISION_NUMBERS = 'ovn_revision_numbers' +OVN_HASH_RING = 'ovn_hash_ring' + + +def upgrade(): + inspector = reflection.Inspector.from_engine(op.get_bind()) + table_names = inspector.get_table_names() + if OVN_REVISION_NUMBERS in table_names and OVN_HASH_RING in table_names: + op.alter_column(OVN_REVISION_NUMBERS, 'revision_number', + nullable=False, server_default='0', + existing_type=sa.BIGINT(), existing_nullable=False) + return + + op.create_table( + OVN_REVISION_NUMBERS, + sa.Column('standard_attr_id', sa.BigInteger, nullable=True), + sa.Column('resource_uuid', sa.String(36), nullable=False, index=True), + sa.Column('resource_type', sa.String(36), nullable=False, index=True), + sa.Column('revision_number', sa.BigInteger, nullable=False, + server_default='0'), + sa.Column('created_at', sa.DateTime, nullable=False, + default=sa.func.now()), + sa.Column('updated_at', sa.TIMESTAMP, default=sa.func.now(), + onupdate=sa.func.now(), nullable=True), + sa.ForeignKeyConstraint( + ['standard_attr_id'], ['standardattributes.id'], + ondelete='SET NULL'), + sa.PrimaryKeyConstraint('resource_uuid', 'resource_type') + ) + + op.create_table( + OVN_HASH_RING, + sa.Column('node_uuid', sa.String(36), nullable=False, index=True), + sa.Column('group_name', sa.String(length=256), nullable=False, + index=True), + sa.Column('hostname', sa.String(length=256), nullable=False), + sa.Column('created_at', sa.DateTime, nullable=False, + default=sa.func.now()), + sa.Column('updated_at', sa.DateTime, nullable=False, + default=sa.func.now()), + sa.PrimaryKeyConstraint('node_uuid', 'group_name'), + ) diff --git a/neutron/db/models/ovn.py b/neutron/db/models/ovn.py new file mode 100644 index 00000000000..35c6230dc1b --- /dev/null +++ b/neutron/db/models/ovn.py @@ -0,0 +1,63 @@ +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.db import model_base +import sqlalchemy as sa +from sqlalchemy.dialects import sqlite + + +class OVNRevisionNumbers(model_base.BASEV2): + __tablename__ = 'ovn_revision_numbers' + + standard_attr_id = sa.Column( + sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), + sa.ForeignKey('standardattributes.id', ondelete='SET NULL'), + nullable=True) + resource_uuid = sa.Column(sa.String(36), nullable=False, index=True) + resource_type = sa.Column(sa.String(36), nullable=False, index=True) + revision_number = sa.Column( + sa.BigInteger().with_variant(sa.Integer(), 'sqlite'), + server_default='0', default=0, nullable=False) + created_at = sa.Column( + sa.DateTime().with_variant( + sqlite.DATETIME(truncate_microseconds=True), 'sqlite'), + default=sa.func.now(), nullable=False) + updated_at = sa.Column(sa.TIMESTAMP, default=sa.func.now(), + onupdate=sa.func.now(), nullable=True) + + __table_args__ = ( + sa.PrimaryKeyConstraint( + resource_uuid, resource_type, + name='ovn_revision_numbers0resource_uuid0resource_type'), + model_base.BASEV2.__table_args__ + ) + + +class OVNHashRing(model_base.BASEV2): + __tablename__ = 'ovn_hash_ring' + + node_uuid = sa.Column(sa.String(36), nullable=False, index=True) + group_name = sa.Column(sa.String(256), nullable=False, index=True) + hostname = sa.Column(sa.String(256), nullable=False) + created_at = sa.Column(sa.DateTime(), default=sa.func.now(), + nullable=False) + updated_at = sa.Column(sa.DateTime(), default=sa.func.now(), + nullable=False) + __table_args__ = ( + sa.PrimaryKeyConstraint( + node_uuid, group_name, + name='ovn_hash_ring0node_uuid0group_name'), + model_base.BASEV2.__table_args__ + )