Exemplo n.º 1
0
def snapshot_rollback(request, dataset, snapname):
    snapshot = '%s@%s' % (dataset, snapname)
    if request.method == "POST":
        ret = notifier().rollback_zfs_snapshot(snapshot=snapshot.__str__())
        if ret == '':
            return JsonResponse(message=_("Rollback successful."))
        else:
            return JsonResponse(error=True, message=ret)
    else:
        return render(request, 'storage/snapshot_confirm_rollback.html', {
            'snapname': snapname,
            'dataset': dataset,
        })
Exemplo n.º 2
0
def snapshot_delete(request, dataset, snapname):
    snapshot = '%s@%s' % (dataset, snapname)
    if request.method == 'POST':
        retval = notifier().destroy_zfs_dataset(path=str(snapshot))
        if retval == '':
            notifier().restart("collectd")
            return JsonResponse(message=_("Snapshot successfully deleted."))
        else:
            return JsonResponse(error=True, message=retval)
    else:
        return render(request, 'storage/snapshot_confirm_delete.html', {
            'snapname': snapname,
            'dataset': dataset,
        })
Exemplo n.º 3
0
def snapshot_delete_bulk(request):

    snaps = request.POST.get("snaps", None)
    delete = request.POST.get("delete", None)
    if snaps and delete == "true":
        snap_list = snaps.split('|')
        for snapshot in snap_list:
            retval = notifier().destroy_zfs_dataset(path=str(snapshot))
            if retval != '':
                return JsonResponse(error=True, message=retval)
        notifier().restart("collectd")
        return JsonResponse(message=_("Snapshots successfully deleted."))

    return render(request, 'storage/snapshot_confirm_delete_bulk.html', {
        'snaps': snaps,
    })
Exemplo n.º 4
0
def shutdown_dialog(request):
    if request.method == "POST":
        request.session['allow_shutdown'] = True
        return JsonResponse(error=False,
                    message=_("Shutdown is being issued"),
                    events=['window.location="%s"' % reverse('system_shutdown')])
    return render(request, 'system/shutdown_dialog.html')
Exemplo n.º 5
0
def zvol_create(request, volume_name):
    defaults = {
        'zvol_compression': 'inherit',
    }
    if request.method == 'POST':
        zvol_form = forms.ZVol_CreateForm(request.POST, vol_name=volume_name)
        if zvol_form.is_valid():
            props = {}
            cleaned_data = zvol_form.cleaned_data
            zvol_size = cleaned_data.get('zvol_size')
            zvol_name = "%s/%s" % (volume_name, cleaned_data.get('zvol_name'))
            zvol_compression = cleaned_data.get('zvol_compression')
            props['compression'] = str(zvol_compression)
            errno, errmsg = notifier().create_zfs_vol(name=str(zvol_name),
                                                      size=str(zvol_size),
                                                      props=props)
            if errno == 0:
                return JsonResponse(
                    message=_("ZFS Volume successfully added."))
            else:
                zvol_form.set_error(errmsg)
    else:
        zvol_form = forms.ZVol_CreateForm(initial=defaults,
                                          vol_name=volume_name)
    return render(request, 'storage/zvols.html', {
        'form': zvol_form,
        'volume_name': volume_name,
    })
Exemplo n.º 6
0
def wizard(request):

    if request.method == "POST":

        form = forms.VolumeWizardForm(request.POST)
        if form.is_valid():
            form.done(request)
            return JsonResponse(message=_("Volume successfully added."))
        else:
            if 'volume_disks' in request.POST:
                disks = request.POST.getlist('volume_disks')
            else:
                disks = None
            zpoolfields = re.compile(r'zpool_(.+)')
            zfsextra = [(zpoolfields.search(i).group(1), i, request.POST.get(i)) \
                        for i in request.POST.keys() if zpoolfields.match(i)]

    else:
        form = forms.VolumeWizardForm()
        disks = []
        zfsextra = None
    return render(
        request, 'storage/wizard.html', {
            'form': form,
            'disks': disks,
            'zfsextra': zfsextra,
            'zfsversion': notifier().zfs_get_version(),
        })
