class EditShareForm(forms.Form): share_id = forms.IntegerField(widget=forms.HiddenInput) name = forms.CharField() path = forms.CharField(required=False) comment = forms.CharField(required=False) browseable = forms.BooleanField(required=False) read_only = forms.BooleanField(required=False) ch = [('all', 'All hosts'), ('restricted', 'Specified hosts')] hosts_allow_choice = forms.ChoiceField(choices=ch) ch = [('none', 'None'), ('restricted', 'Specified hosts')] hosts_deny_choice = forms.ChoiceField(choices=ch) hosts_allow = common_forms.MultipleServerField(required=False) hosts_deny = common_forms.MultipleServerField(required=False) def clean(self): cd = super(EditShareForm, self).clean() if cd['hosts_allow_choice'] == 'restricted' and ( ('hosts_allow' not in cd) or (not cd['hosts_allow'])): self._errors['hosts_allow'] = self.error_class( ["Please specify a valid set of IP addresses or hostnames"]) if cd['hosts_deny_choice'] == 'restricted' and ( ('hosts_deny' not in cd) or (not cd['hosts_deny'])): self._errors["hosts_deny"] = self.error_class( ["Please specify a valid set of IP addresses or hostnames"]) return cd '''
class DNSNameServersForm(forms.Form): nameservers = common_forms.MultipleServerField() def clean(self): cd = super(DNSNameServersForm, self).clean() nameservers = cd.get("nameservers") if nameservers is not None: if nameservers and ',' in nameservers: slist = nameservers.split(',') else: slist = nameservers.split(' ') for server in slist: valid, err = networking.validate_ip(server) if err: self._errors["nameservers"] = self.error_class([ "Error validating DNS server IP address %s : %s" % (server, err) ]) break elif not valid: self._errors["nameservers"] = self.error_class( ["Invalid DNS server IP address : %s" % server]) break return cd
class CreateShareForm(folder_management_forms.DirForm): share_id = forms.IntegerField(widget=forms.HiddenInput, required=False) name = forms.CharField() comment = forms.CharField(required=False) browseable = forms.BooleanField(required=False, initial=True) read_only = forms.BooleanField(required=False) new_folder = forms.CharField(required=False) ch = [('all', 'All hosts'), ('restricted', 'Specified hosts')] hosts_allow_choice = forms.ChoiceField(choices=ch) ch = [('none', 'None'), ('restricted', 'Specified hosts')] hosts_deny_choice = forms.ChoiceField(choices=ch) hosts_allow = common_forms.MultipleServerField(required=False) hosts_deny = common_forms.MultipleServerField(required=False) def __init__(self, *args, **kwargs): if kwargs: dataset_list = kwargs.pop("dataset_list") super(CreateShareForm, self).__init__(*args, **kwargs) ch = [] if dataset_list: for ds in dataset_list: tup = (ds[0], ds[1]) ch.append(tup) self.fields['dataset'] = forms.ChoiceField(widget=forms.Select, choices=ch) def clean(self): cd = super(CreateShareForm, self).clean() if cd['hosts_allow_choice'] == 'restricted' and ( ('hosts_allow' not in cd) or (not cd['hosts_allow'])): self._errors['hosts_allow'] = self.error_class( ["Please specify a valid set of IP addresses or hostnames"]) if cd['hosts_deny_choice'] == 'restricted' and ( ('hosts_deny' not in cd) or (not cd['hosts_deny'])): self._errors["hosts_deny"] = self.error_class( ["Please specify a valid set of IP addresses or hostnames"]) return cd
class InitiatorForm(forms.Form): initiators = common_forms.MultipleServerField() auth_network = forms.CharField() comment = forms.CharField(required=False) def clean(self): cd = super(InitiatorForm, self).clean() if "auth_network" not in cd: return cd auth_network = cd["auth_network"] if cd["initiators"].lower() == 'all': cd["initiators"] = 'ALL' if cd["auth_network"].lower() == 'all': cd["auth_network"] = 'ALL' else: slash_index = auth_network.find('/') if slash_index == -1: self._errors["auth_network"] = self.error_class( ["Please specify a CIDR network mask"]) try: network_mask = int(auth_network[slash_index + 1:]) except Exception, e: del cd["auth_network"] self._errors["auth_network"] = self.error_class( ["Please specify a valid CIDR network mask"]) network_mask = None if network_mask: if network_mask < 1 or network_mask > 31: del cd["auth_network"] self._errors["auth_network"] = self.error_class( ["CIDR network mask should be between 1 and 31"]) ip_addr = auth_network[:slash_index] valid, err = networking.validate_ip(ip_addr) if not valid: del cd["auth_network"] self._errors["auth_network"] = self.error_class( ["Please specify a valid IP address"]) return cd