Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / plugins / ml2 / models.py
1 # Copyright (c) 2013 OpenStack Foundation
2 # All Rights Reserved.
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 import sqlalchemy as sa
17 from sqlalchemy import orm
18
19 from neutron.db import model_base
20 from neutron.db import models_v2
21 from neutron.extensions import portbindings
22
23 BINDING_PROFILE_LEN = 4095
24
25
26 class NetworkSegment(model_base.BASEV2, model_base.HasId):
27     """Represent persistent state of a network segment.
28
29     A network segment is a portion of a neutron network with a
30     specific physical realization. A neutron network can consist of
31     one or more segments.
32     """
33
34     __tablename__ = 'ml2_network_segments'
35
36     network_id = sa.Column(sa.String(36),
37                            sa.ForeignKey('networks.id', ondelete="CASCADE"),
38                            nullable=False)
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')
45
46
47 class PortBinding(model_base.BASEV2):
48     """Represent binding-related state of a port.
49
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
53     binding.
54     """
55
56     __tablename__ = 'ml2_port_bindings'
57
58     port_id = sa.Column(sa.String(36),
59                         sa.ForeignKey('ports.id', ondelete="CASCADE"),
60                         primary_key=True)
61     host = sa.Column(sa.String(255), nullable=False, default='',
62                      server_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='',
70                             server_default='')
71
72     # Add a relationship to the Port model in order to instruct SQLAlchemy to
73     # eagerly load port bindings
74     port = orm.relationship(
75         models_v2.Port,
76         backref=orm.backref("port_binding",
77                             lazy='joined', uselist=False,
78                             cascade='delete'))
79
80
81 class PortBindingLevel(model_base.BASEV2):
82     """Represent each level of a port binding.
83
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.
87     """
88
89     __tablename__ = 'ml2_port_binding_levels'
90
91     port_id = sa.Column(sa.String(36),
92                         sa.ForeignKey('ports.id', ondelete="CASCADE"),
93                         primary_key=True)
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',
99                                          ondelete="SET NULL"))
100
101
102 class DVRPortBinding(model_base.BASEV2):
103     """Represent binding-related state of a DVR port.
104
105     Port binding for all the ports associated to a DVR identified by router_id.
106     """
107
108     __tablename__ = 'ml2_dvr_port_bindings'
109
110     port_id = sa.Column(sa.String(36),
111                         sa.ForeignKey('ports.id', ondelete="CASCADE"),
112                         primary_key=True)
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='',
117                             server_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)
124
125     # Add a relationship to the Port model in order to instruct SQLAlchemy to
126     # eagerly load port bindings
127     port = orm.relationship(
128         models_v2.Port,
129         backref=orm.backref("dvr_port_binding",
130                             lazy='joined', uselist=False,
131                             cascade='delete'))