1 # Copyright (C) 2010 Oregon State University et al.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 from django
.forms
import Form
, CharField
, ModelChoiceField
, ValidationError
19 from django
.utils
.translation
import ugettext_lazy
as _
21 from ganeti_web
.models
import ClusterUser
24 class VirtualMachineTemplateCopyForm(Form
):
26 Form used to when copying a VirtualMachineTemplate
28 template_name
= CharField(label
=_('Template Name'), max_length
=255)
29 description
= CharField(label
=_('Description'), max_length
=255,
33 class VMInstanceFromTemplate(Form
):
34 owner
= ModelChoiceField(label
=_('Owner'),
35 queryset
=ClusterUser
.objects
.all(),
37 hostname
= CharField(label
=_('Instance Name'), max_length
=255)
39 def clean_hostname(self
):
40 hostname
= self
.cleaned_data
.get('hostname')
42 # Spaces in hostname will always break things.
44 self
.errors
["hostname"] = self
.error_class(
45 ["Hostnames cannot contain spaces."])
49 class TemplateFromVMInstance(Form
):
50 template_name
= CharField(label
=_("Template Name"), max_length
=255)
52 def clean_template_name(self
):
53 name
= self
.cleaned_data
['template_name']
54 if name
.strip(' ') == '':
55 raise ValidationError(_("Name cannot consist of spaces."))