| 1 |
# Copyright 2015 OpenStack Foundation |
| 2 |
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
|
| 16 |
from neutron_lib.db import model_base |
| 17 |
from neutron_lib.db import standard_attr |
| 18 |
import sqlalchemy as sa |
| 19 |
from sqlalchemy import orm |
| 20 |
|
| 21 |
|
| 22 |
class L2GatewayConnection(standard_attr.HasStandardAttributes, |
| 23 |
model_base.BASEV2, model_base.HasProject, |
| 24 |
model_base.HasId): |
| 25 |
"""Define an l2 gateway connection between a l2 gateway and a network.""" |
| 26 |
l2_gateway_id = sa.Column(sa.String(36), |
| 27 |
sa.ForeignKey('l2gateways.id', |
| 28 |
ondelete='CASCADE')) |
| 29 |
network_id = sa.Column(sa.String(36), |
| 30 |
sa.ForeignKey('networks.id', ondelete='CASCADE'), |
| 31 |
nullable=False) |
| 32 |
segmentation_id = sa.Column(sa.Integer) |
| 33 |
__table_args__ = (sa.UniqueConstraint(l2_gateway_id, |
| 34 |
network_id),) |
| 35 |
api_collections = ["l2_gateway_connections"] |
| 36 |
|
| 37 |
|
| 38 |
class L2GatewayInterface(model_base.BASEV2, model_base.HasId): |
| 39 |
"""Define an l2 gateway interface.""" |
| 40 |
interface_name = sa.Column(sa.String(255)) |
| 41 |
device_id = sa.Column(sa.String(36), |
| 42 |
sa.ForeignKey('l2gatewaydevices.id', |
| 43 |
ondelete='CASCADE'), |
| 44 |
nullable=False) |
| 45 |
segmentation_id = sa.Column(sa.Integer) |
| 46 |
revises_on_change = ('devices', ) |
| 47 |
|
| 48 |
|
| 49 |
class L2GatewayDevice(standard_attr.HasStandardAttributes, |
| 50 |
model_base.BASEV2, model_base.HasId): |
| 51 |
"""Define an l2 gateway device.""" |
| 52 |
device_name = sa.Column(sa.String(255), nullable=False) |
| 53 |
interfaces = orm.relationship( |
| 54 |
L2GatewayInterface, |
| 55 |
backref=sa.orm.backref("devices", uselist=False, |
| 56 |
lazy='joined', load_on_pending=True), |
| 57 |
cascade='all,delete') |
| 58 |
l2_gateway_id = sa.Column(sa.String(36), |
| 59 |
sa.ForeignKey('l2gateways.id', |
| 60 |
ondelete='CASCADE'), |
| 61 |
nullable=False) |
| 62 |
revises_on_change = ('gateways', ) |
| 63 |
api_collections = ["l2_gateway_devices"] |
| 64 |
|
| 65 |
|
| 66 |
class L2Gateway(standard_attr.HasStandardAttributes, |
| 67 |
model_base.BASEV2, model_base.HasId, model_base.HasProject): |
| 68 |
"""Define an l2 gateway.""" |
| 69 |
name = sa.Column(sa.String(255)) |
| 70 |
devices = orm.relationship( |
| 71 |
L2GatewayDevice, |
| 72 |
backref=sa.orm.backref("gateways", uselist=False, |
| 73 |
lazy='joined', load_on_pending=True), |
| 74 |
cascade='all,delete') |
| 75 |
network_connections = orm.relationship(L2GatewayConnection, |
| 76 |
lazy='joined') |
| 77 |
api_collections = ["l2_gateways"] |