nat support for neutron
[plstackapi.git] / planetstack / neutron_extension / 1:2013.2.2-0ubuntu1~cloud0 / ovs_models_v2.py
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # Copyright 2011 Nicira Networks, Inc.
3 # All Rights Reserved.
4 #
5 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
6 #    not use this file except in compliance with the License. You may obtain
7 #    a copy of the License at
8 #
9 #         http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #    Unless required by applicable law or agreed to in writing, software
12 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 #    License for the specific language governing permissions and limitations
15 #    under the License.
16 # @author: Aaron Rosen, Nicira Networks, Inc.
17 # @author: Bob Kukura, Red Hat, Inc.
18
19
20 from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, PickleType
21 from sqlalchemy.schema import UniqueConstraint
22
23 from neutron.db.models_v2 import model_base
24
25
26 class VlanAllocation(model_base.BASEV2):
27     """Represents allocation state of vlan_id on physical network."""
28     __tablename__ = 'ovs_vlan_allocations'
29
30     physical_network = Column(String(64), nullable=False, primary_key=True)
31     vlan_id = Column(Integer, nullable=False, primary_key=True,
32                      autoincrement=False)
33     allocated = Column(Boolean, nullable=False)
34
35     def __init__(self, physical_network, vlan_id):
36         self.physical_network = physical_network
37         self.vlan_id = vlan_id
38         self.allocated = False
39
40     def __repr__(self):
41         return "<VlanAllocation(%s,%d,%s)>" % (self.physical_network,
42                                                self.vlan_id, self.allocated)
43
44
45 class TunnelAllocation(model_base.BASEV2):
46     """Represents allocation state of tunnel_id."""
47     __tablename__ = 'ovs_tunnel_allocations'
48
49     tunnel_id = Column(Integer, nullable=False, primary_key=True,
50                        autoincrement=False)
51     allocated = Column(Boolean, nullable=False)
52
53     def __init__(self, tunnel_id):
54         self.tunnel_id = tunnel_id
55         self.allocated = False
56
57     def __repr__(self):
58         return "<TunnelAllocation(%d,%s)>" % (self.tunnel_id, self.allocated)
59
60
61 class NetworkBinding(model_base.BASEV2):
62     """Represents binding of virtual network to physical realization."""
63     __tablename__ = 'ovs_network_bindings'
64
65     network_id = Column(String(36),
66                         ForeignKey('networks.id', ondelete="CASCADE"),
67                         primary_key=True)
68     # 'gre', 'vlan', 'flat', 'local'
69     network_type = Column(String(32), nullable=False)
70     physical_network = Column(String(64))
71     segmentation_id = Column(Integer)  # tunnel_id or vlan_id
72
73     def __init__(self, network_id, network_type, physical_network,
74                  segmentation_id):
75         self.network_id = network_id
76         self.network_type = network_type
77         self.physical_network = physical_network
78         self.segmentation_id = segmentation_id
79
80     def __repr__(self):
81         return "<NetworkBinding(%s,%s,%s,%d)>" % (self.network_id,
82                                                   self.network_type,
83                                                   self.physical_network,
84                                                   self.segmentation_id)
85
86 class PortForwarding(model_base.BASEV2):
87     """Ports to be forwarded through NAT """
88     __tablename__ = 'ovs_port_forwarding'
89
90     port_id = Column(String(36),
91                      ForeignKey('ports.id', ondelete="CASCADE"),
92                      primary_key=True)
93     forward_ports = Column(PickleType)
94
95     def __init__(self, port_id, forward_ports):
96         self.port_id = port_id
97         self.forward_ports = forward_ports
98
99     def __repr__(self):
100         return "<PortForwarding(%s,%s)>" % (self.port_id, self.forward_ports)
101
102 class TunnelEndpoint(model_base.BASEV2):
103     """Represents tunnel endpoint in RPC mode."""
104     __tablename__ = 'ovs_tunnel_endpoints'
105     __table_args__ = (
106         UniqueConstraint('id', name='uniq_ovs_tunnel_endpoints0id'),
107     )
108
109     ip_address = Column(String(64), primary_key=True)
110     id = Column(Integer, nullable=False)
111
112     def __init__(self, ip_address, id):
113         self.ip_address = ip_address
114         self.id = id
115
116     def __repr__(self):
117         return "<TunnelEndpoint(%s,%s)>" % (self.ip_address, self.id)
118