swimming in pools

This commit is contained in:
Daniel 2019-05-22 21:39:45 +02:00
parent c0141001b8
commit fb9aa355c7
5 changed files with 74 additions and 43 deletions

View file

@ -1,9 +1,11 @@
from dirkules import db
from dirkules.models import Drive, Partitions
from dirkules.models import Drive, Partitions, Pool
from dirkules.hardware import drive as hardware_drives
from sqlalchemy.sql.expression import exists, and_
# get partitions from hardware (method) and store in db
# contains all logic like replacing, removing in future
def get_partitions(drive_id, force=False):
drive = db.session.query(Drive).get(drive_id)
partdict = hardware_drives.part_for_disk(drive.name)
@ -16,3 +18,33 @@ def get_partitions(drive_id, force=False):
print(part.get("name") + " NICHT in db")
db.session.add(part_obj)
db.session.commit()
def pool_gen():
part_dict = dict()
final_part_dict = list()
for part in Partitions.query.all():
if part.uuid in part_dict:
part_dict[part.uuid].append(part)
else:
part_dict.update({part.uuid: [part]})
for key, value in part_dict.items():
if len(value) == 1:
raid = "Single"
else:
raid = "unknown RAID"
parts = ""
for part in value:
parts = parts + str(part.id) + ","
parts = parts[:-1]
value = value[0]
existence = db.session.query(exists().where(Pool.partitions == parts)).scalar()
# FS is ext4 or BtrFS and there is no element in db with such a part constalation
# TODO: Warning: If a partition has been added to a raid, the disk will still exist
# because not removed and the pool will be displayed twice, because not same part constallation
if (value.fs == "btrfs" or value.fs == "ext4") and not existence:
pool_obj = Pool("not implemented", value.size, 154554, raid, value.fs, value.mountpoint,
"not implemented", parts)
db.session.add(pool_obj)
db.session.commit()

View file

@ -15,29 +15,3 @@ def create_cleaning_obj(jobname, path, active):
job = Cleaning(jobname, path, active)
db.session.add(job)
db.session.commit()
# TODO: Create class out of this
def usable_memory():
part_dict = dict()
final_part_dict = list()
for part in Partitions.query.all():
if part.uuid in part_dict:
part_dict[part.uuid].append(part)
else:
part_dict.update({part.uuid: [part]})
for key, value in part_dict.items():
if len(value) > 1:
parts = list()
for part in value:
parts.append(part.name)
value = value[0]
if value.fs == "btrfs" or value.fs == "ext4":
final_part_dict.append(
{"label": value.label, "part": parts, "fs": value.fs, "mpoint": value.mountpoint})
else:
value = value[0]
if value.fs == "btrfs" or value.fs == "ext4":
final_part_dict.append(
{"label": value.label, "part": value.name, "fs": value.fs, "mpoint": value.mountpoint})
return final_part_dict

View file

@ -53,6 +53,29 @@ class Partitions(db.Model):
self.drive = drive
class Pool(db.Model):
__tablename__ = 'pool'
id = db.Column(db.Integer, primary_key=True)
label = db.Column(db.String)
size = db.Column(db.Integer)
free = db.Column(db.Integer)
raid = db.Column(db.String)
fs = db.Column(db.String)
mountpoint = db.Column(db.String)
mountopt = db.Column(db.String)
partitions = db.Column(db.String)
def __init__(self, label, size, free, raid, fs, mountpoint, mountopt, partitions):
self.label = label
self.size = size
self.free = free
self.raid = raid
self.fs = fs
self.mountpoint = mountpoint
self.mountopt = mountopt
self.partitions = partitions
class Time(db.Model):
__tablename__ = 'time'
id = db.Column(db.Integer, primary_key=True)

View file

@ -24,7 +24,7 @@
<tr>
<td class="collapsing"><i class="hdd icon"></i> {{ drive.name }}</td>
<td>{{ drive.model }}</td>
<td>{{ drive.size|filesizeformat(true) }}</td>
<td class="right aligned">{{ drive.size|filesizeformat(true) }}</td>
{% if drive.smart %}
<td class="collapsing center aligned"><i class="large green checkmark icon"></i></td>
{% else %}
@ -41,17 +41,17 @@
{% endfor %}
</tbody>
</table>
</div>
<div class="ui divider"></div>
<div class="ui container">
<h1 class="ui header">Nutzbarer Speicher</h1>
<h1 class="ui header">Pools</h1>
<div class="ui divider"></div>
<table class="ui very basic celled table">
<thead>
<tr>
<th>Name</th>
<th>Zugehörige Partitionen</th>
<th>Größe</th>
<th>Frei</th>
<th>Typ</th>
<th>Dateisystem</th>
<th>Mountpoint</th>
</tr>
@ -60,14 +60,12 @@
<tbody>
{% for storage in mem %}
<tr>
{% if storage.label|length %}
<td class="collapsing"><i class="download icon"></i> {{ storage.label }}</td>
{% else %}
<td class="collapsing"><i class="download icon"></i>Namenlos</td>
{% endif %}
<td>{{ storage.part }}</td>
<td><i class="download icon"></i> {{ storage.label }}</td>
<td class="right aligned">{{ storage.size|filesizeformat(true) }}</td>
<td class="right aligned">{{ storage.free|filesizeformat(true) }}</td>
<td>{{ storage.raid }}</td>
<td>{{ storage.fs }}</td>
<td class="collapsing">{{ storage.mpoint }}</td>
<td>{{ storage.mountpoint }}</td>
</tr>
{% endfor %}
</tbody>

View file

@ -2,7 +2,7 @@ from flask import Flask, render_template, redirect, request, url_for, flash
from dirkules import app, db
import dirkules.hardware.drive as drico
import dirkules.serviceManagement.serviceManager as servMan
from dirkules.models import Drive, Cleaning, SambaShare
from dirkules.models import Drive, Cleaning, SambaShare, Pool
import dirkules.manager.viewManager as viewManager
from dirkules.validation.validators import CleaningForm, samba_cleaning_form, SambaAddForm
from sqlalchemy import asc, collate
@ -18,11 +18,15 @@ def index():
@app.route('/drives', methods=['GET'])
def drives():
dbDrives = []
db_pools = list()
driveManager.pool_gen()
for drive in Drive.query.all():
d = viewManager.db_object_as_dict(drive)
dbDrives.append(d)
dbmem = viewManager.usable_memory()
return render_template('drives.html', drives=dbDrives, mem=dbmem)
for pool in Pool.query.all():
d = viewManager.db_object_as_dict(pool)
db_pools.append(d)
return render_template('drives.html', drives=dbDrives, mem=db_pools)
@app.route('/about', methods=['GET'])