0c074d0b95592145547a21dc020bd680dec31460
[openstack-build/neutron-build.git] / neutron / db / migration / alembic_migrations / core_init_ops.py
1 # Copyright 2014 OpenStack Foundation
2 #
3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
4 #    not use this file except in compliance with the License. You may obtain
5 #    a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #    Unless required by applicable law or agreed to in writing, software
10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 #    License for the specific language governing permissions and limitations
13 #    under the License.
14 #
15
16 # Initial operations for core resources
17 from alembic import op
18 import sqlalchemy as sa
19
20
21 def upgrade():
22     op.create_table(
23         'networks',
24         sa.Column('tenant_id', sa.String(length=255), nullable=True,
25                   index=True),
26         sa.Column('id', sa.String(length=36), nullable=False),
27         sa.Column('name', sa.String(length=255), nullable=True),
28         sa.Column('status', sa.String(length=16), nullable=True),
29         sa.Column('admin_state_up', sa.Boolean(), nullable=True),
30         sa.Column('shared', sa.Boolean(), nullable=True),
31         sa.Column('mtu', sa.Integer(), nullable=True),
32         sa.Column('vlan_transparent', sa.Boolean(), nullable=True),
33         sa.PrimaryKeyConstraint('id'))
34
35     op.create_table(
36         'ports',
37         sa.Column('tenant_id', sa.String(length=255), nullable=True,
38                   index=True),
39         sa.Column('id', sa.String(length=36), nullable=False),
40         sa.Column('name', sa.String(length=255), nullable=True),
41         sa.Column('network_id', sa.String(length=36), nullable=False),
42         sa.Column('mac_address', sa.String(length=32), nullable=False),
43         sa.Column('admin_state_up', sa.Boolean(), nullable=False),
44         sa.Column('status', sa.String(length=16), nullable=False),
45         sa.Column('device_id', sa.String(length=255), nullable=False),
46         sa.Column('device_owner', sa.String(length=255), nullable=False),
47         sa.ForeignKeyConstraint(['network_id'], ['networks.id']),
48         sa.UniqueConstraint('network_id', 'mac_address',
49                             name='uniq_ports0network_id0mac_address'),
50         sa.PrimaryKeyConstraint('id'),
51         sa.Index(op.f('ix_ports_network_id_device_owner'), 'network_id',
52                  'device_owner'),
53         sa.Index(op.f('ix_ports_network_id_mac_address'), 'network_id',
54                  'mac_address'))
55
56     op.create_table(
57         'subnets',
58         sa.Column('tenant_id', sa.String(length=255), nullable=True,
59                   index=True),
60         sa.Column('id', sa.String(length=36), nullable=False),
61         sa.Column('name', sa.String(length=255), nullable=True),
62         sa.Column('network_id', sa.String(length=36), nullable=True),
63         sa.Column('ip_version', sa.Integer(), nullable=False),
64         sa.Column('cidr', sa.String(length=64), nullable=False),
65         sa.Column('gateway_ip', sa.String(length=64), nullable=True),
66         sa.Column('enable_dhcp', sa.Boolean(), nullable=True),
67         sa.Column('shared', sa.Boolean(), nullable=True),
68         sa.Column('ipv6_ra_mode',
69                   sa.Enum('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless',
70                           name='ipv6_ra_modes'),
71                   nullable=True),
72         sa.Column('ipv6_address_mode',
73                   sa.Enum('slaac', 'dhcpv6-stateful', 'dhcpv6-stateless',
74                           name='ipv6_address_modes'),
75                   nullable=True),
76         sa.Column('subnetpool_id', sa.String(length=36), nullable=True,
77                   index=True),
78         sa.ForeignKeyConstraint(['network_id'], ['networks.id'], ),
79         sa.PrimaryKeyConstraint('id'))
80
81     op.create_table(
82         'dnsnameservers',
83         sa.Column('address', sa.String(length=128), nullable=False),
84         sa.Column('subnet_id', sa.String(length=36), nullable=False),
85         sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'],
86                                 ondelete='CASCADE'),
87         sa.PrimaryKeyConstraint('address', 'subnet_id'))
88
89     op.create_table(
90         'ipallocationpools',
91         sa.Column('id', sa.String(length=36), nullable=False),
92         sa.Column('subnet_id', sa.String(length=36), nullable=True),
93         sa.Column('first_ip', sa.String(length=64), nullable=False),
94         sa.Column('last_ip', sa.String(length=64), nullable=False),
95         sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'],
96                                 ondelete='CASCADE'),
97         sa.PrimaryKeyConstraint('id'))
98
99     op.create_table(
100         'subnetroutes',
101         sa.Column('destination', sa.String(length=64), nullable=False),
102         sa.Column('nexthop', sa.String(length=64), nullable=False),
103         sa.Column('subnet_id', sa.String(length=36), nullable=False),
104         sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'],
105                                 ondelete='CASCADE'),
106         sa.PrimaryKeyConstraint('destination', 'nexthop', 'subnet_id'))
107
108     op.create_table(
109         'ipallocations',
110         sa.Column('port_id', sa.String(length=36), nullable=True),
111         sa.Column('ip_address', sa.String(length=64), nullable=False),
112         sa.Column('subnet_id', sa.String(length=36), nullable=False),
113         sa.Column('network_id', sa.String(length=36), nullable=False),
114         sa.ForeignKeyConstraint(['network_id'], ['networks.id'],
115                                 ondelete='CASCADE'),
116         sa.ForeignKeyConstraint(['port_id'], ['ports.id'], ondelete='CASCADE'),
117         sa.ForeignKeyConstraint(['subnet_id'], ['subnets.id'],
118                                 ondelete='CASCADE'),
119         sa.PrimaryKeyConstraint('ip_address', 'subnet_id', 'network_id'))
120
121     op.create_table(
122         'ipavailabilityranges',
123         sa.Column('allocation_pool_id', sa.String(length=36), nullable=False),
124         sa.Column('first_ip', sa.String(length=64), nullable=False),
125         sa.Column('last_ip', sa.String(length=64), nullable=False),
126         sa.ForeignKeyConstraint(['allocation_pool_id'],
127                                 ['ipallocationpools.id'], ondelete='CASCADE'),
128         sa.PrimaryKeyConstraint('allocation_pool_id', 'first_ip', 'last_ip'),
129         sa.UniqueConstraint(
130             'first_ip', 'allocation_pool_id',
131             name='uniq_ipavailabilityranges0first_ip0allocation_pool_id'),
132         sa.UniqueConstraint(
133             'last_ip', 'allocation_pool_id',
134             name='uniq_ipavailabilityranges0last_ip0allocation_pool_id'))
135
136     op.create_table(
137         'networkdhcpagentbindings',
138         sa.Column('network_id', sa.String(length=36), nullable=False),
139         sa.Column('dhcp_agent_id', sa.String(length=36), nullable=False),
140         sa.ForeignKeyConstraint(['dhcp_agent_id'], ['agents.id'],
141             ondelete='CASCADE'),
142         sa.ForeignKeyConstraint(['network_id'], ['networks.id'],
143             ondelete='CASCADE'),
144         sa.PrimaryKeyConstraint('network_id', 'dhcp_agent_id'))