diff --git a/instances/models.py b/instances/models.py
index 83aa54f..5d4f021 100644
--- a/instances/models.py
+++ b/instances/models.py
@@ -28,6 +28,7 @@ class Instance(models.Model):
uuid = models.CharField(_('uuid'), max_length=36, db_index=True)
is_template = models.BooleanField(_('is template'), default=False)
created = models.DateTimeField(_('created'), auto_now_add=True)
+ drbd = models.CharField(_('drbd'), max_length=24, default="None")
objects = InstanceManager()
diff --git a/instances/templates/allinstances_index_grouped.html b/instances/templates/allinstances_index_grouped.html
index ef5e119..a6c3bc6 100644
--- a/instances/templates/allinstances_index_grouped.html
+++ b/instances/templates/allinstances_index_grouped.html
@@ -7,6 +7,7 @@
{% trans "Name" %} {% trans "Description" %} |
{% trans "User"%} |
{% trans "Status" %} |
+ {% trans "Role/Disk" %} |
{% trans "VCPU" %} |
{% trans "Memory" %} |
{% trans "Actions" %} & {% trans "Mem Usage" %} |
@@ -27,6 +28,7 @@
{% trans "Connected" %}
|
+ |
{{ compute.cpu_count }} |
{{ compute.ram_size|filesizeformat }} |
@@ -62,6 +64,9 @@
{% trans "Suspended" %}
{% endif %}
|
+
+ {% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}{% else %}{% endif %}{{ instance.drbd }}
+ |
{{ 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 e32e29d..114b6b8 100644
--- a/instances/templates/allinstances_index_nongrouped.html
+++ b/instances/templates/allinstances_index_nongrouped.html
@@ -7,6 +7,7 @@
| {% trans 'Host' %} {% trans 'User' %} |
{% endif %}
{% trans 'Status' %} |
+ {% trans 'Role/Disk' %} |
{% trans 'VCPU' %} |
{% trans 'Memory' %} |
{% trans 'Actions' %} |
@@ -44,6 +45,9 @@
{% if instance.proxy.instance.info.0 == 3 %}{% trans "Suspended" %}{% endif %}
+
+ {% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}{% else %}{% endif %}{{ instance.drbd }}
+ |
{{ instance.proxy.instance.info.3 }} |
{{ instance.cur_memory }} MB |
diff --git a/instances/views.py b/instances/views.py
index 6436684..b227046 100644
--- a/instances/views.py
+++ b/instances/views.py
@@ -4,6 +4,7 @@ import os
import re
import socket
import time
+import subprocess
from bisect import insort
from accounts.models import UserInstance, UserSSHKey
@@ -127,6 +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()
+
return render(request, "instance.html", locals())
@@ -134,6 +138,45 @@ def status(request, pk):
instance = get_instance(request.user, pk)
return JsonResponse({"status": instance.proxy.get_status()})
+def drbd_status(request, pk):
+ instance = get_instance(request.user, pk)
+ result = "None DRBD"
+
+ if instance.compute.type == 2:
+ conn = instance.compute.login + "@" + instance.compute.hostname
+ remoteDrbdStatus = subprocess.run(["ssh", conn, "sudo", "drbdadm", "status", "&&", "exit"], stdout=subprocess.PIPE, text=True)
+
+ if remoteDrbdStatus.stdout:
+ try:
+ instanceFindDrbd = re.compile(instance.name + '[_]*[A-Z]* role:(.+?)\n disk:(.+?)\n', re.IGNORECASE)
+ instanceDrbd = instanceFindDrbd.findall(remoteDrbdStatus.stdout)
+
+ primaryCount = 0
+ secondaryCount = 0
+ statusDisk = "OK"
+
+ for disk in instanceDrbd:
+ if disk[0] == "Primary":
+ primaryCount = primaryCount + 1
+ elif disk[0] == "Secondary":
+ secondaryCount = secondaryCount + 1
+ if disk[1] != "UpToDate":
+ statusDisk = "NOK"
+
+ if primaryCount > 0 and secondaryCount > 0:
+ statusRole = "NOK"
+ else:
+ if primaryCount > secondaryCount:
+ statusRole = "Primary"
+ else:
+ statusRole = "Secondary"
+
+ result = statusRole + "/" + statusDisk
+
+ except:
+ print("Error to get drbd role and status")
+
+ return result
def stats(request, pk):
instance = get_instance(request.user, pk)
|