Exemplo n.º 7
0
def password_change(request):

    extra_context = {}
    password_change_form=forms.PasswordChangeForm
    passform = password_change_form(user=request.user)

    if request.method == 'POST':
        passform = password_change_form(user=request.user, data=request.POST)
        if passform.is_valid():
            if passform.cleaned_data['change_root']:
                root = models.bsdUsers.objects.get(bsdusr_username='******')
                new_password = passform.cleaned_data.get('new_password1')
                bsdpasswdform = forms.bsdUserPasswordForm(instance=root)
                bsdpasswdform.cleaned_data = {}
                bsdpasswdform.cleaned_data['bsdusr_password1'] = new_password
                bsdpasswdform.cleaned_data['bsdusr_password2'] = new_password
                bsdpasswdform.save()
            usable = request.user.has_usable_password()
            passform.save()
            events = []
            if not usable:
                from metanasUI.tools.alert import Alert
                alert = Alert()
                alert.perform()
                alert.write()
                del alert
                events.append("loadalert()")

            return JsonResponse(message=_("Password successfully updated."), events=events)

    extra_context.update({
        'form' : passform,
        'inline': True,
        })
    return render(request, 'account/passform.html', extra_context)
Exemplo n.º 8
0
def clonesnap(request, snapshot):
    initial = {'cs_snapshot': snapshot}
    if request.method == "POST":
        form = forms.CloneSnapshotForm(request.POST, initial=initial)
        if form.is_valid():
            retval = form.commit()
            if retval == '':
                return JsonResponse(message=_("Snapshot successfully cloned."))
            else:
                return JsonResponse(error=True, message=retval)
    else:
        is_volume = 'volume' in request.GET
        form = forms.CloneSnapshotForm(initial=initial, is_volume=is_volume)
    return render(request, 'storage/clonesnap.html', {
        'form': form,
        'snapshot': snapshot,
    })
Exemplo n.º 9
0
def geom_disk_replace(request, vname):

    volume = models.Volume.objects.get(vol_name=vname)
    if request.method == "POST":
        form = forms.UFSDiskReplacementForm(request.POST)
        if form.is_valid():
            if form.done(volume):
                return JsonResponse(
                    message=_("Disk replacement has been initiated."))
            else:
                return JsonResponse(error=True,
                                    message=_("An error occurred."))

    else:
        form = forms.UFSDiskReplacementForm()
    return render(request, 'storage/geom_disk_replace.html', {
        'form': form,
        'vname': vname,
    })
Exemplo n.º 10
0
def volume_detach(request, vid):

    volume = models.Volume.objects.get(pk=vid)
    usedbytes = sum(
        [mp._get_used_bytes() for mp in volume.mountpoint_set.all()])
    usedsize = humanize_size(usedbytes)
    services = volume.has_attachments()
    if request.method == "POST":
        form = forms.VolumeExport(request.POST,
                                  instance=volume,
                                  services=services)
        if form.is_valid():
            try:
                volume.delete(destroy=form.cleaned_data['mark_new'],
                              cascade=form.cleaned_data.get('cascade', True))
                return JsonResponse(
                    message=_("The volume has been successfully detached"))
            except ServiceFailed, e:
                return JsonResponse(error=True, message=unicode(e))
Exemplo n.º 11
0
def dataset_delete(request, name):

    datasets = zfs.list_datasets(path=name, recursive=True)
    if request.method == 'POST':
        form = forms.Dataset_Destroy(request.POST, fs=name, datasets=datasets)
        if form.is_valid():
            retval = notifier().destroy_zfs_dataset(path=name, recursive=True)
            if retval == '':
                notifier().restart("collectd")
                return JsonResponse(
                    message=_("Dataset successfully destroyed."))
            else:
                return JsonResponse(error=True, message=retval)
    else:
        form = forms.Dataset_Destroy(fs=name, datasets=datasets)
    return render(request, 'storage/dataset_confirm_delete.html', {
        'name': name,
        'form': form,
        'datasets': datasets,
    })
Exemplo n.º 12
0
 def process_response(self, request, response):
     if sys.exc_type and sys.exc_type in (MiddlewareError, ServiceFailed):
         excp = sys.exc_info()[1]
         kwargs = {
             'error': True,
             'message': _("Error: %s") % unicode(excp.value),
         }
         if not request.is_ajax():
             kwargs['enclosed'] = True
         return JsonResponse(**kwargs)
     return response
