1 # Copyright (C) 2010 Oregon State University et al.
2 # Copyright (C) 2010 Greek Research and Technology Network
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 from django
import forms
20 from django
.forms
import ValidationError
21 from django
.utils
.translation
import ugettext
as _
23 from ganeti_web
import constants
24 from ganeti_web
.utilities
import cluster_default_info
27 class RoleForm(forms
.Form
):
29 Form for editing roles
31 role
= forms
.ChoiceField(initial
='',
32 choices
=constants
.ROLE_CHOICES
,
34 force
= forms
.BooleanField(initial
=False, required
=False)
37 class MigrateForm(forms
.Form
):
38 """ Form used for migrating primary Virtual Machines off a Node """
39 mode
= forms
.ChoiceField(choices
=constants
.MODE_CHOICES
)
42 class EvacuateForm(forms
.Form
):
43 EMPTY_FIELD
= constants
.EMPTY_CHOICE_FIELD
45 iallocator
= forms
.BooleanField(initial
=False, required
=False,
46 label
='Automatic Allocation')
47 iallocator_hostname
= forms
.CharField(initial
='', required
=False,
48 widget
=forms
.HiddenInput())
49 node
= forms
.ChoiceField(initial
='', choices
=[EMPTY_FIELD
], required
=False)
51 def __init__(self
, cluster
, node
, *args
, **kwargs
):
52 super(EvacuateForm
, self
).__init
__(*args
, **kwargs
)
54 node_list
= [str(h
) for h
in cluster
.nodes
.exclude(pk
=node
.pk
)
55 .values_list('hostname', flat
=True)]
56 nodes
= zip(node_list
, node_list
)
57 nodes
.insert(0, self
.EMPTY_FIELD
)
58 self
.fields
['node'].choices
= nodes
60 defaults
= cluster_default_info(cluster
)
61 if defaults
['iallocator'] != '':
62 self
.fields
['iallocator'].initial
= True
63 self
.fields
['iallocator_hostname'].initial
= defaults
['iallocator']
66 data
= self
.cleaned_data
68 iallocator
= data
['iallocator']
69 node
= data
['node'] if 'node' in data
else None
74 data
['iallocator_hostname'] = None
76 raise ValidationError(_('Must choose automatic allocation '
77 'or a specific node'))