Example #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')
Example #2
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')
Example #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().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')
Example #4
0
def update_progress(request):
    handler = UpdateHandler()
    return HttpResponse(
        json.dumps(handler.load()),
        content_type='application/json',
    )
Example #5
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'),
                )
Example #6
0
    )

    parser = argparse.ArgumentParser()
    parser.add_argument('-a',
                        '--apply',
                        action='store_true',
                        help='Apply updates')
    parser.add_argument('-d',
                        '--download',
                        action='store_true',
                        help='Download updates')
    parser.add_argument('-t', '--train', help='Train name')
    parser.add_argument('-c', '--cache', help='Path to the cache directory')
    args = parser.parse_args()

    handler = UpdateHandler(apply_=args.apply)
    handler.dump()
    print handler.uuid

    sys.stdout.flush()

    log.debug("Entering in daemon mode")

    with context:
        log.debug("Entered in daemon context")
        try:
            main(handler, args)
        except Exception, e:
            log.debug('Exception on update')
            log_traceback(log=log)
            handler.error = unicode(e)
Example #7
0
    )

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-a', '--apply', action='store_true',
        help='Apply updates'
    )
    parser.add_argument(
        '-d', '--download', action='store_true',
        help='Download updates'
    )
    parser.add_argument('-t', '--train', help='Train name')
    parser.add_argument('-c', '--cache', help='Path to the cache directory')
    args = parser.parse_args()

    handler = UpdateHandler(apply_=args.apply)
    handler.dump()
    print(handler.uuid)

    sys.stdout.flush()

    log.debug("Entering in daemon mode")

    with context:
        log.debug("Entered in daemon context")
        try:
            main(handler, args)
        except Exception as e:
            log.debug('Exception on update')
            log_traceback(log=log)
            handler.error = str(e)
Example #8
0
def update_progress(request):
    handler = UpdateHandler()
    return HttpResponse(
        json.dumps(handler.load()),
        content_type='application/json',
    )
Example #9
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'),
                )
Example #10
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')
Example #11
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')
Example #12
0
    )

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-a', '--apply', action='store_true',
        help='Apply updates'
    )
    parser.add_argument(
        '-d', '--download', action='store_true',
        help='Download updates'
    )
    parser.add_argument('-t', '--train', help='Train name')
    parser.add_argument('-c', '--cache', help='Path to the cache directory')
    args = parser.parse_args()

    handler = UpdateHandler(apply_=args.apply)
    handler.dump()
    print handler.uuid

    sys.stdout.flush()

    log.debug("Entering in daemon mode")

    with context:
        log.debug("Entered in daemon context")
        try:
            main(handler, args)
        except Exception, e:
            log.debug('Exception on update')
            log_traceback(log=log)
            handler.error = unicode(e)