1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

Add all settings to appsettings page & Convert settings choices

This commit is contained in:
catborise 2020-05-29 00:43:26 +03:00 committed by catborise
parent 62f8ece0ef
commit 7538ddab4f
27 changed files with 454 additions and 447 deletions

View file

@ -121,7 +121,7 @@
<div role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" aria-label="Instance power actions">
{% ifequal status 1 %}
{% if status == 1 %}
<li class="nav-item">
<a class="nav-link text-secondary active" href="#poweroff" aria-controls="poweroff" role="tab" data-toggle="tab">
{% trans "Power Off" %}
@ -144,8 +144,8 @@
</a>
</li>
{% endif %}
{% endifequal %}
{% ifequal status 3 %}
{% endif %}
{% if status == 3 %}
{% if request.user.is_superuser %}
<li class="nav-item">
<a class="nav-link text-secondary" href="#resume" aria-controls="resume" role="tab" data-toggle="tab">
@ -158,18 +158,18 @@
</a>
</li>
{% endif %}
{% endifequal %}
{% ifequal status 5 %}
{% endif %}
{% if status == 5 %}
<li class="nav-item">
<a class="nav-link text-secondary active" href="#boot" aria-controls="boot" role="tab" data-toggle="tab">
{% trans "Power On" %}
</a>
</li>
{% endifequal %}
{% endif %}
</ul>
<!-- Tab panes -->
<div class="tab-content">
{% ifequal status 1 %}
{% if status == 1 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="poweroff">
<p>{% trans "This action sends an ACPI shutdown signal to the instance." %}</p>
<form action="" method="post" role="form" aria-label0="Power off instance form">{% csrf_token %}
@ -200,8 +200,8 @@
</form>
</div>
{% endif %}
{% endifequal %}
{% ifequal status 3 %}
{% endif %}
{% if status == 3 %}
{% if request.user.is_superuser %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resume">
<p>{% trans "This action restore the instance after suspend." %}</p>
@ -226,8 +226,8 @@
</form>
</div>
{% endif %}
{% endifequal %}
{% ifequal status 5 %}
{% endif %}
{% if status == 5 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot">
<p>{% trans "Click on Boot button to start this instance." %}</p>
<form action="" method="post" role="form" aria-label="Start instance form">{% csrf_token %}
@ -240,7 +240,7 @@
<div class="clearfix"></div>
</form>
</div>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -253,33 +253,33 @@
{% trans "Console" %}
</a>
</li>
{% if show_access_root_password %}
{% if show_access_root_password == 'True' %}
<li class="nav-item">
<a class="nav-link text-secondary" href="#rootpasswd" aria-controls="rootpasswd" role="tab" data-toggle="tab">
{% trans "Root Password" %}
</a>
</li>
{% endif %}
{% if show_access_ssh_keys %}
{% if show_access_ssh_keys == 'True' %}
<li class="nav-item">
<a class="nav-link text-secondary" href="#sshkeys" aria-controls="sshkeys" role="tab" data-toggle="tab">
{% trans "SSH Keys" %}
</a>
</li>
{% endif %}
{% ifequal status 1 %}
{% if status == 1 %}
<li class="nav-item">
<a class="nav-link text-secondary" href="#vdiconsole" aria-controls="vdiconsole" role="tab" data-toggle="tab">
{% trans "VDI" %}
</a>
</li>
{% endifequal %}
{% endif %}
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="vnconsole">
<p>{% trans "This action opens a new window with a VNC connection to the console of the instance." %}</p>
{% ifequal status 1 %}
{% if status == 1 %}
<!-- Split button -->
<div class="btn-group float-right">
<button type="button" id="consoleBtnGroup" class="btn btn-lg btn-success" onclick="open_console('lite')">{% trans 'Console' %}</button>
@ -293,10 +293,10 @@
</div>
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Console" %}</button>
{% endifequal %}
{% endif %}
<div class="clearfix"></div>
</div>
{% if show_access_root_password %}
{% if show_access_root_password == 'True' %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="rootpasswd">
<p>{% trans "You need shut down your instance and enter a new root password." %}</p>
<form class="form-inline" method="post" role="form" aria-label="Add root password to instance form">{% csrf_token %}
@ -305,22 +305,22 @@
<input type="text" class="form-control-lg" name="passwd" placeholder="{% trans "Enter Password" %}" maxlength="24">
</div>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<input type="submit" class="btn btn-lg btn-success float-right" name="rootpasswd" value="{% trans "Reset Root Password" %}">
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Reset Root Password" %}</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
</div>
{% endif %}
{% if show_access_ssh_keys %}
{% if show_access_ssh_keys == 'True' %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="sshkeys">
<p>{% trans "You need shut down your instance and choose your public key." %}</p>
<form class="form-inline" method="post" role="form" aria-label="Add public key to instance form">{% csrf_token %}
<div class="form-group row">
<div class="col-sm-12">
<select name="sshkeyid" class="form-control keyselect">
<select name="sshkeyid" class="form-control-lg keyselect">
{% if publickeys %}
{% for key in publickeys %}
<option value="{{ key.id }}">{{ key.keyname }}</option>
@ -331,16 +331,16 @@
</select>
</div>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<input type="submit" class="btn btn-lg btn-success float-right" name="addpublickey" value="{% trans "Add Public Key" %}">
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Add Public Key" %}</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
</div>
{% endif %}
{% ifequal status 1 %}
{% if status == 1 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="vdiconsole">
<p>{% trans "This action opens a remote viewer with a connection to the console of the instance." %}</p>
<div class="input-group">
@ -351,7 +351,7 @@
</div>
<div class="clearfix"></div>
</div>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -408,11 +408,11 @@
</div>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-lg btn-success float-right" name="resizevm_cpu">{% trans "Resize" %}</button>
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
{% else %}
@ -493,11 +493,11 @@
</div>
</div>
{% endfor %}
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-lg btn-success float-right" name="resizevm_disk">{% trans "Resize" %}</button>
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
{% endif %}
</form>
{% else %}
{% trans "You don't have permission for resizing instance" %}
@ -526,7 +526,7 @@
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="takesnapshot">
{% ifequal status 5 %}
{% if status == 5 %}
<p>{% trans "This may take more than an hour, depending on how much content is on your droplet and how large the disk is." %}</p>
<form class="form-inline" method="post" role="form" aria-label="Create snapshot form">{% csrf_token %}
<div class="form-group row">
@ -534,16 +534,16 @@
<input type="text" class="form-control form-control-lg" name="name" placeholder="{% trans "Enter Snapshot Name" %}" maxlength="14">
</div>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<input type="submit" class="btn btn-lg btn-success float-right" name="snapshot" value="{% trans "Take Snapshot" %}">
{% else %}
<button class="btn btn-lg btn-success float-right disabled">{% trans "Take Snapshot" %}</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
{% else %}
<p>{% trans "To take a snapshot please Power Off the instance." %}</p>
{% endifequal %}
{% endif %}
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="managesnapshot">
{% if snapshots %}
@ -563,7 +563,7 @@
<td style="width:30px;">
<form action="" method="post" role="form" aria-label="Restore snapshot form">{% csrf_token %}
<input type="hidden" name="name" value="{{ snap.name }}">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-sm btn-secondary" name="revert_snapshot" title="{% trans 'Revert to this Snapshot' %}" onclick="return confirm('Are you sure?')">
<span class="fa fa-download"></span>
</button>
@ -572,7 +572,7 @@
title="{% trans "To restore snapshots you need Power Off the instance." %}">
<span class="fa fa-download"></span>
</button>
{% endifequal %}
{% endif %}
</form>
</td>
<td style="width:30px;">
@ -668,11 +668,11 @@
<div class="form-group row">
<div class="col-sm-12 text-center">
<p>{% trans "Autostart your instance when host server is power on " %}
{% ifequal autostart 0 %}
{% if autostart == 0 %}
<input type="submit" class="btn btn-success" name="set_autostart" value="{% trans "Enable" %}">
{% else %}
<input type="submit" class="btn btn-danger" name="unset_autostart" value="{% trans "Disable" %}">
{% endifequal %}
{% endif %}
</p>
</div>
</div>
@ -681,23 +681,23 @@
<form action="" method="post" role="form" aria-label="Enable/disable instance boot order form">{% csrf_token %}
<div class="form-group row">
<div class="col-sm-12 text-center">
{% ifequal status 5 %}
{% if status == 5 %}
<p>{% trans "Enable Boot Menu for your instance when it starts up " %}
{% ifequal bootmenu 0 %}
{% if bootmenu == 0 %}
<input type="submit" class="btn btn-success" name="set_bootmenu" title="{% trans 'Show boot menu' %}" value="{% trans "Enable" %}">
{% else %}
<input type="submit" class="btn btn-danger" name="unset_bootmenu" title="{% trans 'Hide boot menu' %}" value="{% trans "Disable" %}">
{% endifequal %}
{% endif %}
{% else %}
{% ifequal bootmenu 0 %}
{% if bootmenu == 0 %}
<p>**** {% trans "Please shutdown instance to modify boot menu" %} ****</p>
{% endifequal %}
{% endifequal %}
{% endif %}
{% endif %}
</div>
</div>
</form>
{% ifequal bootmenu 1 %}
{% if bootmenu == 1 %}
<div class="d-flex justify-content-center">
<div class="col-sm-6 bg-light rounded shadow-sm">
{% for idx, val in boot_order.items %}
@ -734,7 +734,7 @@
</div>
</div>
</form>
{% endifequal %}
{% endif %}
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="disks">
@ -866,7 +866,7 @@
<input type="hidden" name="storage" value="{{ disk.storage }}">
<input type="hidden" name="name" value="{{ disk.image }}">
{% include 'edit_instance_volume.html' with id=forloop.counter0 %}
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-sm btn-secondary" name="detach_vol" value="{{ disk.dev }}" title="{% trans "Detach" %}" onclick="return confirm('{% trans "Are you sure to detach volume?" %}')">
<i class="fa fa-eject"></i>
</button>
@ -880,16 +880,15 @@
<button class="btn btn-sm btn-secondary disabled" name="delete_vol" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure? This may lead data corruption!" %}')">
<i class="fa fa-trash"></i>
</button>
{% endifequal %}
{% endif %}
</form>
</td>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="network">
@ -957,10 +956,10 @@
<input class="form-control" type="text" value="{{ network.nic }}" readonly/>
<select class="form-control" name="net-source-{{ forloop.counter0 }}">
{% for c_net in networks_host %}
<option value="net:{{ c_net }}" {% ifequal c_net network.nic %} selected {% endifequal %}>{% trans 'Network' %} {{ c_net }}</option>
<option value="net:{{ c_net }}" {% if c_net == network.nic %} selected {% endif %}>{% trans 'Network' %} {{ c_net }}</option>
{% endfor %}
{% for c_iface in interfaces_host %}
<option value="iface:{{ c_iface }}" {% ifequal c_iface network.nic %} selected {% endifequal %}>{% trans 'Interface' %} {{ c_iface }}</option>
<option value="iface:{{ c_iface }}" {% if c_iface == network.nic %} selected {% endif %}>{% trans 'Interface' %} {{ c_iface }}</option>
{% endfor %}
</select>
</div>
@ -972,7 +971,7 @@
<select class="form-control" name="net-nwfilter-{{ forloop.counter0 }}">
<option value="">{% trans "None" %}</option>
{% for c_filters in nwfilters_host %}
<option value="{{ c_filters }}" {% ifequal c_filters network.filterref %} selected {% endifequal %}>{{ c_filters }}</option>
<option value="{{ c_filters }}" {% if c_filters == network.filterref %} selected {% endif %}>{{ c_filters }}</option>
{% endfor %}
</select>
</div>
@ -983,7 +982,7 @@
<input class="form-control" type="text" value="{{ network.model }}" readonly/>
<select class="form-control" name="net-model-{{ forloop.counter0 }}">
{% for model in net_models_host %}
<option value="{{ model }}" {% ifequal model network.model %} selected {% endifequal %}>{{ model }}</option>
<option value="{{ model }}" {% if model == network.model %} selected {% endif %}>{{ model }}</option>
{% endfor %}
</select>
</div>
@ -992,7 +991,7 @@
</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-dismiss="modal">{% trans 'Close' %}</button>
<button class="btn btn-success" name="change_network" title="{% trans "Apply Network Changes" %}">{% trans "Apply" %}</button>
<button class="btn btn-success" name="change_network" title="{% trans "Apply network changes" %}">{% trans "Apply" %}</button>
</div>
</div>
</div>
@ -1116,7 +1115,7 @@
<div class="form-group row">
<div class="col-sm-6 offset-3">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="live_migrate" value="true" id="vm_live_migrate" {% ifnotequal status 5 %}checked{% else %}disabled{% endifnotequal %}>
<input class="custom-control-input" type="checkbox" name="live_migrate" value="true" id="vm_live_migrate" {% if status != 5 %}checked{% else %}disabled{% endif %}>
<label class="custom-control-label" for="vm_live_migrate">{% trans "Live migration" %}</label>
</div>
</div>
@ -1140,7 +1139,7 @@
<div class="form-group row">
<div class="col-sm-6 offset-3">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="offline_migrate" value="true" id="offline_migrate" {% ifequal status 5 %}checked{% else %}disabled{% endifequal %}>
<input class="custom-control-input" type="checkbox" name="offline_migrate" value="true" id="offline_migrate" {% if status == 5 %}checked{% else %}disabled{% endif %}>
<label class="custom-control-label" for="offline_migrate">{% trans "Offline migration" %}</label>
</div>
</div>
@ -1148,7 +1147,7 @@
<div class="form-group row">
<div class="col-sm-6 offset-3">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="postcopy" value="true" id="postcopy" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
<input class="custom-control-input" type="checkbox" name="postcopy" value="true" id="postcopy" {% if status != 1 %}disabled{% endif %}>
<label class="custom-control-label" for="postcopy">{% trans "Post copy" %}</label>
</div>
</div>
@ -1156,7 +1155,7 @@
<div class="form-group row">
<div class="col-sm-6 offset-3">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="autoconverge" value="true" id="autoconverge" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
<input class="custom-control-input" type="checkbox" name="autoconverge" value="true" id="autoconverge" {% if status != 1 %}disabled{% endif %}>
<label class="custom-control-label" for="autoconverge" title="{% trans 'Forces CPU convergence during live migration' %}">{% trans "Auto converge" %}</label>
</div>
</div>
@ -1164,7 +1163,7 @@
<div class="form-group row">
<div class="col-sm-6 offset-3">
<div class="custom-control custom-switch">
<input class="custom-control-input" type="checkbox" name="compress" value="true" id="compress" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
<input class="custom-control-input" type="checkbox" name="compress" value="true" id="compress" {% if status != 1 %}disabled{% endif %}>
<label class="custom-control-label" for="compress" title="{% trans 'Compress instance memory for fast migration' %}">{% trans "Compressed" %}</label>
</div>
</div>
@ -1183,7 +1182,7 @@
<div class="col-sm-12" id="xmlheight">
<textarea id="editor">{{ inst_xml }}</textarea>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<input type="hidden" name="inst_xml">
<button type="submit" class="btn btn-lg btn-success float-right" name="change_xml">
{% trans "Change" %}
@ -1192,7 +1191,7 @@
<button class="btn btn-lg btn-success float-right disabled">
{% trans "Change" %}
</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
</div>
@ -1241,11 +1240,11 @@
</select>
<div class="input-group-append">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-success " name="set_console_type">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_console_type">{% trans "Set" %}</button>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -1264,11 +1263,11 @@
{% endfor %}
</select>
<div class="input-group-append">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-success " name="set_console_listen_address">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_console_listen_address">{% trans "Set" %}</button>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -1302,11 +1301,11 @@
{% if console_passwd %}
<a href="#" name="console_show" class="btn btn-md btn-primary" onclick="show_console()">{% trans "Show" %}</a>
{% endif %}
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-success" name="set_console_passwd">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_console_passwd">{% trans "Set" %}</button>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -1334,11 +1333,11 @@
</select>
<div class="input-group-append">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-success" name="set_console_keymap">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_console_keymap">{% trans "Set" %}</button>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -1410,14 +1409,14 @@
<div class="col-sm-6">
<div class="input-group">
<input id="disk_name-{{ disk.dev }}" type="text" class="form-control" name="disk-{{ disk.dev }}" value="{{ disk.image }}"/>
{% ifequal disk.format 'qcow2' %}
{% if disk.format == 'qcow2' %}
<div class="input-group-append">
<span class="input-group-text" >{% trans 'Metadata' %}</span>
<div class="input-group-text">
<input type="checkbox" name="meta-{{ disk.dev }}" value="true">
</div>
</div>
{% endifequal %}
{% endif %}
</div>
</div>
</div>
@ -1439,11 +1438,11 @@
<textarea name="clone-description" class="form-control"></textarea>
</div>
</div>
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-lg btn-success float-right" name="clone" onclick="showPleaseWaitDialog();">{% trans "Clone" %}</button>
{% else %}
<button class="btn btn-lg btn-success float-right disabled" name="clone">{% trans "Clone" %}</button>
{% endifequal %}
{% endif %}
</form>
<div class="clearfix"></div>
</div>
@ -1475,11 +1474,11 @@
</div>
<div class="form-group row">
<div class="offset-3 col-sm-6">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-block btn-success" name="change_options">{% trans "Change" %}</button>
{% else %}
<button class="btn btn-block btn-success disabled" name="change_options">{% trans "Change" %}</button>
{% endifequal %}
{% endif %}
</div>
</div>
</form>
@ -1497,11 +1496,11 @@
{% endfor %}
</select>
<span class="input-group-btn">
{% ifequal status 5 %}
{% if status == 5 %}
<button type="submit" class="btn btn-success" name="set_video_model">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_video_model">{% trans "Set" %}</button>
{% endifequal %}
{% endif %}
</span>
</div>
</div>
@ -1669,10 +1668,9 @@
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
<p>{% trans "Delete storage for instance?" %}</p>
{% if request.user.is_superuser or userinstance.is_delete %}
{% ifequal status 3 %}
{% if status == 3 %}
<button class="btn btn-lg btn-success disabled float-right" name="delete">{% trans "Destroy" %}</button>
{% else %}
<form class="form" method="post" role="form" id="delete_form">{% csrf_token %}
<div class="ml-3 form-row">
<div class="custom-control custom-switch">
@ -1690,7 +1688,7 @@
{% endif %}
<button type="submit" class="btn btn-lg btn-success float-right" name="delete">{% trans "Destroy" %}</button>
</form>
{% endifequal %}
{% endif %}
{% else %}
<button class="btn btn-lg btn-success disabled float-right" name="delete">{% trans "Destroy" %}</button>
{% endif %}

View file

@ -13,9 +13,9 @@ from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from computes.models import Compute
from instances.models import Instance
from appsettings.models import AppSettings
from django.contrib.auth.models import User
from accounts.models import UserInstance, UserSSHKey
from appsettings.models import AppSettings
from vrtManager.hostdetails import wvmHostDetails
from vrtManager.instance import wvmInstance, wvmInstances
from vrtManager.connection import connection_manager
@ -64,7 +64,7 @@ def allinstances(request):
error_messages.append(lib_err)
addlogmsg(request.user.username, request.POST.get("name", "instance"), lib_err)
view_style = settings.VIEW_INSTANCES_LIST_STYLE
view_style = AppSettings.objects.get(key="VIEW_INSTANCES_LIST_STYLE").value
return render(request, 'allinstances.html', locals())
@ -111,10 +111,11 @@ def instance(request, compute_id, vname):
computes_count = computes.count()
users = User.objects.all().order_by('username')
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
appsettings = AppSettings.objects.all()
keymaps = settings.QEMU_KEYMAPS
console_types = settings.QEMU_CONSOLE_TYPES
console_types = appsettings.get(key="QEMU_CONSOLE_DEFAULT_TYPE").choices_as_list
console_listen_addresses = settings.QEMU_CONSOLE_LISTEN_ADDRESSES
bottom_bar = AppSettings.objects.get(key="VIEW_INSTANCE_DETAIL_BOTTOM_BAR").value
bottom_bar = appsettings.get(key="VIEW_INSTANCE_DETAIL_BOTTOM_BAR").value
try:
userinstance = UserInstance.objects.get(instance__compute_id=compute_id,
instance__name=vname,
@ -144,7 +145,7 @@ def instance(request, compute_id, vname):
return int(float(size_str))
def get_clone_free_names(size=10):
prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX
prefix = appsettings.get(key="CLONE_INSTANCE_DEFAULT_PREFIX").value
free_names = []
existing_names = [i.name for i in Instance.objects.filter(name__startswith=prefix)]
index = 1
@ -179,21 +180,22 @@ def instance(request, compute_id, vname):
disk_size += int(disk['size']) >> 30
if ua.max_instances > 0 and instance > ua.max_instances:
quota_debug = appsettings.get(key="QUOTA_DEBUG").value
msg = "instance"
if settings.QUOTA_DEBUG:
msg += " (%s > %s)" % (instance, ua.max_instances)
if quota_debug:
msg += f" ({instance} > {ua.max_instances})"
if ua.max_cpus > 0 and cpu > ua.max_cpus:
msg = "cpu"
if settings.QUOTA_DEBUG:
msg += " (%s > %s)" % (cpu, ua.max_cpus)
if quota_debug:
msg += f" ({cpu} > {ua.max_cpus})"
if ua.max_memory > 0 and memory > ua.max_memory:
msg = "memory"
if settings.QUOTA_DEBUG:
msg += " (%s > %s)" % (memory, ua.max_memory)
if quota_debug:
msg += f" ({memory} > {ua.max_memory})"
if ua.max_disk_size > 0 and disk_size > ua.max_disk_size:
msg = "disk"
if settings.QUOTA_DEBUG:
msg += " (%s > %s)" % (disk_size, ua.max_disk_size)
if quota_debug:
msg += f" ({disk_size} > {ua.max_disk_size})"
return msg
def get_new_disk_dev(media, disks, bus):
@ -314,18 +316,21 @@ def instance(request, compute_id, vname):
io_modes = sorted(conn.get_io_modes().items())
discard_modes = sorted(conn.get_discard_modes().items())
detect_zeroes_modes = sorted(conn.get_detect_zeroes_modes().items())
default_io = settings.INSTANCE_VOLUME_DEFAULT_IO
default_discard = settings.INSTANCE_VOLUME_DEFAULT_DISCARD
default_zeroes = settings.INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES
default_cache = settings.INSTANCE_VOLUME_DEFAULT_CACHE
default_format = settings.INSTANCE_VOLUME_DEFAULT_FORMAT
default_owner = settings.INSTANCE_VOLUME_DEFAULT_OWNER
default_bus = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_BUS").value
default_io = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_IO").value
default_discard = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_DISCARD").value
default_zeroes = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES").value
default_cache = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_CACHE").value
default_format = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_FORMAT").value
default_disk_owner_uid = int(appsettings.get(key="INSTANCE_VOLUME_DEFAULT_OWNER_UID").value)
default_disk_owner_gid = int(appsettings.get(key="INSTANCE_VOLUME_DEFAULT_OWNER_GID").value)
formats = conn.get_image_formats()
show_access_root_password = settings.SHOW_ACCESS_ROOT_PASSWORD
show_access_ssh_keys = settings.SHOW_ACCESS_SSH_KEYS
clone_instance_auto_name = settings.CLONE_INSTANCE_AUTO_NAME
default_bus = settings.INSTANCE_VOLUME_DEFAULT_BUS
show_access_root_password = appsettings.get(key="SHOW_ACCESS_ROOT_PASSWORD").value
show_access_ssh_keys = appsettings.get(key="SHOW_ACCESS_SSH_KEYS").value
clone_instance_auto_name = appsettings.get(key="CLONE_INSTANCE_AUTO_NAME").value
try:
instance = Instance.objects.get(compute_id=compute_id, name=vname)
@ -520,7 +525,7 @@ def instance(request, compute_id, vname):
error_messages.append(msg)
else:
conn.resize_disk(disks_new)
msg = _("Resize")
msg = _("Disk resize")
addlogmsg(request.user.username, instance.name, msg)
messages.success(request, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize')
@ -539,9 +544,9 @@ def instance(request, compute_id, vname):
cache = request.POST.get('cache', default_cache)
target_dev = get_new_disk_dev(media, disks, bus)
source = conn_create.create_volume(storage, name, size, format, meta_prealloc, default_owner)
source = conn_create.create_volume(storage, name, size, format, meta_prealloc, default_disk_owner_uid, default_disk_owner_gid)
conn.attach_disk(target_dev, source, target_bus=bus, driver_type=format, cache_mode=cache)
msg = _('Attach new disk {} ({})'.format(name, format))
msg = _(f"Attach new disk {name} ({format})")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#disks')
@ -810,8 +815,11 @@ def instance(request, compute_id, vname):
if 'set_console_type' in request.POST:
console_type = request.POST.get('console_type', '')
conn.set_console_type(console_type)
msg = _("Set VNC type")
if console_type in console_types:
conn.set_console_type(console_type)
else:
msg = _("Console type not supported")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
@ -943,13 +951,13 @@ def instance(request, compute_id, vname):
if 'add_owner' in request.POST:
user_id = int(request.POST.get('user_id', ''))
if settings.ALLOW_INSTANCE_MULTIPLE_OWNER:
if appsettings.get(key="ALLOW_INSTANCE_MULTIPLE_OWNER").value == 'True':
check_inst = UserInstance.objects.filter(instance=instance, user_id=user_id)
else:
check_inst = UserInstance.objects.filter(instance=instance)
if check_inst:
msg = _("Owner already added")
msg = _("One owner is allowed and owner already added")
error_messages.append(msg)
else:
add_user_inst = UserInstance(instance=instance, user_id=user_id)
@ -975,10 +983,13 @@ def instance(request, compute_id, vname):
quota_msg = check_user_quota(1, vcpu, memory, disk_sum)
check_instance = Instance.objects.filter(name=clone_data['name'])
clone_data['disk_owner_uid'] = default_disk_owner_uid
clone_data['disk_owner_gid'] = default_disk_owner_gid
for post in request.POST:
clone_data[post] = request.POST.get(post, '').strip()
if clone_instance_auto_name and not clone_data['name']:
if clone_instance_auto_name == 'True' and not clone_data['name']:
auto_vname = clone_free_names[0]
clone_data['name'] = auto_vname
clone_data['clone-net-mac-0'] = _get_dhcp_mac_address(auto_vname)
@ -1016,7 +1027,8 @@ def instance(request, compute_id, vname):
msg = _("Clone of '%s'" % instance.name)
addlogmsg(request.user.username, new_instance.name, msg)
if settings.CLONE_INSTANCE_AUTO_MIGRATE:
if appsettings.get(key="CLONE_INSTANCE_AUTO_MIGRATE").value == 'True':
new_compute = Compute.objects.order_by('?').first()
migrate_instance(new_compute, new_instance, xml_del=True, offline=True)
return HttpResponseRedirect(
@ -1326,7 +1338,7 @@ def random_mac_address(request):
def guess_clone_name(request):
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX
prefix = appsettings.get(key="CLONE_INSTANCE_DEFAULT_PREFIX").value
if os.path.isfile(dhcp_file):
instance_names = [i.name for i in Instance.objects.filter(name__startswith=prefix)]
with open(dhcp_file, 'r') as f: