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:
parent
62f8ece0ef
commit
7538ddab4f
27 changed files with 454 additions and 447 deletions
|
|
@ -83,7 +83,7 @@
|
|||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="addFromXML">
|
||||
<div class="well">
|
||||
<div>
|
||||
<form method="post" role="form" aria-label="Create instance with XML form">{% csrf_token %}
|
||||
<div class="col-sm-12" id="xmlheight">
|
||||
<input type="hidden" name="dom_xml"/>
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@
|
|||
<div class="col-sm-6">
|
||||
<select id="cache_mode" name="cache_mode" class="custom-select">
|
||||
{% for mode, name in cache_modes %}
|
||||
<option value="{{ mode }}" {% ifequal mode default_cache %}selected {% endifequal %}>
|
||||
<option value="{{ mode }}" {% if mode == default_cache %}selected {% endif %}>
|
||||
{% trans name %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
@ -303,7 +303,7 @@
|
|||
</div>
|
||||
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="addCustom">
|
||||
<div class="well">
|
||||
<div>
|
||||
<form method="post" role="form" aria-label="Create custom instance form">{% csrf_token %}
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-3 col-form-label">{% trans "Name" %}</label>
|
||||
|
|
@ -423,7 +423,7 @@
|
|||
<div class="col-sm-7">
|
||||
<select id="cache_mode" name="cache_mode" class="form-control">
|
||||
{% for mode, name in cache_modes %}
|
||||
<option value="{{ mode }}" {% ifequal mode default_cache %}selected {% endifequal %}>
|
||||
<option value="{{ mode }}" {% if mode == default_cache %}selected {% endif %}>
|
||||
{% trans name %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
@ -516,7 +516,7 @@
|
|||
</div>
|
||||
|
||||
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="addFromTemp">
|
||||
<div class="well">
|
||||
<div>
|
||||
<form method="post" role="form" aria-label="Create instance from template form">{% csrf_token %}
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-3 col-form-label">{% trans "Name" %}</label>
|
||||
|
|
@ -636,7 +636,7 @@
|
|||
<div class="col-sm-7">
|
||||
<select id="cache_mode" name="cache_mode" class="custom-select">
|
||||
{% for mode, name in cache_modes %}
|
||||
<option value="{{ mode }}" {% ifequal mode default_cache %}selected{% endifequal %}>
|
||||
<option value="{{ mode }}" {% if mode == default_cache %}selected{% endif %}>
|
||||
{% trans name %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
@ -788,8 +788,7 @@
|
|||
'{% endfor %}' +
|
||||
'</select>' +
|
||||
' -> ' + value + ' ' +
|
||||
'<a class="btn-link float-right" onclick="javascript:$(\'#image-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a>' +
|
||||
'</li>';
|
||||
'<a class="btn-link float-right" onclick="javascript:$(\'#image-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a></li>';
|
||||
selected_list_html += li;
|
||||
counter++;
|
||||
});
|
||||
|
|
@ -797,7 +796,6 @@
|
|||
$('#disk_list_div').addClass('d-none');
|
||||
}
|
||||
$('#img-list').html(selected_list_html);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -822,7 +820,7 @@
|
|||
$.each(input_value.split(','), function (index, value) {
|
||||
let li = '<li>eth' + counter +
|
||||
' -> ' + value + ' ' +
|
||||
'<a class="btn-link float-right" onclick="$(\'#network-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a></a></li>';
|
||||
'<a class="btn-link float-right" onclick="$(\'#network-control\').multiselect(\'deselect\', \'' + value + '\', true)"><i class="fa fa-remove"></i></a></li>';
|
||||
selected_list_html += li;
|
||||
counter++;
|
||||
});
|
||||
|
|
|
|||
108
create/views.py
108
create/views.py
|
|
@ -8,23 +8,12 @@ from admin.decorators import superuser_only
|
|||
from computes.models import Compute
|
||||
from create.models import Flavor
|
||||
from create.forms import FlavorAddForm, NewVMForm
|
||||
from appsettings.models import AppSettings
|
||||
from instances.models import Instance
|
||||
from vrtManager.create import wvmCreate
|
||||
from vrtManager import util
|
||||
from logs.views import addlogmsg
|
||||
|
||||
from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_CACHE
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_BUS
|
||||
from webvirtcloud.settings import INSTANCE_CPU_DEFAULT_MODE
|
||||
from webvirtcloud.settings import INSTANCE_MACHINE_DEFAULT_TYPE
|
||||
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_IO
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_DISCARD
|
||||
from webvirtcloud.settings import INSTANCE_ARCH_DEFAULT_TYPE
|
||||
from webvirtcloud.settings import INSTANCE_FIRMWARE_DEFAULT_TYPE
|
||||
|
||||
|
||||
@superuser_only
|
||||
def create_instance_select_type(request, compute_id):
|
||||
|
|
@ -40,6 +29,7 @@ def create_instance_select_type(request, compute_id):
|
|||
hypervisors = list()
|
||||
meta_prealloc = False
|
||||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
appsettings = AppSettings.objects.all()
|
||||
|
||||
try:
|
||||
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
||||
|
|
@ -48,8 +38,8 @@ def create_instance_select_type(request, compute_id):
|
|||
# Supported hypervisors by webvirtcloud: i686, x86_64(for now)
|
||||
supported_arch = ["x86_64", "i686", "aarch64", "armv7l", "ppc64", "ppc64le", "s390x"]
|
||||
hypervisors = [hpv for hpv in all_hypervisors.keys() if hpv in supported_arch]
|
||||
default_machine = INSTANCE_MACHINE_DEFAULT_TYPE
|
||||
default_arch = INSTANCE_ARCH_DEFAULT_TYPE
|
||||
default_machine = appsettings.get(key="INSTANCE_MACHINE_DEFAULT_TYPE").value
|
||||
default_arch = appsettings.get(key="INSTANCE_ARCH_DEFAULT_TYPE").value
|
||||
|
||||
if request.method == 'POST':
|
||||
if 'create_xml' in request.POST:
|
||||
|
|
@ -93,28 +83,33 @@ def create_instance(request, compute_id, arch, machine):
|
|||
meta_prealloc = False
|
||||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
flavors = Flavor.objects.filter().order_by('id')
|
||||
appsettings = AppSettings.objects.all()
|
||||
|
||||
try:
|
||||
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
||||
|
||||
default_firmware = INSTANCE_FIRMWARE_DEFAULT_TYPE
|
||||
default_cpu_mode = INSTANCE_CPU_DEFAULT_MODE
|
||||
default_firmware = appsettings.get(key="INSTANCE_FIRMWARE_DEFAULT_TYPE").value
|
||||
default_cpu_mode = appsettings.get(key="INSTANCE_CPU_DEFAULT_MODE").value
|
||||
instances = conn.get_instances()
|
||||
videos = conn.get_video_models(arch, machine)
|
||||
cache_modes = sorted(conn.get_cache_modes().items())
|
||||
default_cache = INSTANCE_VOLUME_DEFAULT_CACHE.lower()
|
||||
default_io = INSTANCE_VOLUME_DEFAULT_IO.lower()
|
||||
default_zeroes = INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES.lower()
|
||||
default_discard = INSTANCE_VOLUME_DEFAULT_DISCARD.lower()
|
||||
default_cache = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_CACHE").value
|
||||
default_io = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_IO").value
|
||||
default_zeroes = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_DETECT_ZEROES").value
|
||||
default_discard = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_DISCARD").value
|
||||
default_disk_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)
|
||||
default_scsi_disk_model = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_SCSI_CONTROLLER").value
|
||||
listener_addr = QEMU_CONSOLE_LISTEN_ADDRESSES
|
||||
mac_auto = util.randomMAC()
|
||||
disk_devices = conn.get_disk_device_types(arch, machine)
|
||||
disk_buses = conn.get_disk_bus_types(arch, machine)
|
||||
default_bus = INSTANCE_VOLUME_DEFAULT_BUS
|
||||
default_bus = appsettings.get(key="INSTANCE_VOLUME_DEFAULT_BUS").value
|
||||
networks = sorted(conn.get_networks())
|
||||
nwfilters = conn.get_nwfilters()
|
||||
storages = sorted(conn.get_storages(only_actives=True))
|
||||
default_graphics = QEMU_CONSOLE_DEFAULT_TYPE
|
||||
default_graphics = appsettings.get(key="QEMU_CONSOLE_DEFAULT_TYPE").value
|
||||
|
||||
dom_caps = conn.get_dom_capabilities(arch, machine)
|
||||
caps = conn.get_capabilities(arch)
|
||||
|
|
@ -177,18 +172,29 @@ def create_instance(request, compute_id, arch, machine):
|
|||
error_messages.append(error_msg)
|
||||
else:
|
||||
try:
|
||||
path = conn.create_volume(data['storage'],
|
||||
data['name'],
|
||||
data['hdd_size'],
|
||||
metadata=meta_prealloc)
|
||||
path = conn.create_volume(
|
||||
data['storage'],
|
||||
data['name'],
|
||||
data['hdd_size'],
|
||||
default_disk_format,
|
||||
meta_prealloc,
|
||||
default_disk_owner_uid,
|
||||
default_disk_owner_gid)
|
||||
volume = dict()
|
||||
volume['device'] = 'disk'
|
||||
volume['path'] = path
|
||||
volume['type'] = conn.get_volume_type(path)
|
||||
volume['device'] = 'disk'
|
||||
if data['virtio']:
|
||||
volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS
|
||||
volume['cache_mode'] = data['cache_mode']
|
||||
volume['bus'] = default_bus
|
||||
if volume['bus'] == 'scsi':
|
||||
volume['scsi_model'] = default_scsi_disk_model
|
||||
volume['discard_mode'] = default_discard
|
||||
volume['detect_zeroes_mode'] = default_zeroes
|
||||
volume['io_mode'] = default_io
|
||||
|
||||
volume_list.append(volume)
|
||||
is_disk_created = True
|
||||
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err)
|
||||
elif data['template']:
|
||||
|
|
@ -198,16 +204,25 @@ def create_instance(request, compute_id, arch, machine):
|
|||
error_msg = _("Image has already exist. Please check volumes or change instance name")
|
||||
error_messages.append(error_msg)
|
||||
else:
|
||||
clone_path = conn.clone_from_template(data['name'],
|
||||
templ_path,
|
||||
data['storage'],
|
||||
metadata=meta_prealloc)
|
||||
clone_path = conn.clone_from_template(
|
||||
data['name'],
|
||||
templ_path,
|
||||
data['storage'],
|
||||
meta_prealloc,
|
||||
default_disk_owner_uid,
|
||||
default_disk_owner_gid)
|
||||
volume = dict()
|
||||
volume['path'] = clone_path
|
||||
volume['type'] = conn.get_volume_type(clone_path)
|
||||
volume['device'] = 'disk'
|
||||
if data['virtio']:
|
||||
volume['bus'] = INSTANCE_VOLUME_DEFAULT_BUS
|
||||
volume['cache_mode'] = data['cache_mode']
|
||||
volume['bus'] = default_bus
|
||||
if volume['bus'] == 'scsi':
|
||||
volume['scsi_model'] = default_scsi_disk_model
|
||||
volume['discard_mode'] = default_discard
|
||||
volume['detect_zeroes_mode'] = default_zeroes
|
||||
volume['io_mode'] = default_io
|
||||
|
||||
volume_list.append(volume)
|
||||
is_disk_created = True
|
||||
else:
|
||||
|
|
@ -223,6 +238,13 @@ def create_instance(request, compute_id, arch, machine):
|
|||
volume['type'] = conn.get_volume_type(path)
|
||||
volume['device'] = request.POST.get('device' + str(idx), '')
|
||||
volume['bus'] = request.POST.get('bus' + str(idx), '')
|
||||
if volume['bus'] == 'scsi':
|
||||
volume['scsi_model'] = default_scsi_disk_model
|
||||
volume['cache_mode'] = data['cache_mode']
|
||||
volume['discard_mode'] = default_discard
|
||||
volume['detect_zeroes_mode'] = default_zeroes
|
||||
volume['io_mode'] = default_io
|
||||
|
||||
volume_list.append(volume)
|
||||
except libvirtError as lib_err:
|
||||
error_messages.append(lib_err)
|
||||
|
|
@ -253,23 +275,19 @@ def create_instance(request, compute_id, arch, machine):
|
|||
arch=arch,
|
||||
machine=machine,
|
||||
firmware=firmware,
|
||||
images=volume_list,
|
||||
cache_mode=data['cache_mode'],
|
||||
io_mode=default_io,
|
||||
discard_mode=default_discard,
|
||||
detect_zeroes_mode=default_zeroes,
|
||||
networks=data['networks'],
|
||||
volumes=volume_list,
|
||||
networks=data['networks'],
|
||||
virtio=data['virtio'],
|
||||
listen_addr=data["listener_addr"],
|
||||
listen_addr=data["listener_addr"],
|
||||
nwfilter=data["nwfilter"],
|
||||
graphics=data["graphics"],
|
||||
graphics=data["graphics"],
|
||||
video=data["video"],
|
||||
console_pass=data["console_pass"],
|
||||
console_pass=data["console_pass"],
|
||||
mac=data['mac'],
|
||||
qemu_ga=data['qemu_ga'])
|
||||
create_instance = Instance(compute_id=compute_id, name=data['name'], uuid=uuid)
|
||||
create_instance.save()
|
||||
msg = _("Instance is created.")
|
||||
msg = _("Instance is created")
|
||||
messages.success(request, msg)
|
||||
addlogmsg(request.user.username, create_instance.name, msg)
|
||||
return HttpResponseRedirect(reverse('instance', args=[compute_id, data['name']]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue