1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # Copyright 2011 Nicira Networks, Inc.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
16 # @author: Aaron Rosen, Nicira Networks, Inc.
17 # @author: Bob Kukura, Red Hat, Inc.
20 from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, PickleType
21 from sqlalchemy.schema import UniqueConstraint
23 from neutron.db.models_v2 import model_base
26 class VlanAllocation(model_base.BASEV2):
27 """Represents allocation state of vlan_id on physical network."""
28 __tablename__ = 'ovs_vlan_allocations'
30 physical_network = Column(String(64), nullable=False, primary_key=True)
31 vlan_id = Column(Integer, nullable=False, primary_key=True,
33 allocated = Column(Boolean, nullable=False)
35 def __init__(self, physical_network, vlan_id):
36 self.physical_network = physical_network
37 self.vlan_id = vlan_id
38 self.allocated = False
41 return "<VlanAllocation(%s,%d,%s)>" % (self.physical_network,
42 self.vlan_id, self.allocated)
45 class TunnelAllocation(model_base.BASEV2):
46 """Represents allocation state of tunnel_id."""
47 __tablename__ = 'ovs_tunnel_allocations'
49 tunnel_id = Column(Integer, nullable=False, primary_key=True,
51 allocated = Column(Boolean, nullable=False)
53 def __init__(self, tunnel_id):
54 self.tunnel_id = tunnel_id
55 self.allocated = False
58 return "<TunnelAllocation(%d,%s)>" % (self.tunnel_id, self.allocated)
61 class NetworkBinding(model_base.BASEV2):
62 """Represents binding of virtual network to physical realization."""
63 __tablename__ = 'ovs_network_bindings'
65 network_id = Column(String(36),
66 ForeignKey('networks.id', ondelete="CASCADE"),
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
73 def __init__(self, network_id, network_type, physical_network,
75 self.network_id = network_id
76 self.network_type = network_type
77 self.physical_network = physical_network
78 self.segmentation_id = segmentation_id
81 return "<NetworkBinding(%s,%s,%s,%d)>" % (self.network_id,
83 self.physical_network,
86 class PortForwarding(model_base.BASEV2):
87 """Ports to be forwarded through NAT """
88 __tablename__ = 'ovs_port_forwarding'
90 port_id = Column(String(36),
91 ForeignKey('ports.id', ondelete="CASCADE"),
93 forward_ports = Column(PickleType)
95 def __init__(self, port_id, forward_ports):
96 self.port_id = port_id
97 self.forward_ports = forward_ports
100 return "<PortForwarding(%s,%s)>" % (self.port_id, self.forward_ports)
102 class TunnelEndpoint(model_base.BASEV2):
103 """Represents tunnel endpoint in RPC mode."""
104 __tablename__ = 'ovs_tunnel_endpoints'
106 UniqueConstraint('id', name='uniq_ovs_tunnel_endpoints0id'),
109 ip_address = Column(String(64), primary_key=True)
110 id = Column(Integer, nullable=False)
112 def __init__(self, ip_address, id):
113 self.ip_address = ip_address
117 return "<TunnelEndpoint(%s,%s)>" % (self.ip_address, self.id)