1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

Added DRBD status

This commit is contained in:
Info-IIG 2022-06-15 13:51:56 +02:00
parent 32eb91f53f
commit 02b02d3321
4 changed files with 53 additions and 0 deletions

View file

@ -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()

View file

@ -7,6 +7,7 @@
<th scope="col">{% trans "Name" %}<br>{% trans "Description" %}</th>
<th scope="col" class="d-none d-sm-table-cell">{% trans "User"%}</th>
<th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "Role/Disk" %}</th>
<th scope="col" class="d-none d-sm-table-cell">{% trans "VCPU" %}</th>
<th scope="col" class="d-none d-sm-table-cell">{% trans "Memory" %}</th>
<th scope="col" style="width:200px;" data-sortable="false">{% trans "Actions" %} & {% trans "Mem Usage" %}</th>
@ -27,6 +28,7 @@
<td>
<span class="text-success">{% trans "Connected" %}</span>
</td>
<td class="d-none d-sm-table-cell"></td>
<td class="d-none d-sm-table-cell text-center">{{ compute.cpu_count }}</td>
<td class="d-none d-sm-table-cell text-right">{{ compute.ram_size|filesizeformat }}</td>
<td>
@ -62,6 +64,9 @@
<span class="text-warning">{% trans "Suspended" %}</span>
{% endif %}
</td>
<td>
{% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}<span class="text-success">{% else %}<span class="text-danger">{% endif %}{{ instance.drbd }}</span>
</td>
<td>{{ instance.proxy.instance.info.3 }}</td>
<td>{{ instance.cur_memory }} MB</td>
<td class="text-nowrap">

View file

@ -7,6 +7,7 @@
<th scope="col">{% trans 'Host' %}<br>{% trans 'User' %}</th>
{% endif %}
<th scope="col">{% trans 'Status' %}</th>
<th scope="col">{% trans 'Role/Disk' %}</th>
<th scope="col">{% trans 'VCPU' %}</th>
<th scope="col">{% trans 'Memory' %}</th>
<th scope="col" data-sortable="false">{% trans 'Actions' %}</th>
@ -44,6 +45,9 @@
{% if instance.proxy.instance.info.0 == 3 %}<span
class="text-warning">{% trans "Suspended" %}</span>{% endif %}
</td>
<td>
{% if instance.drbd == "Primary/OK" or instance.drbd == "Secondary/OK" %}<span class="text-success">{% else %}<span class="text-danger">{% endif %}{{ instance.drbd }}</span>
</td>
<td>{{ instance.proxy.instance.info.3 }}</td>
<td>{{ instance.cur_memory }} MB</td>
<td class="text-nowrap">

View file

@ -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)