summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleonoverweel <l.overweel@gmail.com>2017-02-27 15:58:57 +0100
committerleonoverweel <l.overweel@gmail.com>2017-02-27 15:58:57 +0100
commitc4d43ebc5f6db3015c41ae6381e2f30198f5e41d (patch)
treed2c308d5e357c431b3c29303b322a546ea8e8fcf
parent6dd522632d5c47d9af3aae943df1a5d238e698cc (diff)
parentefb1a88fbf7c7993af0aff4b6eeac22232f72bcc (diff)
Merge branch 'master' into workload-core-occupation
-rw-r--r--database/README.md13
-rw-r--r--database/rebuild-database.py31
-rw-r--r--database/schema.sql14
-rw-r--r--database/view-table.py17
m---------opendc-frontend14
m---------opendc-web-server14
6 files changed, 86 insertions, 17 deletions
diff --git a/database/README.md b/database/README.md
new file mode 100644
index 00000000..9fba2d5c
--- /dev/null
+++ b/database/README.md
@@ -0,0 +1,13 @@
+# OpenDC Database
+
+To rebuild the database at a location (or in this directory if none is specified):
+
+```bash
+python rebuild-database.py "path/to/database/directory"
+```
+
+To view a table in the database:
+
+```bash
+python view-table.py "path/to/database/directory" table_name
+```
diff --git a/database/rebuild-database.py b/database/rebuild-database.py
new file mode 100644
index 00000000..6e10b646
--- /dev/null
+++ b/database/rebuild-database.py
@@ -0,0 +1,31 @@
+import os
+import sqlite3
+import sys
+
+sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
+
+try:
+ BASE_DIR = directory_name=sys.argv[1]
+except:
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+db_location = os.path.join(BASE_DIR, 'opendc.db')
+
+print "Removing old database..."
+os.remove(db_location)
+
+print "Connecting to new database..."
+conn = sqlite3.connect(db_location)
+c = conn.cursor()
+
+print "Importing schema..."
+with open('schema.sql') as schema:
+ c.executescript(schema.read())
+
+print "Importing test data..."
+with open('test.sql') as test:
+ c.executescript(test.read())
+
+conn.commit()
+conn.close()
+
+print "Done."
diff --git a/database/schema.sql b/database/schema.sql
index ef67a8b0..bb066328 100644
--- a/database/schema.sql
+++ b/database/schema.sql
@@ -36,7 +36,9 @@ CREATE UNIQUE INDEX authorizations_index ON authorizations (
CREATE TABLE IF NOT EXISTS authorization_levels (
level TEXT PRIMARY KEY NOT NULL
);
-INSERT INTO authorization_levels (level) VALUES ("OWN"), ("EDIT"), ("VIEW");
+INSERT INTO authorization_levels (level) VALUES ("OWN");
+INSERT INTO authorization_levels (level) VALUES ("EDIT");
+INSERT INTO authorization_levels (level) VALUES ("VIEW");
/*
* A Simulation has several Paths, which define the topology of the datacenter at different times. A Simulation also
@@ -209,7 +211,11 @@ CREATE TABLE IF NOT EXISTS rooms (
CREATE TABLE IF NOT EXISTS room_types (
name TEXT PRIMARY KEY NOT NULL
);
-INSERT INTO room_types (name) VALUES ('SERVER'), ('HALLWAY'), ('OFFICE'), ('POWER'), ('COOLING');
+INSERT INTO room_types (name) VALUES ('SERVER');
+INSERT INTO room_types (name) VALUES ('HALLWAY');
+INSERT INTO room_types (name) VALUES ('OFFICE');
+INSERT INTO room_types (name) VALUES ('POWER');
+INSERT INTO room_types (name) VALUES ('COOLING');
/*
* A room consists of tiles that have a quantized (x,y) position. The same tile can't be in multiple rooms. All tiles
@@ -297,7 +303,9 @@ CREATE TABLE IF NOT EXISTS objects (
CREATE TABLE IF NOT EXISTS object_types (
name TEXT PRIMARY KEY NOT NULL
);
-INSERT INTO object_types (name) VALUES ('PSU'), ('COOLING_ITEM'), ('RACK');
+INSERT INTO object_types (name) VALUES ('PSU');
+INSERT INTO object_types (name) VALUES ('COOLING_ITEM');
+INSERT INTO object_types (name) VALUES ('RACK');
-- Allowed objects table
CREATE TABLE IF NOT EXISTS allowed_objects (
diff --git a/database/view-table.py b/database/view-table.py
new file mode 100644
index 00000000..615b4081
--- /dev/null
+++ b/database/view-table.py
@@ -0,0 +1,17 @@
+import os
+import sqlite3
+import sys
+
+try:
+ BASE_DIR = directory_name=sys.argv[1]
+except:
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+db_location = os.path.join(BASE_DIR, 'opendc.db')
+
+conn = sqlite3.connect(db_location)
+c = conn.cursor()
+
+rows = c.execute('SELECT * FROM ' + sys.argv[2])
+
+for row in rows:
+ print row
diff --git a/opendc-frontend b/opendc-frontend
-Subproject 50fcb0634c9ebe894988103184d50d372bc7690
+Subproject df65449694e17a367e59b112c0cc12d66c387ca
diff --git a/opendc-web-server b/opendc-web-server
-Subproject 1b942d9e9d5b2c08d09fb8f294437ea99a88996
+Subproject 855b654942d400204ea3ce952b5fe0cebf8492c