| 117 | |
| 118 | |
| 119 | class ComputeEditHostForm(forms.Form): |
| 120 | host_id = forms.CharField() |
| 121 | name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, |
| 122 | max_length=20) |
| 123 | hostname = forms.CharField(error_messages={'required': _('No IP / Domain name has been entered')}, |
| 124 | max_length=100) |
| 125 | login = forms.CharField(error_messages={'required': _('No login has been entered')}, |
| 126 | max_length=100) |
| 127 | password = forms.CharField(max_length=100) |
| 128 | |
| 129 | def clean_name(self): |
| 130 | name = self.cleaned_data['name'] |
| 131 | have_symbol = re.match('[^a-zA-Z0-9._-]+', name) |
| 132 | if have_symbol: |
| 133 | raise forms.ValidationError(_('The name of the host must not contain any special characters')) |
| 134 | elif len(name) > 20: |
| 135 | raise forms.ValidationError(_('The name of the host must not exceed 20 characters')) |
| 136 | return name |
| 137 | |
| 138 | def clean_hostname(self): |
| 139 | hostname = self.cleaned_data['hostname'] |
| 140 | have_symbol = re.match('[^a-zA-Z0-9._-]+', hostname) |
| 141 | wrong_ip = re.match('^0.|^255.', hostname) |
| 142 | if have_symbol: |
| 143 | raise forms.ValidationError(_('Hostname must contain only numbers, or the domain name separated by "."')) |
| 144 | elif wrong_ip: |
| 145 | raise forms.ValidationError(_('Wrong IP address')) |
| 146 | return hostname |
| 147 | |
| 148 | |
| 149 | class ComputeAddSocketForm(forms.Form): |