blob: 84fe622e69d696d272ad65cacd8f39a03b0001bf [file] [log] [blame]
Dave Pigott281203e2014-09-17 23:45:02 +01001#! /usr/bin/python
2
Steve McIntyre719e3772018-01-31 17:16:53 +00003# Copyright 2014-2018 Linaro Limited
Steve McIntyre94ef65e2015-09-25 01:08:14 +01004# 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 McIntyre719e3772018-01-31 17:16:53 +000025# Create the switch, port, vlan, trunk and state tables
Dave Pigott281203e2014-09-17 23:45:02 +010026
Steve McIntyre719e3772018-01-31 17:16:53 +000027import datetime
Dave Pigott281203e2014-09-17 23:45:02 +010028from psycopg2 import connect
29
30conn = connect(database="postgres", user="postgres", password="postgres")
31
32cur = conn.cursor()
33cur.execute("CREATE USER vland WITH SUPERUSER")
34cur.execute("CREATE DATABASE vland WITH OWNER = vland PASSWORD 'vland'")
35conn.close()
36
37conn = connect(database="vland", user="vland", password="vland")
38cur = conn.cursor()
39
Steve McIntyre87e1adb2014-11-27 16:04:45 +000040cur.execute("CREATE TABLE switch (switch_id SERIAL, name VARCHAR(64))")
Steve McIntyreea753972015-08-05 13:52:48 +010041cur.execute("CREATE TABLE port (port_id SERIAL, name VARCHAR(64),"
Steve McIntyre87e1adb2014-11-27 16:04:45 +000042 "switch_id INTEGER, is_locked BOOLEAN,"
43 "is_trunk BOOLEAN, base_vlan_id INTEGER,"
Steve McIntyrec4890132015-08-07 15:19:11 +010044 "current_vlan_id INTEGER, number INTEGER, trunk_id INTEGER)")
Steve McIntyre87e1adb2014-11-27 16:04:45 +000045cur.execute("CREATE TABLE vlan (vlan_id SERIAL, name VARCHAR(32),"
Steve McIntyre36e8e802014-12-16 18:18:50 +000046 "tag INTEGER, is_base_vlan BOOLEAN, creation_time TIMESTAMP)")
Steve McIntyrec4890132015-08-07 15:19:11 +010047cur.execute("CREATE TABLE trunk (trunk_id SERIAL,"
48 "creation_time TIMESTAMP)")
Steve McIntyre719e3772018-01-31 17:16:53 +000049cur.execute("CREATE TABLE state (last_modified TIMESTAMP, schema_version INTEGER)")
50cur.execute("INSERT INTO state (last_modified, schema_version) VALUES (%s, %s)" % (datetime.datetime.now(), "1"))
Steve McIntyre87e1adb2014-11-27 16:04:45 +000051cur.execute("COMMIT;")
52