cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
node.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.wi.forms.node
22 #
23 # @author Krzysztof Danielowski
24 # @author Piotr W√≥jcik
25 # @date 17.10.2011
26 #
27 
28 from django import forms
29 from django.utils.translation import ugettext_lazy as _
30 
31 from wi.utils import parsing
32 from wi.utils.forms import attrs_dict, BetterForm
33 
34 
35 ##
36 #
37 # Class for <b>mounting node</b> form.
38 #
39 class MountNodeForm(forms.Form):
40  def __init__(self, *args, **kwargs):
41  rest_data = kwargs.pop('rest_data')
42  super(MountNodeForm, self).__init__(*args, **kwargs)
43  self.fields['node_id'] = forms.ChoiceField(choices=parsing.parse_node_names(rest_data),
44  initial=0,
45  label=_("Node"))
46 
47 
48 ##
49 #
50 # Class for <b>creating a node</b> form.
51 #
52 class NodeForm(BetterForm):
53 
54  ##
55  #
56  # Fieldset names definition.
57  #
58  class Meta:
59  fieldsets = (('libvirt', {'fields': ('address',), 'legend': _('Libvirt configuration')}),
60  ('resources', {'fields': ('hdd_total', 'cpu_total', 'memory_total'), 'legend': _('Node capacity')}),)
61 
62  def __init__(self):
63  pass
64 
65  def __init__(self, *args, **kwargs):
66  super(NodeForm, self).__init__(*args, **kwargs)
67  self.fields['address'] = forms.CharField(widget=forms.TextInput(attrs=dict(attrs_dict, maxlength=45)),
68  label=_('Node address'),
69  help_text=_('Node address - IP or DNS name'))
70  self.fields['hdd_total'] = forms.IntegerField(min_value=1,
71  label=_('HDD Total [MB]'),
72  help_text=_(' - total amount of storage for virtual machine images'))
73  self.fields['cpu_total'] = forms.IntegerField(min_value=1,
74  label=_('Cpu Total'),
75  help_text=_(' - total amount of CPU\'s for libvirt'))
76  self.fields['memory_total'] = forms.IntegerField(min_value=1,
77  label=_('Memory Total [MB]'),
78  help_text=_(' - total amount of RAM'))
79 
80 
81 ##
82 #
83 # Class for <b>editing a node</b> form.
84 #
85 class EditNodeForm(NodeForm, BetterForm):
86 
87  ##
88  #
89  # Fieldset names definition.
90  #
91  class Meta:
92  fieldsets = (('libvirt', {'fields': ('address', 'comment'), 'legend': _('Libvirt configuration')}),
93  ('resources', {'fields': ('hdd_total', 'cpu_total', 'memory_total'), 'legend': _('Node capacity')}),)
94 
95  def __init__(self):
96  pass
97 
98  def __init__(self, *args, **kwargs):
99  super(EditNodeForm, self).__init__(*args, **kwargs)
100  self.fields['comment'] = forms.CharField(required=False,
101  widget=forms.Textarea(attrs=dict(attrs_dict,
102  maxlength=256,
103  rows=4,
104  cols=20)),
105  label=_('Comment'))
106