Skip to content
Snippets Groups Projects
Commit 34a93a0d authored by Alex ubuntu vm's avatar Alex ubuntu vm
Browse files

database: updated schema

Updated l2sm database schema and operator to go along with it. Now there are more constraints in the database and errors are handled accordingly, so the application is more robust against errors
parent 16f90fd5
No related branches found
No related tags found
1 merge request!2repo: added new directory where utils scripts will be
{
"version": "0.2.0",
"configurations": [
{
"name": "Kopf Run: l2sm-operator",
"type": "node-terminal",
"request": "launch",
"command": "kopf run ${workspaceFolder}/src/operator/l2sm-operator.py",
"env": {
"CONTROLLER_IP": "10.152.183.3",
"DATABASE_IP": "10.152.183.132",
"MYSQL_USER": "l2sm",
"MYSQL_PASSWORD": "l2sm",
"MYSQL_DATABASE": "l2sm"
}
}
]
}
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-schema
data:
init.sql: |
CREATE DATABASE IF NOT EXISTS l2sm;
USE l2sm;
CREATE TABLE networks (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
type ENUM('vlink', 'vnet', 'ext-vnet') NOT NULL,
UNIQUE KEY unique_network_name (name, type)
);
CREATE TABLE switches (
id INT PRIMARY KEY AUTO_INCREMENT,
node_name VARCHAR(255) NOT NULL,
openflowId TEXT,
ip VARCHAR(15)
);
CREATE TABLE neds (
id INT PRIMARY KEY AUTO_INCREMENT,
node_name VARCHAR(255) NOT NULL,
provider VARCHAR(255) NOT NULL,
openflowId TEXT,
ip VARCHAR(15)
);
CREATE TABLE interfaces (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
pod VARCHAR(255),
switch_id INT,
ned_id INT,
network_id INT,
FOREIGN KEY (switch_id) REFERENCES switches(id),
FOREIGN KEY (ned_id) REFERENCES neds(id),
FOREIGN KEY (network_id) REFERENCES networks(id)
);
-- Define the one-to-many relationship between switches and interfaces
ALTER TABLE interfaces
ADD CONSTRAINT fk_switch_interface
FOREIGN KEY (switch_id)
REFERENCES switches(id);
-- Define the one-to-many relationship between neds and interfaces
ALTER TABLE interfaces
ADD CONSTRAINT fk_ned_interface
FOREIGN KEY (ned_id)
REFERENCES neds(id);
-- Define the many-to-one relationship between networks and interfaces
ALTER TABLE interfaces
ADD CONSTRAINT fk_network_interface
FOREIGN KEY (network_id)
REFERENCES networks(id);
apiVersion: v1
kind: Pod
metadata:
name: mysql-development-pod
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
envFrom:
- secretRef:
name: mysql-secret
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
- name: initdb-volume
mountPath: /docker-entrypoint-initdb.d
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
- name: initdb-volume
configMap:
name: mysql-schema
items:
- key: init.sql
path: init.sql
nodeName: l2sm1
---
apiVersion: v1
kind: Service
metadata:
name: mysql-development-service
spec:
type: NodePort
ports:
- port: 3306
targetPort: 3306
nodePort: 30001
protocol: TCP
selector:
app: mysql
---
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
type: Opaque
data:
MYSQL_ROOT_PASSWORD: cGFzc3dvcmQ= # Base64 encoded "password"
MYSQL_USER: bDJzbQ== # Base64 encoded "l2sm"
MYSQL_PASSWORD: bDJzbQ== # Base64 encoded "l2sm"
MYSQL_DATABASE: bDJzbQ==
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment