| 79 | |
| 80 | |
| 81 | class ComputeAddTlsForm(forms.Form): |
| 82 | name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, |
| 83 | max_length=20) |
| 84 | hostname = forms.CharField(error_messages={'required': _('No IP / Domain name has been entered')}, |
| 85 | max_length=100) |
| 86 | login = forms.CharField(error_messages={'required': _('No login has been entered')}, |
| 87 | max_length=100) |
| 88 | password = forms.CharField(error_messages={'required': _('No password has been entered')}, |
| 89 | max_length=100) |
| 90 | |
| 91 | def clean_name(self): |
| 92 | name = self.cleaned_data['name'] |
| 93 | have_symbol = re.match('[^a-zA-Z0-9._-]+', name) |
| 94 | if have_symbol: |
| 95 | raise forms.ValidationError(_('The host name must not contain any special characters')) |
| 96 | elif len(name) > 20: |
| 97 | raise forms.ValidationError(_('The host name must not exceed 20 characters')) |
| 98 | try: |
| 99 | Compute.objects.get(name=name) |
| 100 | except Compute.DoesNotExist: |
| 101 | return name |
| 102 | raise forms.ValidationError(_('This host is already connected')) |
| 103 | |
| 104 | def clean_hostname(self): |
| 105 | hostname = self.cleaned_data['hostname'] |
| 106 | have_symbol = re.match('[^a-z0-9.-]+', hostname) |
| 107 | wrong_ip = re.match('^0.|^255.', hostname) |
| 108 | if have_symbol: |
| 109 | raise forms.ValidationError(_('Hostname must contain only numbers, or the domain name separated by "."')) |
| 110 | elif wrong_ip: |
| 111 | raise forms.ValidationError(_('Wrong IP address')) |
| 112 | try: |
| 113 | Compute.objects.get(hostname=hostname) |
| 114 | except Compute.DoesNotExist: |
| 115 | return hostname |
| 116 | raise forms.ValidationError(_('This host is already connected')) |
| 117 | |
| 118 | |
| 119 | class ComputeEditHostForm(forms.Form): |