Exemplo n.º 13
0
 def done(self, request, form_list):
     retval = getattr(self, 'retval', None)
     events = []
     if not retval:
         events.append('reloadHttpd()')
     return JsonResponse(
         error=bool(retval),
         message=retval if retval else __("PBI successfully installed."),
         enclosed=not request.is_ajax(),
         events=events,
     )
Exemplo n.º 14
0
def zvol_delete(request, name):

    if request.method == 'POST':
        extents = iSCSITargetExtent.objects.filter(
            iscsi_target_extent_type='ZVOL',
            iscsi_target_extent_path='zvol/' + name)
        if extents.count() > 0:
            return JsonResponse(
                error=True,
                message=_("This is in use by the iscsi target, please remove "
                          "it there first."))
        retval = notifier().destroy_zfs_vol(name)
        if retval == '':
            return JsonResponse(
                message=_("ZFS Volume successfully destroyed."))
        else:
            return JsonResponse(error=True, message=retval)
    else:
        return render(request, 'storage/zvol_confirm_delete.html', {
            'name': name,
        })
Exemplo n.º 15
0
def manualsnap(request, fs):
    if request.method == "POST":
        form = forms.ManualSnapshotForm(request.POST)
        if form.is_valid():
            form.commit(fs)
            return JsonResponse(message=_("Snapshot successfully taken."))
    else:
        form = forms.ManualSnapshotForm()
    return render(request, 'storage/manualsnap.html', {
        'form': form,
        'fs': fs,
    })
Exemplo n.º 16
0
def user2group_update(request, object_id):
    if request.method == 'POST':
        f = forms.bsdUserToGroupForm(object_id, request.POST)
        if f.is_valid():
            f.save()
            return JsonResponse(message=_("Groups successfully updated."))
    else:
        f = forms.bsdUserToGroupForm(userid=object_id)
    return render(request, 'account/bsdgroup2user_form.html', {
        'url': reverse('account_bsduser_groups', kwargs={'object_id':object_id}),
        'form' : f,
    })
Exemplo n.º 17
0
def lagg_add(request):

    lagg = forms.LAGGInterfaceForm()
    if request.method == 'POST':
        lagg = forms.LAGGInterfaceForm(request.POST)
        if lagg.is_valid():
            _lagg_performadd(lagg)
            return JsonResponse(message=_("LAGG successfully added"))

    return render(request, 'network/lagg_add.html', {
        'form': lagg,
    })
Exemplo n.º 18
0
def zpool_disk_replace(request, vname, label):

    disk = notifier().label_to_disk(label)
    volume = models.Volume.objects.get(vol_name=vname)
    if request.method == "POST":
        form = forms.ZFSDiskReplacementForm(request.POST, disk=disk)
        if form.is_valid():
            if form.done(volume, disk, label):
                return JsonResponse(
                    message=_("Disk replacement has been initiated."))
            else:
                return JsonResponse(error=True,
                                    message=_("An error occurred."))

    else:
        form = forms.ZFSDiskReplacementForm(disk=disk)
    return render(request, 'storage/zpool_disk_replace.html', {
        'form': form,
        'vname': vname,
        'label': label,
        'disk': disk,
    })
Exemplo n.º 19
0
def disk_detach(request, vname, label):

    volume = models.Volume.objects.get(vol_name=vname)

    if request.method == "POST":
        notifier().zfs_detach_disk(volume, label)
        return JsonResponse(
            message=_("Disk detach has been successfully done."))

    return render(request, 'storage/disk_detach.html', {
        'vname': vname,
        'label': label,
    })
Exemplo n.º 20
0
def zpool_scrub(request, vid):
    volume = models.Volume.objects.get(pk=vid)
    pool = notifier().zpool_parse(volume.vol_name)
    if request.method == "POST":
        if request.POST.get("scrub") == 'IN_PROGRESS':
            notifier().zfs_scrub(str(volume.vol_name), stop=True)
        else:
            notifier().zfs_scrub(str(volume.vol_name))
        return JsonResponse(message=_("The scrub process has begun"))

    return render(request, 'storage/scrub_confirm.html', {
        'volume': volume,
        'scrub': pool.scrub,
    })
