def settings_form(request, hostname): """ Ajax page for changing server settings. """ if hostname is None: vm = None else: vm = get_vm(request, hostname) if request.user.is_admin(request): # can_edit permission action = None form = AdminServerSettingsForm(request, vm, request.POST, prefix='opt') else: action = 'update' form = ServerSettingsForm(request, vm, request.POST, prefix='opt') # noinspection PyUnresolvedReferences if form.is_valid(): # noinspection PyUnresolvedReferences status = form.save(action=action, args=(form.current_hostname, )) if status == 204: # Nothing changed return HttpResponse(None, status=status) elif status in (200, 201): # noinspection PyUnresolvedReferences if form.action == 'delete': return redirect('vm_list') else: return redirect('vm_details', hostname=form.saved_hostname) return render(request, 'gui/vm/settings_form.html', { 'settingsform': form, 'vm': vm, 'mb_addon': SIZE_FIELD_MB_ADDON, })
def set_installed(request, hostname): """ Ajax page for marking the server as installed. """ vm = get_vm(request, hostname) if request.POST.get('installed'): # PUT vm_define res = ServerSettingsForm.api_call('update', vm, request, args=(hostname,), data={'installed': True}) if res.status_code == 200: messages.success(request, _('Server was marked as installed.')) return redirect('vm_details', hostname=hostname) else: return JSONResponse(res.data, status=res.status_code) raise PermissionDenied
def details(request, hostname): """ Page with details of server. """ dc_settings = request.dc.settings context = collect_view_data(request, 'vm_list', mb_addon=SIZE_FIELD_MB_ADDON) context['vm'] = vm = get_vm(request, hostname, sr=('dc', 'owner', 'node', 'template', 'slavevm')) context['vms'] = vms = get_vms(request) context['vms_tags'] = get_vms_tags(vms) context['vm_disks'] = vm_disks = get_vm_define_disk(request, vm) context['vm_nics'] = vm_nics = get_vm_define_nic(request, vm) context['ptrform'] = PTRForm(prefix='ptr') context['iso_rescuecd'] = dc_settings.VMS_ISO_RESCUECD context['mon_sla_enabled'] = (settings.MON_ZABBIX_ENABLED and DefaultDc().settings.MON_ZABBIX_ENABLED and dc_settings.MON_ZABBIX_VM_SLA) context['can_edit'] = request.user.is_admin(request) if vm.slave_vms: context['slave_vm'] = vm.slave_vm.select_related( 'master_vm', 'vm', 'vm__node').exclude(name='').first() else: context['slave_vm'] = None if vm.is_kvm(): context['iso_images'] = get_iso_images(request, vm.ostype) if vm.ostype == Vm.WINDOWS: context[ 'stop_timeout_period'] = dc_settings.VMS_VM_STOP_WIN_TIMEOUT_DEFAULT else: context[ 'stop_timeout_period'] = dc_settings.VMS_VM_STOP_TIMEOUT_DEFAULT if context['can_edit']: context['settingsform'] = AdminServerSettingsForm(request, vm, prefix='opt') initial_disk = { 'disk_id': len(vm_disks) + 1, 'zpool': vm.zpool, 'model': dc_settings.VMS_DISK_MODEL_DEFAULT, 'compression': dc_settings.VMS_DISK_COMPRESSION_DEFAULT, 'image': dc_settings.VMS_DISK_IMAGE_DEFAULT, } if initial_disk['disk_id'] == 1: initial_disk['boot'] = True initial_nic = { 'nic_id': len(vm_nics) + 1, 'model': dc_settings.VMS_NIC_MODEL_DEFAULT, 'net': dc_settings.VMS_NET_DEFAULT, } if initial_nic['nic_id'] == 1: initial_nic['dns'] = True initial_nic['primary'] = True if initial_nic['nic_id'] == dc_settings.VMS_NIC_MONITORING_DEFAULT: initial_nic['monitoring'] = True if vm.template: initial_disk.update( vm.template.get_vm_define_disk(initial_disk['disk_id'])) initial_nic.update( vm.template.get_vm_define_nic(initial_nic['nic_id'])) context['disk_settingsform'] = AdminServerDiskSettingsForm( request, vm, prefix='opt-disk', initial=initial_disk) context['nic_settingsform'] = AdminServerNicSettingsForm( request, vm, prefix='opt-nic', initial=initial_nic) else: context['settingsform'] = ServerSettingsForm(request, vm, prefix='opt') context['disk_settingsform'] = ServerDiskSettingsForm( request, vm, prefix='opt-disk') context['nic_settingsform'] = ServerNicSettingsForm(request, vm, prefix='opt-nic') view_vm_details.send(sender='gui.vm.views.details', request=request, context=context) return render(request, 'gui/vm/details.html', context)