Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 1 | #! /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 | |
| 26 | from psycopg2 import connect |
| 27 | |
| 28 | conn = connect(database="postgres", user="postgres", password="postgres") |
| 29 | |
| 30 | cur = conn.cursor() |
| 31 | cur.execute("CREATE USER vland WITH SUPERUSER") |
| 32 | cur.execute("CREATE DATABASE vland WITH OWNER = vland PASSWORD 'vland'") |
| 33 | conn.close() |
| 34 | |
| 35 | conn = connect(database="vland", user="vland", password="vland") |
| 36 | cur = conn.cursor() |
| 37 | |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 38 | cur.execute("CREATE TABLE switch (switch_id SERIAL, name VARCHAR(64))") |
Steve McIntyre | ea75397 | 2015-08-05 13:52:48 +0100 | [diff] [blame^] | 39 | cur.execute("CREATE TABLE port (port_id SERIAL, name VARCHAR(64)," |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 40 | "switch_id INTEGER, is_locked BOOLEAN," |
| 41 | "is_trunk BOOLEAN, base_vlan_id INTEGER," |
Steve McIntyre | ea75397 | 2015-08-05 13:52:48 +0100 | [diff] [blame^] | 42 | "current_vlan_id INTEGER, number INTEGER)") |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 43 | cur.execute("CREATE TABLE vlan (vlan_id SERIAL, name VARCHAR(32)," |
Steve McIntyre | 36e8e80 | 2014-12-16 18:18:50 +0000 | [diff] [blame] | 44 | "tag INTEGER, is_base_vlan BOOLEAN, creation_time TIMESTAMP)") |
Dave Pigott | 281203e | 2014-09-17 23:45:02 +0100 | [diff] [blame] | 45 | |
Steve McIntyre | 87e1adb | 2014-11-27 16:04:45 +0000 | [diff] [blame] | 46 | cur.execute("COMMIT;") |
| 47 | |