Exemplo n.º 21
0
def zfsvolume_edit(request, object_id):

    mp = models.MountPoint.objects.get(pk=object_id)
    volume_form = forms.ZFSVolume_EditForm(mp=mp)

    if request.method == 'POST':
        volume_form = forms.ZFSVolume_EditForm(request.POST, mp=mp)
        if volume_form.is_valid():
            volume = mp.mp_volume
            volume_name = volume.vol_name
            volume_name = mp.mp_path.replace("/mnt/", "")

            if volume_form.cleaned_data["volume_refquota"] == "0":
                volume_form.cleaned_data["volume_refquota"] = "none"

            error, errors = False, {}
            for attr in (
                    'compression',
                    'atime',
                    'refquota',
                    'refreservation',
            ):
                formfield = 'volume_%s' % attr
                if volume_form.cleaned_data[formfield] == "inherit":
                    success, err = notifier().zfs_inherit_option(
                        volume_name,
                        attr,
                    )
                else:
                    success, err = notifier().zfs_set_option(
                        volume_name,
                        attr,
                        volume_form.cleaned_data[formfield],
                    )
                if not success:
                    error = True
                    errors[formfield] = err

            if not error:
                return JsonResponse(
                    message=_("Native dataset successfully edited."))
            else:
                for field, err in errors.items():
                    volume_form._errors[field] = volume_form.error_class([
                        err,
                    ])
    return render(request, 'storage/volume_edit.html', {
        'mp': mp,
        'form': volume_form
    })
Exemplo n.º 22
0
def zpool_disk_remove(request, vname, label):

    volume = models.Volume.objects.get(vol_name=vname)
    disk = notifier().label_to_disk(label)

    if request.method == "POST":
        notifier().zfs_remove_disk(volume, label)
        return JsonResponse(message=_("Disk has been removed."))

    return render(request, 'storage/disk_remove.html', {
        'vname': vname,
        'label': label,
        'disk': disk,
    })
Exemplo n.º 23
0
def mp_permission(request, path):
    path = '/' + path
    if request.method == 'POST':
        form = forms.MountPointAccessForm(request.POST)
        if form.is_valid():
            form.commit(path=path)
            return JsonResponse(
                message=_("Mount Point permissions successfully updated."))
    else:
        form = forms.MountPointAccessForm(initial={'path': path})
    return render(request, 'storage/permission.html', {
        'path': path,
        'form': form,
    })
Exemplo n.º 24
0
def dataset_edit(request, dataset_name):
    if request.method == 'POST':
        dataset_form = forms.ZFSDataset_EditForm(request.POST, fs=dataset_name)
        if dataset_form.is_valid():
            if dataset_form.cleaned_data["dataset_quota"] == "0":
                dataset_form.cleaned_data["dataset_quota"] = "none"
            if dataset_form.cleaned_data["dataset_refquota"] == "0":
                dataset_form.cleaned_data["dataset_refquota"] = "none"

            error = False
            errors = {}

            for attr in (
                    'compression',
                    'atime',
                    'reservation',
                    'refreservation',
                    'quota',
                    'refquota',
            ):
                formfield = 'dataset_%s' % attr
                if dataset_form.cleaned_data[formfield] == "inherit":
                    success, err = notifier().zfs_inherit_option(
                        dataset_name,
                        attr,
                    )
                else:
                    success, err = notifier().zfs_set_option(
                        dataset_name,
                        attr,
                        dataset_form.cleaned_data[formfield],
                    )
                error |= not success
                if not success:
                    errors[formfield] = err

            if not error:
                return JsonResponse(message=_("Dataset successfully edited."))
            else:
                for field, err in errors.items():
                    dataset_form._errors[field] = dataset_form.error_class([
                        err,
                    ])
    else:
        dataset_form = forms.ZFSDataset_EditForm(fs=dataset_name)
    return render(request, 'storage/dataset_edit.html', {
        'dataset_name': dataset_name,
        'form': dataset_form
    })
Exemplo n.º 25
0
def periodicsnap(request):

    if request.method == "POST":

        form = forms.PeriodicSnapForm(request.POST)
        if form.is_valid():
            form.save()

            return JsonResponse(message=_("Snapshot successfully added."))
    else:
        form = forms.PeriodicSnapForm()
    return render(request, 'storage/periodicsnap.html', {
        'form': form,
        'extra_js': models.Task._admin.extra_js,
    })
