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