blob: 37ed7dca6ab276a863e6803737510bda61b8294a [file] [log] [blame]
Dave Pigott281203e2014-09-17 23:45:02 +01001#! /usr/bin/python
2
Steve McIntyre94ef65e2015-09-25 01:08:14 +01003# Copyright 2014-2015 Linaro Limited
4# Authors: Dave Pigott <dave.pigot@linaro.org>,
5# Steve McIntyre <steve.mcintyre@linaro.org>
Dave Pigott281203e2014-09-17 23:45:02 +01006#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20# MA 02110-1301, USA.
21
22# First of all, create the vland user
23# Next - create the vland database
24
Steve McIntyrec4890132015-08-07 15:19:11 +010025# Create the switch, port, vlan and trunk tables
Dave Pigott281203e2014-09-17 23:45:02 +010026
27from psycopg2 import connect
28
29conn = connect(database="postgres", user="postgres", password="postgres")
30
31cur = conn.cursor()
32cur.execute("CREATE USER vland WITH SUPERUSER")
33cur.execute("CREATE DATABASE vland WITH OWNER = vland PASSWORD 'vland'")
34conn.close()
35
36conn = connect(database="vland", user="vland", password="vland")
37cur = conn.cursor()
38
Steve McIntyre87e1adb2014-11-27 16:04:45 +000039cur.execute("CREATE TABLE switch (switch_id SERIAL, name VARCHAR(64))")
Steve McIntyreea753972015-08-05 13:52:48 +010040cur.execute("CREATE TABLE port (port_id SERIAL, name VARCHAR(64),"
Steve McIntyre87e1adb2014-11-27 16:04:45 +000041 "switch_id INTEGER, is_locked BOOLEAN,"
42 "is_trunk BOOLEAN, base_vlan_id INTEGER,"
Steve McIntyrec4890132015-08-07 15:19:11 +010043 "current_vlan_id INTEGER, number INTEGER, trunk_id INTEGER)")
Steve McIntyre87e1adb2014-11-27 16:04:45 +000044cur.execute("CREATE TABLE vlan (vlan_id SERIAL, name VARCHAR(32),"
Steve McIntyre36e8e802014-12-16 18:18:50 +000045 "tag INTEGER, is_base_vlan BOOLEAN, creation_time TIMESTAMP)")
Steve McIntyrec4890132015-08-07 15:19:11 +010046cur.execute("CREATE TABLE trunk (trunk_id SERIAL,"
47 "creation_time TIMESTAMP)")
Steve McIntyreea343aa2015-10-23 17:46:17 +010048cur.execute("CREATE TABLE state (last_modified TIMESTAMP)")
Steve McIntyre87e1adb2014-11-27 16:04:45 +000049cur.execute("COMMIT;")
50