1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-01-12 08:25:18 +00:00

Add guest info like:hostname,os,version,kernel. indendation fixes

This commit is contained in:
catborise 2020-12-17 14:29:07 +03:00
parent 993a247228
commit d30e6470e2
13 changed files with 1540 additions and 1460 deletions

View file

@ -54,7 +54,14 @@
{{ ipv4 }} | {{ ipv4 }} |
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
<a class="text-secondary" href="{% url 'instances:instance' instance.id %}" title="{% trans 'Refresh instance info' %}"><span class="fa fa-refresh"></span></a> {% if instance.guest_agent_ready %}
<a class="text-secondary" title="{% trans 'Show Instance OS details' %}" onclick="get_osinfo()">
<span class="fa fa-info-circle"></span>
</a>
{% endif %}
<a class="text-secondary" href="{% url 'instances:instance' instance.id %}" title="{% trans 'Refresh instance info' %}">
<span class="fa fa-refresh"></span>
</a>
</div> </div>
{% if user_quota_msg %} {% if user_quota_msg %}
<div class="alert alert-warning fade show"> <div class="alert alert-warning fade show">
@ -71,13 +78,13 @@
<ul class="nav nav-pills" id="navbtn" aria-label="Instance actions"> <ul class="nav nav-pills" id="navbtn" aria-label="Instance actions">
<li class="nav-item"> <li class="nav-item">
<a href="#power" class="nav-link action-button active" aria-controls="power" role="tab" data-toggle="tab"> <a href="#power" class="nav-link action-button active" aria-controls="power" role="tab" data-toggle="tab">
<i id="action-block" class="fa fa-power-off fa-2x" aria-hidden="true"></i> <span id="action-block" class="fa fa-power-off fa-2x" aria-hidden="true"></span>
{% trans "Power" %} {% trans "Power" %}
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a href="#access" class="nav-link action-button" aria-controls="access" role="tab" data-toggle="tab"> <a href="#access" class="nav-link action-button" aria-controls="access" role="tab" data-toggle="tab">
<i id="action-block" class="fa fa-lock" aria-hidden="true"></i> <span id="action-block" class="fa fa-lock" aria-hidden="true"></span>
{% trans "Access" %} {% trans "Access" %}
</a> </a>
</li> </li>
@ -684,7 +691,7 @@
} }
}); });
} }
if (~$.inArray(hash, ['#boot_opt', "#disks", '#network', '#clone', '#xmledit', '#vncsettings', '#migrate', '#options', '#users'])) { if (~$.inArray(hash, ['#osinfo', '#boot_opt', "#disks", '#network', '#clone', '#xmledit', '#vncsettings', '#migrate', '#options', '#users'])) {
var btnsect = $('#navbtn>li>a'); var btnsect = $('#navbtn>li>a');
$(btnsect).each(function () { $(btnsect).each(function () {
if ($(this).attr('href') === '#settings') { if ($(this).attr('href') === '#settings') {
@ -715,4 +722,22 @@
}); });
} }
</script> </script>
<script>
function get_osinfo() {
$('#navbtn a[href="#settings"]').tab('show');
$('#settings a[href="#osinfo"]').tab('show');
$.getJSON('{% url 'instances:osinfo' instance.id %}', function (data) {
$.each(data, function() {
$('#oshostname').text(data['host-name']);
$('#osname').text(data.id);
$('#osprettyname').text(data['pretty-name']);
$('#oskernelrelease').text(data['kernel-release']);
$('#oskernelversion').text(data['kernel-version']);
$('#osversion').text(data.version);
$('#ostimezone').text(data.zone + " / " + data.offset);
})
});
}
</script>
{% endblock %} {% endblock %}

View file

@ -1,6 +1,5 @@
{% load i18n %} {% load i18n %}
<div role="tabpanel" class="tab-pane" id="access" aria-label="Instance access options"> <div role="tabpanel" class="tab-pane" id="access" aria-label="Instance access options">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist"> <ul class="nav nav-tabs" role="tablist">
<li class="nav-item"> <li class="nav-item">
@ -164,7 +163,6 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div>
{% block script %} {% block script %}
<script> <script>
function open_console(view_style) { function open_console(view_style) {

View file

@ -1,6 +1,5 @@
{% load i18n %} {% load i18n %}
<div role="tabpanel" class="tab-pane" id="undefine"> <div role="tabpanel" class="tab-pane" id="undefine">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance destroy menu"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance destroy menu">
<li class="nav-item"> <li class="nav-item">
@ -26,4 +25,3 @@
</div> </div>
</div> </div>
</div> </div>
</div>

View file

@ -0,0 +1,20 @@
{% load i18n %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="osinfo">
<h3 class="page-header">{% trans "Guest Info" %}</h3>
<dl class="mx-3 row">
<dt class="col-3">{% trans "Hostname" %}</dt>
<dd class="col-9" id="oshostname"></dd>
<dt class="col-3">{% trans "OS Name" %}</dt>
<dd class="col-9" id="osname"></dd>
<dt class="col-3">{% trans "OS Pretty-Name" %}</dt>
<dd class="col-9" id="osprettyname"></dd>
<dt class="col-3">{% trans "Version" %}</dt>
<dd class="col-9" id="osversion"></dd>
<dt class="col-3">{% trans "Kernel Release" %}</dt>
<dd class="col-9" id="oskernelrelease"></dd>
<dt class="col-3">{% trans "Kernel Version" %}</dt>
<dd class="col-9" id="oskernelversion"></dd>
<dt class="col-3">{% trans "Timezone / Offset" %}</dt>
<dd class="col-9" id="ostimezone"></dd>
</dl>
</div>

View file

@ -1,6 +1,5 @@
{% load i18n %} {% load i18n %}
<div role="tabpanel" class="tab-pane active" id="power"> <div role="tabpanel" class="tab-pane active" id="power">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance power actions"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance power actions">
{% if instance.status == 1 %} {% if instance.status == 1 %}
@ -128,4 +127,3 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div>

View file

@ -1,6 +1,5 @@
{% load i18n %} {% load i18n %}
<div role="tabpanel" class="tab-pane" id="resize"> <div role="tabpanel" class="tab-pane" id="resize">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance resize options"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance resize options">
<li class="nav-item"> <li class="nav-item">
@ -161,4 +160,3 @@
</div> </div>
</div> </div>
</div> </div>
</div>

View file

@ -2,10 +2,17 @@
{% load bootstrap4 %} {% load bootstrap4 %}
{% load icons %} {% load icons %}
<div role="tabpanel" class="tab-pane" id="settings"> <div role="tabpanel" class="tab-pane" id="settings">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance settings"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance settings">
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
{% if instance.guest_agent_ready %}
<li class="nav-item">
<a class="px-1 nav-link text-secondary" href="#osinfo" aria-controls="os-info" role="tab" data-toggle="tab" onclick="get_osinfo()">
<span class="fa fa-info-circle"></span>
</a>
</li>
{% endif %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-secondary active" href="#boot_opt" aria-controls="boot" role="tab" data-toggle="tab"> <a class="nav-link text-secondary active" href="#boot_opt" aria-controls="boot" role="tab" data-toggle="tab">
{% trans "Boot" %} {% trans "Boot" %}
@ -68,6 +75,7 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
{% include 'instances/info_tab.html' %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot_opt"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot_opt">
<p class="font-weight-bold">{% trans 'Autostart' %}</p> <p class="font-weight-bold">{% trans 'Autostart' %}</p>
<div class="form-group row"> <div class="form-group row">
@ -259,7 +267,7 @@
<strong>IO Mode:</strong> {{ disk.io }} <br/> <strong>IO Mode:</strong> {{ disk.io }} <br/>
<strong>Discard:</strong> {{ disk.discard }} <br/> <strong>Discard:</strong> {{ disk.discard }} <br/>
<strong>Detect Zeroes:</strong> {{ disk.detect_zeroes }}"> <strong>Detect Zeroes:</strong> {{ disk.detect_zeroes }}">
<i class="fa fa-info"></i> <span class="fa fa-info"></span>
</button> </button>
{{ disk.dev }} {{ disk.dev }}
</td> </td>
@ -513,7 +521,7 @@
<button type="submit" class="btn btn-sm btn-primary" <button type="submit" class="btn btn-sm btn-primary"
name="set_qos" data-toggle="modal" name="set_qos" data-toggle="modal"
title="{% trans "Edit QoS" %}" onclick="return confirm('{% trans "Are you sure?" %}')"> title="{% trans "Edit QoS" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-save"></i> <span class="fa fa-save"></span>
</button> </button>
</form> </form>
<form action="{% url 'instances:unset_qos' instance.id %}" method="post" role="form" aria-label="Instance QoS configuration form"> <form action="{% url 'instances:unset_qos' instance.id %}" method="post" role="form" aria-label="Instance QoS configuration form">
@ -906,4 +914,3 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div>

View file

@ -1,7 +1,6 @@
{% load i18n %} {% load i18n %}
{% load icons %} {% load icons %}
<div role="tabpanel" class="tab-pane" id="snapshots"> <div role="tabpanel" class="tab-pane" id="snapshots">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance snapshot menu"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance snapshot menu">
<li class="nav-item"> <li class="nav-item">
@ -80,4 +79,3 @@
</div> </div>
</div> </div>
</div> </div>
</div>

View file

@ -1,6 +1,5 @@
{% load i18n %} {% load i18n %}
<div role="tabpanel" class="tab-pane" id="graphics"> <div role="tabpanel" class="tab-pane" id="graphics">
<div role="tabpanel">
<!-- Nav tabs --> <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance graphs and logs menu"> <ul class="nav nav-tabs" role="tablist" aria-label="Instance graphs and logs menu">
<li class="nav-item"> <li class="nav-item">
@ -96,7 +95,6 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<script> <script>
function update_logs_table(vname) { function update_logs_table(vname) {
// TODO // TODO

View file

@ -20,6 +20,7 @@ urlpatterns = [
path('<int:pk>/migrate/', views.migrate, name='migrate'), path('<int:pk>/migrate/', views.migrate, name='migrate'),
path('<int:pk>/status/', views.status, name='status'), path('<int:pk>/status/', views.status, name='status'),
path('<int:pk>/stats/', views.stats, name='stats'), path('<int:pk>/stats/', views.stats, name='stats'),
path('<int:pk>/osinfo/', views.osinfo, name='osinfo'),
path('<int:pk>/rootpasswd/', views.set_root_pass, name='rootpasswd'), path('<int:pk>/rootpasswd/', views.set_root_pass, name='rootpasswd'),
path('<int:pk>/add_public_key/', views.add_public_key, name='add_public_key'), path('<int:pk>/add_public_key/', views.add_public_key, name='add_public_key'),
path('<int:pk>/resizevm_cpu/', views.resizevm_cpu, name='resizevm_cpu'), path('<int:pk>/resizevm_cpu/', views.resizevm_cpu, name='resizevm_cpu'),

View file

@ -161,6 +161,11 @@ def stats(request, pk):
} }
) )
def osinfo(request, pk):
instance = get_instance(request.user, pk)
results = instance.proxy.osinfo()
return JsonResponse(results)
def guess_mac_address(request, vname): def guess_mac_address(request, vname):
data = {"vname": vname} data = {"vname": vname}

View file

@ -296,12 +296,12 @@
<button type="submit" class="btn btn-sm btn-primary" <button type="submit" class="btn btn-sm btn-primary"
name="modify_fixed_address" name="modify_fixed_address"
title="{% trans "Edit entry" %}" onclick="return confirm('{% trans "Are you sure?" %}')"> title="{% trans "Edit entry" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-save"></i> <span class="fa fa-save"></span>
</button> </button>
<button type="submit" class="btn btn-sm btn-danger" <button type="submit" class="btn btn-sm btn-danger"
name="delete_fixed_address" name="delete_fixed_address"
title="{% trans "Delete entry" %}" onclick="return confirm('{% trans "Are you sure?" %}')"> title="{% trans "Delete entry" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
<i class="fa fa-trash"></i> <span class="fa fa-trash"></span>
</button> </button>
</td> </td>
</form> </form>

View file

@ -1,3 +1,4 @@
import json
import os.path import os.path
import time import time
@ -20,6 +21,10 @@ try:
VIR_MIGRATE_POSTCOPY, VIR_MIGRATE_POSTCOPY,
) )
from libvirt import VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT from libvirt import VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT
from libvirt_qemu import (
qemuAgentCommand,
VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT
)
except: except:
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE
@ -160,6 +165,35 @@ class wvmInstance(wvmConnect):
self._ip_cache = None self._ip_cache = None
self.instance = self.get_instance(vname) self.instance = self.get_instance(vname)
def osinfo(self):
info_results = qemuAgentCommand(
self.instance,
'{"execute":"guest-get-osinfo"}',
VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, 0
)
timezone_results = qemuAgentCommand(
self.instance,
'{"execute":"guest-get-timezone"}',
VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, 0
)
hostname_results = qemuAgentCommand(
self.instance,
'{"execute":"guest-get-host-name"}',
VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, 0
)
info_results = json.loads(info_results).get('return')
timezone_results = json.loads(timezone_results).get('return')
hostname_results = json.loads(hostname_results).get('return')
info_results.update(timezone_results)
info_results.update(hostname_results)
return info_results
def start(self): def start(self):
self.instance.create() self.instance.create()