~ubuntu-branches/ubuntu/trusty/horizon/trusty

« back to all changes in this revision

Viewing changes to horizon/dashboards/nova/access_and_security/security_groups/forms.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-03-09 11:50:22 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120309115022-ymiww5i58rbg97my
Tags: 2012.1~rc1~20120308.1479-0ubuntu1
* New upstream version.
* debian/rules: Fix symlink when installing horizon.
  (LP: #947118)
* debian/control: Add python-django-nose as a dep. (LP: #944235)
* debian/control: Fix broken depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from horizon import exceptions
32
32
from horizon import forms
33
33
from horizon.utils.validators import validate_ipv4_cidr
 
34
from horizon.utils.validators import validate_port_range
34
35
 
35
36
 
36
37
LOG = logging.getLogger(__name__)
68
69
                                               "in the range (-1: 255)"),
69
70
                                   widget=forms.TextInput(
70
71
                                          attrs={'data': _('From port'),
71
 
                                                 'data-icmp': _('Type')}))
 
72
                                                 'data-icmp': _('Type')}),
 
73
                                   validators=[validate_port_range])
72
74
    to_port = forms.IntegerField(label=_("To port"),
73
75
                                 help_text=_("TCP/UDP: Enter integer value "
74
76
                                             "between 1 and 65535. ICMP: "
76
78
                                             "in the range (-1: 255)"),
77
79
                                 widget=forms.TextInput(
78
80
                                        attrs={'data': _('To port'),
79
 
                                               'data-icmp': _('Code')}))
 
81
                                               'data-icmp': _('Code')}),
 
82
                                 validators=[validate_port_range])
80
83
    cidr = forms.CharField(label=_("CIDR"),
81
84
                           help_text=_("Classless Inter-Domain Routing "
82
85
                                       "(i.e. 192.168.0.0/24"),
89
92
 
90
93
    def clean(self):
91
94
        cleaned_data = super(AddRule, self).clean()
92
 
        if cleaned_data["to_port"] < cleaned_data["from_port"]:
 
95
        from_port = cleaned_data.get("from_port", None)
 
96
        to_port = cleaned_data.get("to_port", None)
 
97
        cidr = cleaned_data.get("cidr", None)
 
98
 
 
99
        if from_port == None:
 
100
            msg = _('The "from" port number is invalid.')
 
101
            raise ValidationError(msg)
 
102
        if to_port == None:
 
103
            msg = _('The "to" port number is invalid.')
 
104
            raise ValidationError(msg)
 
105
        if to_port < from_port:
93
106
            msg = _('The "to" port number must be greater than or equal to '
94
107
                    'the "from" port number.')
95
108
            raise ValidationError(msg)
 
109
 
 
110
        if cidr == None:
 
111
            msg = _('The "CIDR" is invalid')
 
112
            raise ValidationError(msg)
 
113
 
96
114
        return cleaned_data
97
115
 
98
116
    def handle(self, request, data):