mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Added admin application
- Manage users - Manage groups - Manage logs
This commit is contained in:
parent
38befa4362
commit
27f62dff6c
38 changed files with 933 additions and 742 deletions
|
@ -23,13 +23,12 @@ from webvirtcloud.settings import INSTANCE_FIRMWARE_DEFAULT_TYPE
|
|||
|
||||
from django.contrib import messages
|
||||
from logs.views import addlogmsg
|
||||
from admin.decorators import superuser_only
|
||||
|
||||
|
||||
@superuser_only
|
||||
def create_instance_select_type(request, compute_id):
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
conn = None
|
||||
error_messages = list()
|
||||
storages = list()
|
||||
|
@ -39,10 +38,7 @@ def create_instance_select_type(request, compute_id):
|
|||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
|
||||
try:
|
||||
conn = wvmCreate(compute.hostname,
|
||||
compute.login,
|
||||
compute.password,
|
||||
compute.type)
|
||||
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
||||
instances = conn.get_instances()
|
||||
all_hypervisors = conn.get_hypervisors_machines()
|
||||
# Supported hypervisors by webvirtcloud: i686, x86_64(for now)
|
||||
|
@ -74,6 +70,7 @@ def create_instance_select_type(request, compute_id):
|
|||
return render(request, 'create_instance_w1.html', locals())
|
||||
|
||||
|
||||
@superuser_only
|
||||
def create_instance(request, compute_id, arch, machine):
|
||||
"""
|
||||
:param request:
|
||||
|
@ -82,8 +79,6 @@ def create_instance(request, compute_id, arch, machine):
|
|||
:param machine:
|
||||
:return:
|
||||
"""
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
conn = None
|
||||
error_messages = list()
|
||||
|
@ -96,10 +91,7 @@ def create_instance(request, compute_id, arch, machine):
|
|||
flavors = Flavor.objects.filter().order_by('id')
|
||||
|
||||
try:
|
||||
conn = wvmCreate(compute.hostname,
|
||||
compute.login,
|
||||
compute.password,
|
||||
compute.type)
|
||||
conn = wvmCreate(compute.hostname, compute.login, compute.password, compute.type)
|
||||
|
||||
default_firmware = INSTANCE_FIRMWARE_DEFAULT_TYPE
|
||||
default_cpu_mode = INSTANCE_CPU_DEFAULT_MODE
|
||||
|
@ -150,10 +142,7 @@ def create_instance(request, compute_id, arch, machine):
|
|||
form = FlavorAddForm(request.POST)
|
||||
if form.is_valid():
|
||||
data = form.cleaned_data
|
||||
create_flavor = Flavor(label=data['label'],
|
||||
vcpu=data['vcpu'],
|
||||
memory=data['memory'],
|
||||
disk=data['disk'])
|
||||
create_flavor = Flavor(label=data['label'], vcpu=data['vcpu'], memory=data['memory'], disk=data['disk'])
|
||||
create_flavor.save()
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
if 'delete_flavor' in request.POST:
|
||||
|
@ -184,7 +173,9 @@ 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'],
|
||||
path = conn.create_volume(data['storage'],
|
||||
data['name'],
|
||||
data['hdd_size'],
|
||||
metadata=meta_prealloc)
|
||||
volume = dict()
|
||||
volume['path'] = path
|
||||
|
@ -203,7 +194,10 @@ 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'],
|
||||
metadata=meta_prealloc)
|
||||
volume = dict()
|
||||
volume['path'] = clone_path
|
||||
volume['type'] = conn.get_volume_type(clone_path)
|
||||
|
@ -238,23 +232,36 @@ def create_instance(request, compute_id, arch, machine):
|
|||
firmware["readonly"] = 'yes'
|
||||
firmware["type"] = 'pflash'
|
||||
if 'secboot' in firmware["loader"] and machine != 'q35':
|
||||
messages.warning(request, "Changing machine type from '%s' to 'q35' "
|
||||
"which is required for UEFI secure boot." % machine)
|
||||
messages.warning(
|
||||
request, "Changing machine type from '%s' to 'q35' "
|
||||
"which is required for UEFI secure boot." % machine)
|
||||
machine = 'q35'
|
||||
firmware["secure"] = 'yes'
|
||||
|
||||
if not error_messages:
|
||||
uuid = util.randomUUID()
|
||||
try:
|
||||
conn.create_instance(name=data['name'], memory=data['memory'], vcpu=data['vcpu'],
|
||||
vcpu_mode=data['vcpu_mode'], uuid=uuid, arch=arch, machine=machine,
|
||||
conn.create_instance(name=data['name'],
|
||||
memory=data['memory'],
|
||||
vcpu=data['vcpu'],
|
||||
vcpu_mode=data['vcpu_mode'],
|
||||
uuid=uuid,
|
||||
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'], virtio=data['virtio'],
|
||||
listen_addr=data["listener_addr"], nwfilter=data["nwfilter"],
|
||||
graphics=data["graphics"], video=data["video"],
|
||||
console_pass=data["console_pass"], mac=data['mac'],
|
||||
images=volume_list,
|
||||
cache_mode=data['cache_mode'],
|
||||
io_mode=default_io,
|
||||
discard_mode=default_discard,
|
||||
detect_zeroes_mode=default_zeroes,
|
||||
networks=data['networks'],
|
||||
virtio=data['virtio'],
|
||||
listen_addr=data["listener_addr"],
|
||||
nwfilter=data["nwfilter"],
|
||||
graphics=data["graphics"],
|
||||
video=data["video"],
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue