pools are now created dynamically

This commit is contained in:
Daniel 2019-09-20 13:09:21 +02:00
parent 44fc32bd4f
commit c3f8aec018
5 changed files with 19 additions and 22 deletions

View file

@ -78,7 +78,6 @@ def get_drives():
db.session.commit()
# TODO: not able to remove or update pools
def pool_gen():
part_dict = dict()
# creates map uuid is key, partitions are values
@ -98,8 +97,8 @@ def pool_gen():
drives = drives + str(Drive.query.get(part.drive_id)) + ","
drives = drives[:-1]
value = value[0]
existence = db.session.query(db.exists().where(db.and_(Pool.drives == drives, Pool.fs == value.fs))).scalar()
if value.fs == "btrfs" and not existence:
Pool.query.delete()
if value.fs == "btrfs":
if value.mountpoint:
memory_map = btrfsTools.get_space(value.mountpoint)
raid_map = btrfsTools.get_raid(value.mountpoint)
@ -109,11 +108,10 @@ def pool_gen():
['unbekannt', '1.00', 'unbekannt', '1.00'])))
pool_obj = Pool(value.label, memory_map.get("total"), memory_map.get("free"), raid_map.get("data_raid"),
raid_map.get("data_ratio"), raid_map.get("meta_raid"), raid_map.get("meta_ratio"), value.fs,
value.mountpoint, "not implemented", drives)
value.mountpoint, "not implemented", drives, get_pool_health(drives))
db.session.add(pool_obj)
db.session.commit()
if value.fs == "ext4" and not existence:
elif value.fs == "ext4":
if value.mountpoint:
free_space = ext4Tools.get_free_space(value.name)
else:
@ -121,6 +119,13 @@ def pool_gen():
pool_obj = Pool(value.label, value.size, free_space, raid, 1.00, raid, 1.00, value.fs, value.mountpoint,
"not implemented", drives)
db.session.add(pool_obj)
db.session.commit()
# TODO: too much commits
db.session.commit()
def get_pool_health(drive_list):
drive_split = drive_list.split(",")
for drive in drive_split:
db_drive = db.session.query(Drive).filter(Drive.name == drive).scalar()
if db_drive.smart is not True:
return False
return True

View file

@ -18,15 +18,6 @@ def create_cleaning_obj(jobname, path, active):
db.session.commit()
def get_pool_health(drive_list):
drive_split = drive_list.split(",")
for drive in drive_split:
db_drive = db.session.query(Drive).filter(Drive.name == drive).scalar()
if db_drive.smart is not True:
return False
return True
def get_empty_drives():
drives = Drive.query.all()
choices = list()

View file

@ -81,9 +81,10 @@ class Pool(db.Model):
mountpoint = db.Column(db.String)
mountopt = db.Column(db.String)
drives = db.Column(db.String)
healthy = db.Column(db.Boolean)
def __init__(self, label, size, free, data_raid, data_ratio, meta_raid, meta_ratio, fs, mountpoint, mountopt,
drives):
drives, healthy):
self.label = label
self.size = size
self.free = free
@ -95,6 +96,7 @@ class Pool(db.Model):
self.mountpoint = mountpoint
self.mountopt = mountopt
self.drives = drives
self.healthy = healthy
class Time(db.Model):

View file

@ -81,7 +81,7 @@
</tr>
<tr>
<td>Gesundheit</td>
{% if health %}
{% if pool.healthy %}
<td class="positive"><i class="icon checkmark"></i>Gesund</td>
{% else %}
<td class="negative"><i class="attention icon"></i>Kritisch</td>
@ -105,7 +105,7 @@
</p>
</div>
{% endif %}
{% if health %}
{% if pool.healthy %}
<div class="ui positive message">
<i class="close icon"></i>
<div class="header">

View file

@ -41,8 +41,7 @@ def pool(pool):
db_pool = Pool.query.get(pool)
if db_pool is None:
abort(404, description="Pool with ID {} could not be found.".format(pool))
pool_health = viewManager.get_pool_health(db_pool.drives)
return render_template('pool.html', pool=db_pool, health=pool_health)
return render_template('pool.html', pool=db_pool)
@app.route('/pools/add', methods=['GET', 'POST'])