MCPcopy
hub / github.com/retspen/webvirtcloud / ComputeAddSshForm

Class ComputeAddSshForm

computes/forms.py:45–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class ComputeAddSshForm(forms.Form):
46 name = forms.CharField(error_messages={'required': _('No hostname has been entered')},
47 max_length=20)
48 hostname = forms.CharField(error_messages={'required': _('No IP / Domain name has been entered')},
49 max_length=100)
50 login = forms.CharField(error_messages={'required': _('No login has been entered')},
51 max_length=20)
52
53 def clean_name(self):
54 name = self.cleaned_data['name']
55 have_symbol = re.match('[^a-zA-Z0-9._-]+', name)
56 if have_symbol:
57 raise forms.ValidationError(_('The name of the host must not contain any special characters'))
58 elif len(name) > 20:
59 raise forms.ValidationError(_('The name of the host must not exceed 20 characters'))
60 try:
61 Compute.objects.get(name=name)
62 except Compute.DoesNotExist:
63 return name
64 raise forms.ValidationError(_('This host is already connected'))
65
66 def clean_hostname(self):
67 hostname = self.cleaned_data['hostname']
68 have_symbol = re.match('[^a-zA-Z0-9._-]+', hostname)
69 wrong_ip = re.match('^0.|^255.', hostname)
70 if have_symbol:
71 raise forms.ValidationError(_('Hostname must contain only numbers, or the domain name separated by "."'))
72 elif wrong_ip:
73 raise forms.ValidationError(_('Wrong IP address'))
74 try:
75 Compute.objects.get(hostname=hostname)
76 except Compute.DoesNotExist:
77 return hostname
78 raise forms.ValidationError(_('This host is already connected'))
79
80
81class ComputeAddTlsForm(forms.Form):

Callers 1

computesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected