Merge "Create tables for floating IP reservations"
This commit is contained in:
commit
039ef68734
|
@ -0,0 +1,82 @@
|
|||
# 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.
|
||||
|
||||
"""add_floatingip_reservation
|
||||
|
||||
Revision ID: f4084140f608
|
||||
Revises: e069c014356d
|
||||
Create Date: 2019-02-25 06:25:22.038890
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f4084140f608'
|
||||
down_revision = 'e069c014356d'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('floatingip_allocations',
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('id', sa.String(length=36), nullable=False),
|
||||
sa.Column('floatingip_id',
|
||||
sa.String(length=36), nullable=True),
|
||||
sa.Column('reservation_id',
|
||||
sa.String(length=36), nullable=True),
|
||||
|
||||
sa.ForeignKeyConstraint(['floatingip_id'],
|
||||
['floatingips.id'], ),
|
||||
sa.ForeignKeyConstraint(['reservation_id'],
|
||||
['reservations.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'))
|
||||
|
||||
op.create_table('floatingip_reservations',
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('id', sa.String(length=36), nullable=False),
|
||||
sa.Column('reservation_id',
|
||||
sa.String(length=36), nullable=True),
|
||||
sa.Column('network_id',
|
||||
sa.String(length=255), nullable=False),
|
||||
sa.Column('amount', sa.Integer(), nullable=False),
|
||||
|
||||
sa.ForeignKeyConstraint(['reservation_id'],
|
||||
['reservations.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'))
|
||||
|
||||
op.create_table('required_floatingips',
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('id', sa.String(length=36), nullable=False),
|
||||
sa.Column('address',
|
||||
sa.String(length=255), nullable=False),
|
||||
sa.Column('floatingip_reservation_id',
|
||||
sa.String(length=36), nullable=True),
|
||||
sa.ForeignKeyConstraint(['floatingip_reservation_id'],
|
||||
['floatingip_reservations.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('required_floatingips')
|
||||
op.drop_table('floatingip_reservations')
|
||||
op.drop_table('floatingip_allocations')
|
||||
# ### end Alembic commands ###
|
|
@ -99,6 +99,16 @@ class Reservation(mb.BlazarBase):
|
|||
cascade="all,delete",
|
||||
backref='reservation',
|
||||
lazy='joined')
|
||||
floatingip_reservation = relationship('FloatingIPReservation',
|
||||
uselist=False,
|
||||
cascade="all,delete",
|
||||
backref='reservation',
|
||||
lazy='joined')
|
||||
floatingip_allocations = relationship('FloatingIPAllocation',
|
||||
uselist=True,
|
||||
cascade="all,delete",
|
||||
backref='reservation',
|
||||
lazy='joined')
|
||||
|
||||
def to_dict(self):
|
||||
d = super(Reservation, self).to_dict()
|
||||
|
@ -124,6 +134,10 @@ class Reservation(mb.BlazarBase):
|
|||
'resource_properties']
|
||||
d.update(self.instance_reservation.to_dict(include=ir_keys))
|
||||
|
||||
if self.floatingip_reservation:
|
||||
fip_keys = ['network_id', 'amount']
|
||||
d.update(self.floatingip_reservation.to_dict(include=fip_keys))
|
||||
|
||||
return d
|
||||
|
||||
|
||||
|
@ -247,6 +261,55 @@ class ComputeHostExtraCapability(mb.BlazarBase):
|
|||
|
||||
|
||||
# Floating IP
|
||||
class FloatingIPReservation(mb.BlazarBase):
|
||||
"""Description
|
||||
|
||||
Specifies resources asked by reservation from
|
||||
Floating IP Reservation API.
|
||||
"""
|
||||
|
||||
__tablename__ = 'floatingip_reservations'
|
||||
|
||||
id = _id_column()
|
||||
reservation_id = sa.Column(sa.String(36), sa.ForeignKey('reservations.id'))
|
||||
network_id = sa.Column(sa.String(255), nullable=False)
|
||||
amount = sa.Column(sa.Integer, nullable=False)
|
||||
required_fips = relationship('RequiredFloatingIP',
|
||||
cascade='all,delete',
|
||||
backref='floatingip_reservation',
|
||||
lazy='joined')
|
||||
|
||||
def to_dict(self, include=None):
|
||||
d = super(FloatingIPReservation, self).to_dict(include=include)
|
||||
d['required_floatingips'] = [ip['address'] for ip in
|
||||
self.required_fips]
|
||||
return d
|
||||
|
||||
|
||||
class RequiredFloatingIP(mb.BlazarBase):
|
||||
"""A table for a requested Floating IP.
|
||||
|
||||
Keeps an user requested floating IP address in a floating IP reservation.
|
||||
"""
|
||||
__tablename__ = 'required_floatingips'
|
||||
|
||||
id = _id_column()
|
||||
address = sa.Column(sa.String(255), nullable=False)
|
||||
floatingip_reservation_id = sa.Column(
|
||||
sa.String(36), sa.ForeignKey('floatingip_reservations.id'))
|
||||
|
||||
|
||||
class FloatingIPAllocation(mb.BlazarBase):
|
||||
"""Mapping between FloatingIP, FloatingIPReservation and Reservation."""
|
||||
|
||||
__tablename__ = 'floatingip_allocations'
|
||||
|
||||
id = _id_column()
|
||||
floatingip_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('floatingips.id'))
|
||||
reservation_id = sa.Column(sa.String(36),
|
||||
sa.ForeignKey('reservations.id'))
|
||||
|
||||
|
||||
class FloatingIP(mb.BlazarBase):
|
||||
"""A table for Floating IP resource."""
|
||||
|
|
Loading…
Reference in New Issue