From 421f17d5caab376d3f115d1eb3ced923fb383e89 Mon Sep 17 00:00:00 2001 From: Info-IIG Date: Wed, 29 Jun 2022 15:08:07 +0200 Subject: [PATCH] Added VM DRBD Status to appsettings --- .../migrations/0007_auto_20220629_1213.py | 29 +++++++++++++++++++ .../templates/allinstances_index_grouped.html | 6 ++++ .../allinstances_index_nongrouped.html | 4 +++ instances/views.py | 5 ++-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 appsettings/migrations/0007_auto_20220629_1213.py diff --git a/appsettings/migrations/0007_auto_20220629_1213.py b/appsettings/migrations/0007_auto_20220629_1213.py new file mode 100644 index 0000000..e9f2ed5 --- /dev/null +++ b/appsettings/migrations/0007_auto_20220629_1213.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.12 on 2022-06-29 12:13 + +from django.db import migrations +from django.utils.translation import gettext_lazy as _ + + +def add_default_settings(apps, schema_editor): + setting = apps.get_model("appsettings", "AppSettings") + db_alias = schema_editor.connection.alias + setting.objects.using(db_alias).bulk_create([ + setting(31, _("VM DRBD Status"), "VM_DRBD_STATUS", "False", "True,False", _("Show VM DRBD Status")), + ]) + + +def del_default_settings(apps, schema_editor): + setting = apps.get_model("appsettings", "AppSettings") + db_alias = schema_editor.connection.alias + setting.objects.using(db_alias).filter(key="VM_DRBD_STATUS").delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('appsettings', '0006_alter_appsettings_id'), + ] + + operations = [ + migrations.RunPython(add_default_settings, del_default_settings), + ] diff --git a/instances/templates/allinstances_index_grouped.html b/instances/templates/allinstances_index_grouped.html index a6c3bc6..bdeda51 100644 --- a/instances/templates/allinstances_index_grouped.html +++ b/instances/templates/allinstances_index_grouped.html @@ -7,7 +7,9 @@ {% trans "Name" %}
{% trans "Description" %} {% trans "User"%} {% trans "Status" %} + {% if app_settings.VM_DRBD_STATUS == 'True' %} {% trans "Role/Disk" %} + {% endif %} {% trans "VCPU" %} {% trans "Memory" %} {% trans "Actions" %} & {% trans "Mem Usage" %} @@ -28,7 +30,9 @@ {% trans "Connected" %} + {% if app_settings.VM_DRBD_STATUS == 'True' %} + {% endif %} {{ compute.cpu_count }} {{ compute.ram_size|filesizeformat }} @@ -64,9 +68,11 @@ {% trans "Suspended" %} {% endif %} + {% if app_settings.VM_DRBD_STATUS == 'True' %} {% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}{% else %}{% endif %}{{ instance.drbd }} + {% endif %} {{ instance.proxy.instance.info.3 }} {{ instance.cur_memory }} MB diff --git a/instances/templates/allinstances_index_nongrouped.html b/instances/templates/allinstances_index_nongrouped.html index 114b6b8..a836fa7 100644 --- a/instances/templates/allinstances_index_nongrouped.html +++ b/instances/templates/allinstances_index_nongrouped.html @@ -7,7 +7,9 @@ {% trans 'Host' %}
{% trans 'User' %} {% endif %} {% trans 'Status' %} + {% if app_settings.VM_DRBD_STATUS == 'True' %} {% trans 'Role/Disk' %} + {% endif %} {% trans 'VCPU' %} {% trans 'Memory' %} {% trans 'Actions' %} @@ -45,9 +47,11 @@ {% if instance.proxy.instance.info.0 == 3 %}{% trans "Suspended" %}{% endif %} + {% if app_settings.VM_DRBD_STATUS == 'True' %} {% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}{% else %}{% endif %}{{ instance.drbd }} + {% endif %} {{ instance.proxy.instance.info.3 }} {{ instance.cur_memory }} MB diff --git a/instances/views.py b/instances/views.py index ff8702c..449fc7b 100644 --- a/instances/views.py +++ b/instances/views.py @@ -128,8 +128,9 @@ def instance(request, pk): storages_host = sorted(instance.proxy.get_storages(True)) net_models_host = instance.proxy.get_network_models() - instance.drbd = drbd_status(request, pk) - instance.save() + if app_settings.VM_DRBD_STATUS == 'True': + instance.drbd = drbd_status(request, pk) + instance.save() return render(request, "instance.html", locals())