| 5 | |
| 6 | |
| 7 | class ComputeAddTcpForm(forms.Form): |
| 8 | name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, |
| 9 | max_length=20) |
| 10 | hostname = forms.CharField(error_messages={'required': _('No IP / Domain name has been entered')}, |
| 11 | max_length=100) |
| 12 | login = forms.CharField(error_messages={'required': _('No login has been entered')}, |
| 13 | max_length=100) |
| 14 | password = forms.CharField(error_messages={'required': _('No password has been entered')}, |
| 15 | max_length=100) |
| 16 | |
| 17 | def clean_name(self): |
| 18 | name = self.cleaned_data['name'] |
| 19 | have_symbol = re.match('[^a-zA-Z0-9._-]+', name) |
| 20 | if have_symbol: |
| 21 | raise forms.ValidationError(_('The host name must not contain any special characters')) |
| 22 | elif len(name) > 20: |
| 23 | raise forms.ValidationError(_('The host name must not exceed 20 characters')) |
| 24 | try: |
| 25 | Compute.objects.get(name=name) |
| 26 | except Compute.DoesNotExist: |
| 27 | return name |
| 28 | raise forms.ValidationError(_('This host is already connected')) |
| 29 | |
| 30 | def clean_hostname(self): |
| 31 | hostname = self.cleaned_data['hostname'] |
| 32 | have_symbol = re.match('[^a-z0-9.-]+', hostname) |
| 33 | wrong_ip = re.match('^0.|^255.', hostname) |
| 34 | if have_symbol: |
| 35 | raise forms.ValidationError(_('Hostname must contain only numbers, or the domain name separated by "."')) |
| 36 | elif wrong_ip: |
| 37 | raise forms.ValidationError(_('Wrong IP address')) |
| 38 | try: |
| 39 | Compute.objects.get(hostname=hostname) |
| 40 | except Compute.DoesNotExist: |
| 41 | return hostname |
| 42 | raise forms.ValidationError(_('This host is already connected')) |
| 43 | |
| 44 | |
| 45 | class ComputeAddSshForm(forms.Form): |