Exemple #1
0
def imagestore_update(request, repo):
    """
    Ajax page for refreshing imagestore repositories.
    """
    if repo not in ImageStore.get_repositories(
            include_image_vm=request.user.is_staff):
        raise Http404

    res = call_api_view(request,
                        'PUT',
                        imagestore_manage,
                        repo,
                        log_response=True)

    if res.status_code == 200:
        imagestore = res.data['result']
        msg = _(
            'Downloaded metadata for %(image_count)d images from image repository %(name)s'
        )
        messages.success(request, msg % imagestore)

        return redirect('imagestore_list_repo',
                        repo=repo,
                        query_string=request.GET)
    else:
        if res.data.get('result', {}).get('error', None):
            status = 200  # The error will be displayed by ImageStoreList JS
        else:
            status = res.status_code

        return JSONResponse(res.data, status=status)
Exemple #2
0
def undo_settings(request, hostname):
    """
    Ajax page for reverting server definition by calling vm_define_revert.
    """
    vm = get_vm(request, hostname)
    res = UndoSettingsForm.api_call('update', vm, request, args=(hostname, ))

    if res.status_code == 200:
        return redirect('vm_details', hostname=vm.hostname)

    return JSONResponse(res.data, status=res.status_code)
Exemple #3
0
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
Exemple #4
0
def multi_settings_form(request):
    """
    Ajax page for changing settings of multiple servers.
    """
    if not request.user.is_admin(request):  # can_edit permission
        raise PermissionDenied

    if request.POST['action'] == 'delete':  # delete only for now
        for hostname in request.POST.getlist('hostname'):
            # DELETE vm_define
            vm = get_vm(request, hostname, auto_dc_switch=False)
            res = AdminServerSettingsForm.api_call('delete', vm, request, args=(hostname,))
            if res.status_code != 200:
                return JSONResponse(res.data, status=res.status_code)

        node = request.GET.get('node', None)

        if node:
            return redirect('node_vms', node)
        else:
            return redirect('vm_list')