Beispiel #1
0
def upgrade(request):

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                try:
                    Update(
                        get_handler=handler.get_handler,
                        install_handler=handler.install_handler,
                    )
                except Exception, e:
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Beispiel #2
0
def upgrade(request):

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                try:
                    Update(
                        get_handler=handler.get_handler,
                        install_handler=handler.install_handler,
                    )
                except Exception, e:
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Beispiel #3
0
def update_apply(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().get_update_location()
                try:
                    log.debug("Starting ApplyUpdate")
                    ApplyUpdate(
                        path,
                        install_handler=handler.install_handler,
                    )
                    log.debug("ApplyUpdate finished!")
                except Exception, e:
                    log.debug("Exception ApplyUpdate")
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Beispiel #4
0
def update_apply(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().system_dataset_path()
                if not path:
                    raise MiddlewareError(_('System dataset not configured'))
                try:
                    ApplyUpdate(
                        '%s/update' % path,
                        install_handler=handler.install_handler,
                    )
                except Exception, e:
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Beispiel #5
0
def update_apply(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        handler = UpdateHandler(uuid=uuid)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().system_dataset_path()
                if not path:
                    raise MiddlewareError(_('System dataset not configured'))
                try:
                    ApplyUpdate(
                        '%s/update' % path,
                        install_handler=handler.install_handler,
                    )
                except Exception, e:
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            request.session['allow_reboot'] = True
            return render(request, 'system/done.html')
Beispiel #6
0
def update_check(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        if request.POST.get('apply') == '1':
            apply_ = True
        else:
            apply_ = False
        handler = UpdateHandler(uuid=uuid, apply_=apply_)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().system_dataset_path()
                if not path:
                    raise MiddlewareError(_('System dataset not configured'))
                try:
                    if handler.apply:
                        Update(
                            train=updateobj.get_train(),
                            get_handler=handler.get_handler,
                            install_handler=handler.install_handler,
                            cache_dir='%s/update' % path,
                        )
                    else:
                        DownloadUpdate(
                            updateobj.get_train(),
                            '%s/update' % path,
                            check_handler=handler.get_handler,
                            get_handler=handler.get_file_handler,
                        )
                except Exception, e:
                    from freenasUI.common.log import log_traceback
                    log_traceback(log=log)
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            if handler.apply:
                request.session['allow_reboot'] = True
                return render(request, 'system/done.html')
            else:
                return JsonResp(
                    request,
                    message=_('Packages downloaded'),
                )
Beispiel #7
0
def update_check(request):

    try:
        updateobj = models.Update.objects.order_by('-id')[0]
    except IndexError:
        updateobj = models.Update.objects.create()

    if request.method == 'POST':
        uuid = request.GET.get('uuid')
        if request.POST.get('apply') == '1':
            apply_ = True
        else:
            apply_ = False
        handler = UpdateHandler(uuid=uuid, apply_=apply_)
        if not uuid:
            #FIXME: ugly
            pid = os.fork()
            if pid != 0:
                return HttpResponse(handler.uuid, status=202)
            else:
                handler.pid = os.getpid()
                handler.dump()
                path = notifier().system_dataset_path()
                if not path:
                    raise MiddlewareError(_('System dataset not configured'))
                try:
                    if handler.apply:
                        Update(
                            train=updateobj.get_train(),
                            get_handler=handler.get_handler,
                            install_handler=handler.install_handler,
                            cache_dir='%s/update' % path,
                        )
                    else:
                        DownloadUpdate(
                            updateobj.get_train(),
                            '%s/update' % path,
                            check_handler=handler.get_handler,
                            get_handler=handler.get_file_handler,
                        )
                except Exception, e:
                    from freenasUI.common.log import log_traceback
                    log_traceback(log=log)
                    handler.error = unicode(e)
                handler.finished = True
                handler.dump()
                os.kill(handler.pid, 9)
        else:
            if handler.error is not False:
                raise MiddlewareError(handler.error)
            if not handler.finished:
                return HttpResponse(handler.uuid, status=202)
            handler.exit()
            if handler.apply:
                request.session['allow_reboot'] = True
                return render(request, 'system/done.html')
            else:
                return JsonResp(
                    request,
                    message=_('Packages downloaded'),
                )