1 # Copyright (c) 2013 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 import sqlalchemy as sa
17 from sqlalchemy import orm
19 from neutron.db import model_base
20 from neutron.db import models_v2
21 from neutron.extensions import portbindings
23 BINDING_PROFILE_LEN = 4095
26 class NetworkSegment(model_base.BASEV2, model_base.HasId):
27 """Represent persistent state of a network segment.
29 A network segment is a portion of a neutron network with a
30 specific physical realization. A neutron network can consist of
34 __tablename__ = 'ml2_network_segments'
36 network_id = sa.Column(sa.String(36),
37 sa.ForeignKey('networks.id', ondelete="CASCADE"),
39 network_type = sa.Column(sa.String(32), nullable=False)
40 physical_network = sa.Column(sa.String(64))
41 segmentation_id = sa.Column(sa.Integer)
42 is_dynamic = sa.Column(sa.Boolean, default=False, nullable=False,
43 server_default=sa.sql.false())
44 segment_index = sa.Column(sa.Integer, nullable=False, server_default='0')
47 class PortBinding(model_base.BASEV2):
48 """Represent binding-related state of a port.
50 A port binding stores the port attributes required for the
51 portbindings extension, as well as internal ml2 state such as
52 which MechanismDriver and which segment are used by the port
56 __tablename__ = 'ml2_port_bindings'
58 port_id = sa.Column(sa.String(36),
59 sa.ForeignKey('ports.id', ondelete="CASCADE"),
61 host = sa.Column(sa.String(255), nullable=False, default='',
63 vnic_type = sa.Column(sa.String(64), nullable=False,
64 default=portbindings.VNIC_NORMAL,
65 server_default=portbindings.VNIC_NORMAL)
66 profile = sa.Column(sa.String(BINDING_PROFILE_LEN), nullable=False,
67 default='', server_default='')
68 vif_type = sa.Column(sa.String(64), nullable=False)
69 vif_details = sa.Column(sa.String(4095), nullable=False, default='',
72 # Add a relationship to the Port model in order to instruct SQLAlchemy to
73 # eagerly load port bindings
74 port = orm.relationship(
76 backref=orm.backref("port_binding",
77 lazy='joined', uselist=False,
81 class PortBindingLevel(model_base.BASEV2):
82 """Represent each level of a port binding.
84 Stores information associated with each level of an established
85 port binding. Different levels might correspond to the host and
86 ToR switch, for instance.
89 __tablename__ = 'ml2_port_binding_levels'
91 port_id = sa.Column(sa.String(36),
92 sa.ForeignKey('ports.id', ondelete="CASCADE"),
94 host = sa.Column(sa.String(255), nullable=False, primary_key=True)
95 level = sa.Column(sa.Integer, primary_key=True, autoincrement=False)
96 driver = sa.Column(sa.String(64))
97 segment_id = sa.Column(sa.String(36),
98 sa.ForeignKey('ml2_network_segments.id',
102 class DVRPortBinding(model_base.BASEV2):
103 """Represent binding-related state of a DVR port.
105 Port binding for all the ports associated to a DVR identified by router_id.
108 __tablename__ = 'ml2_dvr_port_bindings'
110 port_id = sa.Column(sa.String(36),
111 sa.ForeignKey('ports.id', ondelete="CASCADE"),
113 host = sa.Column(sa.String(255), nullable=False, primary_key=True)
114 router_id = sa.Column(sa.String(36), nullable=True)
115 vif_type = sa.Column(sa.String(64), nullable=False)
116 vif_details = sa.Column(sa.String(4095), nullable=False, default='',
118 vnic_type = sa.Column(sa.String(64), nullable=False,
119 default=portbindings.VNIC_NORMAL,
120 server_default=portbindings.VNIC_NORMAL)
121 profile = sa.Column(sa.String(BINDING_PROFILE_LEN), nullable=False,
122 default='', server_default='')
123 status = sa.Column(sa.String(16), nullable=False)
125 # Add a relationship to the Port model in order to instruct SQLAlchemy to
126 # eagerly load port bindings
127 port = orm.relationship(
129 backref=orm.backref("dvr_port_binding",
130 lazy='joined', uselist=False,