Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | |
Steve McIntyre | 719e377 | 2018-01-31 17:16:53 +0000 | [diff] [blame^] | 3 | # Copyright 2014-2018 Linaro Limited |
Steve McIntyre | 94ef65e | 2015-09-25 01:08:14 +0100 | [diff] [blame] | 4 | # Authors: Dave Pigott <dave.pigot@linaro.org>, |
| 5 | # Steve McIntyre <steve.mcintyre@linaro.org> |
Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 6 | # |
| 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 McIntyre | 719e377 | 2018-01-31 17:16:53 +0000 | [diff] [blame^] | 25 | # Create the switch, port, vlan, trunk and state tables |
Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 26 | |
Steve McIntyre | 719e377 | 2018-01-31 17:16:53 +0000 | [diff] [blame^] | 27 | import datetime |
Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 28 | from psycopg2 import connect |
| 29 | |
| 30 | conn = connect(database="postgres", user="postgres", password="postgres") |
| 31 | |
| 32 | cur = conn.cursor() |
| 33 | cur.execute("CREATE USER vland WITH SUPERUSER") |
| 34 | cur.execute("CREATE DATABASE vland WITH OWNER = vland PASSWORD 'vland'") |
| 35 | conn.close() |
| 36 | |
| 37 | conn = connect(database="vland", user="vland", password="vland") |
| 38 | cur = conn.cursor() |
| 39 | |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 40 | cur.execute("CREATE TABLE switch (switch_id SERIAL, name VARCHAR(64))") |
Steve McIntyre | ea75397 | 2015-08-05 13:52:48 +0100 | [diff] [blame] | 41 | cur.execute("CREATE TABLE port (port_id SERIAL, name VARCHAR(64)," |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 42 | "switch_id INTEGER, is_locked BOOLEAN," |
| 43 | "is_trunk BOOLEAN, base_vlan_id INTEGER," |
Steve McIntyre | c489013 | 2015-08-07 15:19:11 +0100 | [diff] [blame] | 44 | "current_vlan_id INTEGER, number INTEGER, trunk_id INTEGER)") |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 45 | cur.execute("CREATE TABLE vlan (vlan_id SERIAL, name VARCHAR(32)," |
Steve McIntyre | 36e8e80 | 2014-12-16 18:18:50 +0000 | [diff] [blame] | 46 | "tag INTEGER, is_base_vlan BOOLEAN, creation_time TIMESTAMP)") |
Steve McIntyre | c489013 | 2015-08-07 15:19:11 +0100 | [diff] [blame] | 47 | cur.execute("CREATE TABLE trunk (trunk_id SERIAL," |
| 48 | "creation_time TIMESTAMP)") |
Steve McIntyre | 719e377 | 2018-01-31 17:16:53 +0000 | [diff] [blame^] | 49 | cur.execute("CREATE TABLE state (last_modified TIMESTAMP, schema_version INTEGER)") |
| 50 | cur.execute("INSERT INTO state (last_modified, schema_version) VALUES (%s, %s)" % (datetime.datetime.now(), "1")) |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 51 | cur.execute("COMMIT;") |
| 52 | |