Exemple #1
0
 def save(self):
     super(iSCSITargetGlobalConfigurationForm, self).save()
     started = notifier().reload("iscsitarget")
     if started is False and models.services.objects.get(
             srv_service='iscsitarget').srv_enable:
         raise ServiceFailed("iscsitarget",
                             _("The iSCSI service failed to reload."))
Exemple #2
0
 def save(self):
     super(LDAPForm, self).save()
     started = notifier().restart("ldap")
     if started is False and models.services.objects.get(
             srv_service='ldap').srv_enable:
         raise ServiceFailed("ldap",
                             _("The ldap service failed to reload."))
Exemple #3
0
 def save(self):
     super(DynamicDNSForm, self).save()
     started = notifier().restart("dynamicdns")
     if started is False and models.services.objects.get(
             srv_service='dynamicdns').srv_enable:
         raise ServiceFailed("dynamicdns",
                             _("The DynamicDNS service failed to reload."))
Exemple #4
0
 def save(self):
     super(SMARTForm, self).save()
     started = notifier().restart("smartd")
     if started is False and models.services.objects.get(
             srv_service='smartd').srv_enable:
         raise ServiceFailed("smartd",
                             _("The S.M.A.R.T. service failed to reload."))
Exemple #5
0
 def save(self):
     super(RsyncModForm, self).save()
     started = notifier().reload("rsync")
     if started is False and models.services.objects.get(
             srv_service='rsync').srv_enable:
         raise ServiceFailed("rsync",
                             _("The Rsync service failed to reload."))
Exemple #6
0
 def save(self):
     super(CIFSForm, self).save()
     started = notifier().reload("cifs")
     if started is False and models.services.objects.get(
             srv_service='cifs').srv_enable:
         raise ServiceFailed("cifs",
                             _("The CIFS service failed to reload."))
Exemple #7
0
 def save(self):
     super(ActiveDirectoryForm, self).save()
     started = notifier().start("activedirectory")
     if started is False and models.services.objects.get(
             srv_service='activedirectory').srv_enable:
         raise ServiceFailed(
             "activedirectory",
             _("The activedirectory service failed to reload."))
Exemple #8
0
 def save(self):
     super(PluginsJailForm, self).save()
     started = notifier().restart("plugins_jail")
     if started is False and models.services.objects.get(
             srv_service='plugins').srv_enable:
         raise ServiceFailed(
             "plugins_jail",
             _("The Plugins Jail service failed to reload."))
Exemple #9
0
 def save(self, *args, **kwargs):
     obj = super(DiskFormPartial, self).save(*args, **kwargs)
     if obj.disk_togglesmart != self._original_smart_en or \
         obj.disk_smartoptions != self._original_smart_opts:
         started = notifier().restart("smartd")
         if started is False and \
           services.objects.get(srv_service='smartd').srv_enable:
             raise ServiceFailed("smartd",
                                 _("The SMART service failed to restart."))
     return obj
Exemple #10
0
 def save(self, commit=True):
     oAuthCredential = super(iSCSITargetAuthCredentialForm,
                             self).save(commit=False)
     oAuthCredential.iscsi_target_auth_secret = self.cleaned_data[
         "iscsi_target_auth_secret1"]
     oAuthCredential.iscsi_target_auth_peersecret = self.cleaned_data[
         "iscsi_target_auth_peersecret1"]
     if commit:
         oAuthCredential.save()
     started = notifier().reload("iscsitarget")
     if started is False and models.services.objects.get(
             srv_service='iscsitarget').srv_enable:
         raise ServiceFailed("iscsitarget",
                             _("The iSCSI service failed to reload."))
     return oAuthCredential