Exemplo n.º 26
0
def user_change(request):

    extra_context = {}
    changeform = forms.UserChangeForm(instance=request.user)

    if request.method == 'POST':
        changeform = forms.UserChangeForm(instance=request.user, data=request.POST)
        if changeform.is_valid():
            changeform.save()
            return JsonResponse(message=_("Admin user successfully updated."))

    extra_context.update({
        'form' : changeform,
        'inline': True,
        })
    return render(request, 'account/changeform.html', extra_context)
Exemplo n.º 27
0
def plugin_edit(request, plugin_id):
    plugin = models.Plugins.objects.filter(id=plugin_id)[0]

    if request.method == 'POST':
        plugins_form = forms.PluginsForm(request.POST, instance=plugin)
        if plugins_form.is_valid():
            plugins_form.save()
            return JsonResponse(message=_("Plugin successfully updated."))
        else:
            plugin = None

    else:
        plugins_form = forms.PluginsForm(instance=plugin)

    return render(request, 'plugins/plugin_edit.html', {
        'plugin_id': plugin_id,
        'form': plugins_form
    })
Exemplo n.º 28
0
def volautoimport(request):

    if request.method == "POST":

        form = forms.VolumeAutoImportForm(request.POST)
        if form.is_valid():
            form.done(request)
            return JsonResponse(message=_("Volume successfully added."))
        else:

            if 'volume_disks' in request.POST:
                disks = request.POST.getlist('volume_disks')
            else:
                disks = None
    else:
        form = forms.VolumeAutoImportForm()
        disks = []
    return render(request, 'storage/autoimport.html', {
        'form': form,
        'disks': disks
    })
Exemplo n.º 29
0
def plugin_update(request, plugin_id):
    if request.method == "POST":
        pj = PluginsJail.objects.order_by("-id")[0]
        notifier().change_upload_location(pj.plugins_path)
        form = forms.PBIUpdateForm(request.POST, request.FILES)
        if form.is_valid():
            form.done()
            return JsonResponse(message=_('Plugin successfully updated'),
                                events=['reloadHttpd()'],
                                enclosed=True)
        else:
            resp = render(request, "plugins/plugin_update.html", {
                'form': form,
            })
            resp.content = ("<html><body><textarea>" + resp.content +
                            "</textarea></boby></html>")
            return resp
    else:
        form = forms.PBIUpdateForm()

    return render(request, "plugins/plugin_update.html", {
        'form': form,
    })
Exemplo n.º 30
0
def dataset_create(request, fs):
    defaults = {'dataset_compression': 'inherit', 'dataset_atime': 'inherit'}
    if request.method == 'POST':
        dataset_form = forms.ZFSDataset_CreateForm(request.POST, fs=fs)
        if dataset_form.is_valid():
            props = {}
            cleaned_data = dataset_form.cleaned_data
            dataset_name = "%s/%s" % (fs, cleaned_data.get('dataset_name'))
            dataset_compression = cleaned_data.get('dataset_compression')
            props['compression'] = dataset_compression.__str__()
            dataset_atime = cleaned_data.get('dataset_atime')
            props['atime'] = dataset_atime.__str__()
            refquota = cleaned_data.get('dataset_refquota')
            if refquota != '0':
                props['refquota'] = refquota.__str__()
            quota = cleaned_data.get('dataset_quota')
            if quota != '0':
                props['quota'] = quota.__str__()
            refreservation = cleaned_data.get('dataset_refreserv')
            if refreservation != '0':
                props['refreservation'] = refreservation.__str__()
            refreservation = cleaned_data.get('dataset_reserv')
            if refreservation != '0':
                props['refreservation'] = refreservation.__str__()
            errno, errmsg = notifier().create_zfs_dataset(
                path=str(dataset_name), props=props)
            if errno == 0:
                return JsonResponse(message=_("Dataset successfully added."))
            else:
                dataset_form.set_error(errmsg)
    else:
        dataset_form = forms.ZFSDataset_CreateForm(initial=defaults, fs=fs)
    return render(request, 'storage/datasets.html', {
        'form': dataset_form,
        'fs': fs,
    })