Ejemplo n.º 1
0
def license_update(request):

    license, reason = utils.get_license()
    if request.method == 'POST':
        form = forms.LicenseUpdateForm(request.POST)
        if form.is_valid():
            with open(utils.LICENSE_FILE, 'wb+') as f:
                f.write(form.cleaned_data.get('license').encode('ascii'))
            events = []
            try:
                _n = notifier()
                if not _n.is_freenas():
                    s = _n.failover_rpc()
                    if s is not None:
                        _n.sync_file_send(s, utils.LICENSE_FILE)
                form.done(request, events)
            except Exception as e:
                log.debug("Failed to sync license file: %s", e, exc_info=True)
            return JsonResp(request,
                            events=events,
                            message=_('License updated.'))
        else:
            return JsonResp(request, form=form)
    else:
        form = forms.LicenseUpdateForm()
    return render(request, 'support/license_update.html', {
        'form': form,
        'license': license,
    })
Ejemplo n.º 2
0
def license_update(request):

    license, reason = utils.get_license()
    if request.method == 'POST':
        form = forms.LicenseUpdateForm(request.POST)
        if form.is_valid():
            with open(utils.LICENSE_FILE, 'wb+') as f:
                f.write(form.cleaned_data.get('license').encode('ascii'))
            try:
                _n = notifier()
                if hasattr(_n, 'failover_getpeer'):
                    ip, secret = _n.failover_getpeer()
                    if ip:
                        s = _n.failover_rpc(ip=ip)
                        _n.sync_file_send(s, secret, utils.LICENSE_FILE)
            except Exception as e:
                log.debug("Failed to sync license file: %s", e)
            return JsonResp(request, message=_('License updated.'))
        else:
            return JsonResp(request, form=form)
    else:
        form = forms.LicenseUpdateForm()
    return render(request, 'support/license_update.html', {
        'form': form,
        'license': license,
    })
Ejemplo n.º 3
0
def license_update(request):

    license, reason = utils.get_license()
    if request.method == 'POST':
        form = forms.LicenseUpdateForm(request.POST)
        if form.is_valid():
            with open(utils.LICENSE_FILE, 'wb+') as f:
                f.write(form.cleaned_data.get('license').encode('ascii'))
            with client as c:
                c.call('etc.generate', 'rc')
            events = []
            try:
                _n = notifier()
                if not _n.is_freenas():
                    with client as c:
                        _n.sync_file_send(c, utils.LICENSE_FILE)
                        c.call('failover.call_remote', 'etc.generate', ['rc'])
                form.done(request, events)
            except Exception as e:
                log.debug("Failed to sync license file: %s", e, exc_info=True)
            return JsonResp(request,
                            events=events,
                            message=_('License updated.'))
        else:
            return JsonResp(request, form=form)
    else:
        _n = notifier()
        try:
            if not _n.is_freenas() and _n.failover_licensed():
                with client as c:
                    c.call('failover.call_remote', 'core.ping')
        except ClientException:
            return render(request, 'failover/failover_down.html')
        form = forms.LicenseUpdateForm()

    eula = None
    if not notifier().is_freenas():
        if os.path.exists('/usr/local/share/truenas/eula.html'):
            with open('/usr/local/share/truenas/eula.html',
                      'r',
                      encoding='utf8') as f:
                eula = f.read()

    return render(request, 'support/license_update.html', {
        'eula': eula,
        'form': form,
        'license': license,
    })
Ejemplo n.º 4
0
def license_update(request):

    license, reason = utils.get_license()
    if request.method == 'POST':
        form = forms.LicenseUpdateForm(request.POST)
        if form.is_valid():
            with open(utils.LICENSE_FILE, 'wb+') as f:
                f.write(form.cleaned_data.get('license').encode('ascii'))
            return JsonResp(request, message=_('License updated.'))
        else:
            return JsonResp(request, form=form)
    else:
        form = forms.LicenseUpdateForm()
    return render(request, 'support/license_update.html', {
        'form': form,
        'license': license,
    })
Ejemplo n.º 5
0
def license_update(request):

    license = utils.get_license()[0]
    if request.method == 'POST':
        form = forms.LicenseUpdateForm(request.POST)
        if form.is_valid():
            with client as c:
                try:
                    c.call('system.license_update', form.cleaned_data.get('license'))
                except Exception as e:
                    form._errors['__all__'] = form.error_class([str(e)])
                    return JsonResp(request, form=form)

            return JsonResp(
                request,
                message=_('License updated.')
            )
        else:
            return JsonResp(request, form=form)
    else:
        _n = notifier()
        try:
            if not _n.is_freenas() and _n.failover_licensed():
                with client as c:
                    c.call('failover.call_remote', 'core.ping')
        except ClientException:
            return render(request, 'failover/failover_down.html')
        form = forms.LicenseUpdateForm()

    eula = None
    if not notifier().is_freenas():
        if os.path.exists('/usr/local/share/truenas/eula.html'):
            with open('/usr/local/share/truenas/eula.html', 'r', encoding='utf8') as f:
                eula = f.read()

    return render(request, 'support/license_update.html', {
        'eula': eula,
        'form': form,
        'license': license,
    })