Exemple #11
0
 def save(self, commit=True):
     oExtent = super(iSCSITargetDeviceExtentForm, self).save(commit=False)
     if commit:
         # label it only if it is a real disk
         if self.cleaned_data["iscsi_extent_disk"].startswith("zvol"):
             oExtent.iscsi_target_extent_path = self.cleaned_data[
                 "iscsi_extent_disk"]
             oExtent.iscsi_target_extent_type = 'ZVOL'
         elif self.cleaned_data["iscsi_extent_disk"].startswith(
                 "multipath"):
             notifier().unlabel_disk(
                 str(self.cleaned_data["iscsi_extent_disk"]))
             notifier().label_disk(
                 "extent_%s" % self.cleaned_data["iscsi_extent_disk"],
                 self.cleaned_data["iscsi_extent_disk"])
             mp_name = self.cleaned_data["iscsi_extent_disk"].split("/")[-1]
             diskobj = models.Disk.objects.get(disk_multipath_name=mp_name)
             oExtent.iscsi_target_extent_type = 'Disk'
             oExtent.iscsi_target_extent_path = str(diskobj.id)
         else:
             notifier().unlabel_disk(
                 str(self.cleaned_data["iscsi_extent_disk"]))
             diskobj = models.Disk.objects.get(
                 disk_name=self.cleaned_data["iscsi_extent_disk"])
             if diskobj.disk_identifier.startswith("{devicename}") or \
                     diskobj.disk_identifier.startswith("{uuid}"):
                 notifier().label_disk(
                     "extent_%s" % self.cleaned_data["iscsi_extent_disk"],
                     self.cleaned_data["iscsi_extent_disk"])
                 notifier().sync_disk(
                     self.cleaned_data["iscsi_extent_disk"])
             oExtent.iscsi_target_extent_type = 'Disk'
             oExtent.iscsi_target_extent_path = str(diskobj.id)
         oExtent.iscsi_target_extent_filesize = 0
         oExtent.save()
     started = notifier().reload("iscsitarget")
     if started is False and models.services.objects.get(
             srv_service='iscsitarget').srv_enable:
         raise ServiceFailed("iscsitarget",
                             _("The iSCSI service failed to reload."))
     return oExtent
Exemple #12
0
class iSCSITargetFileExtentForm(ModelForm):
    class Meta:
        model = models.iSCSITargetExtent
        exclude = ('iscsi_target_extent_type')
        widgets = {
            'iscsi_target_extent_path': DirectoryBrowser(dirsonly=False),
        }

    def clean_iscsi_target_extent_path(self):
        path = self.cleaned_data["iscsi_target_extent_path"]
        if (os.path.exists(path)
                and not os.path.isfile(path)) or path[-1] == '/':
            raise forms.ValidationError(
                _("You need to specify a filepath, not a directory."))
        valid = False
        for mp in MountPoint.objects.all():
            if path == mp.mp_path:
                raise forms.ValidationError(
                    _("You need to specify a file inside your volume/dataset.")
                )
            if path.startswith(mp.mp_path + '/'):
                valid = True
        if not valid:
            raise forms.ValidationError(
                _("Your path to the extent must reside inside a volume/dataset mount point."
                  ))
        return path

    def clean_iscsi_target_extent_filesize(self):
        size = self.cleaned_data['iscsi_target_extent_filesize']
        try:
            int(size)
        except ValueError:
            suffixes = ['KB', 'MB', 'GB', 'TB']
            for x in suffixes:
                if size.upper().endswith(x):
                    m = re.match(r'(\d+)\s*?(%s)' % x, size)
                    if m:
                        return "%s%s" % (m.group(1), m.group(2))
            raise forms.ValidationError(
                _("This value can be a size in bytes, or can be postfixed with KB, MB, GB, TB"
                  ))
        return size

    def clean(self):
        cdata = self.cleaned_data
        path = cdata.get("iscsi_target_extent_path")
        if cdata.get("iscsi_target_extent_filesize") == "0" and path and \
            (not os.path.exists(path) or (os.path.exists(path) and not os.path.isfile(path))):
            self._errors['iscsi_target_extent_path'] = self.error_class([
                _("The file must exist if the extent size is set to auto (0)")
            ])
            del cdata['iscsi_target_extent_path']
        return cdata

    def save(self, commit=True):
        oExtent = super(iSCSITargetFileExtentForm, self).save(commit=False)
        oExtent.iscsi_target_extent_type = 'File'
        if commit:
            oExtent.save()
        path = self.cleaned_data["iscsi_target_extent_path"]
        dirs = "/".join(path.split("/")[:-1])
        if not os.path.exists(dirs):
            try:
                os.makedirs(dirs)
            except Exception, e:
                pass
        started = notifier().reload("iscsitarget")
        if started is False and models.services.objects.get(
                srv_service='iscsitarget').srv_enable:
            raise ServiceFailed("iscsitarget",
                                _("The iSCSI service failed to reload."))
        return oExtent
Exemple #13
0
 def save(self):
     super(SSHForm, self).save()
     started = notifier().reload("ssh")
     if started is False and models.services.objects.get(
             srv_service='ssh').srv_enable:
         raise ServiceFailed("ssh", _("The SSH service failed to reload."))
Exemple #14
0
 def save(self):
     super(FTPForm, self).save()
     started = notifier().reload("ftp")
     if started is False and models.services.objects.get(
             srv_service='ftp').srv_enable:
         raise ServiceFailed("ftp", _("The ftp service failed to start."))