Beispiel #1
0
    def clean(self):
        cleaned_data = super(PortsAction, self).clean()
        s_protocol = None
        d_protocol = None

        msg = u"This field is required."

        if cleaned_data.get('public_port_alias', None):
            if cleaned_data['public_port_alias'] == 'Custom':
                if cleaned_data['public_protocol'] is None:
                    self._errors['public_protocol'] = self.error_class([msg])
                    del cleaned_data["public_protocol"]
                else:
                    s_protocol = cleaned_data['public_protocol']

                if cleaned_data['public_port'] is None:
                    self._errors['public_port'] = self.error_class(
                        [msg])
                    del cleaned_data["public_port"]
            else:
                port_alias = neutron_extensions_client.portalias_get(
                    self.request, cleaned_data['public_port_alias'])
                cleaned_data['public_protocol'] = port_alias['protocol']
                cleaned_data['public_port'] = port_alias['port']
                s_protocol = port_alias['protocol']

        if cleaned_data.get('private_port_alias', None):
            if cleaned_data['private_port_alias'] == 'Custom':
                if cleaned_data['private_protocol'] is None:
                    self._errors['private_protocol'] = self.error_class(
                        [msg])
                    del cleaned_data["private_protocol"]
                else:
                    d_protocol = cleaned_data["private_protocol"]

                if cleaned_data['private_port'] is None:
                    self._errors['private_port'] = self.error_class(
                        [msg])
                    del cleaned_data["private_port"]
            else:
                port_alias = neutron_extensions_client.portalias_get(
                    self.request, cleaned_data['private_port_alias'])
                cleaned_data['private_protocol'] = port_alias['protocol']
                cleaned_data['private_port'] = port_alias['port']
                d_protocol = port_alias['protocol']

        if s_protocol and d_protocol:
            if s_protocol != d_protocol:
                raise forms.ValidationError(
                    "The source and destination Port Aliases "
                    "must use the same protocol.")

        return cleaned_data
Beispiel #2
0
    def clean(self):
        cleaned_data = super(BaseFirewallRuleForm, self).clean()
        s_protocol = None
        d_protocol = None

        msg = u"This field is required."

        if cleaned_data.get('source_port_alias', None):
            if cleaned_data['source_port_alias'] == 'Custom':
                if cleaned_data['source_protocol'] is None:
                    self._errors['source_protocol'] = self.error_class([msg])
                    del cleaned_data["source_protocol"]
                else:
                    s_protocol = cleaned_data['source_protocol']

                if cleaned_data['source_public_port'] is None:
                    self._errors['source_public_port'] = self.error_class(
                        [msg])
                    del cleaned_data["source_public_port"]
            else:
                port_alias = neutron_extensions_client.portalias_get(
                    self.request, cleaned_data['source_port_alias'])
                cleaned_data['source_protocol'] = port_alias['protocol']
                cleaned_data['source_public_port'] = port_alias['port']
                s_protocol = port_alias['protocol']

        if cleaned_data.get('destination_port_alias', None):
            if cleaned_data['destination_port_alias'] == 'Custom':
                if cleaned_data['destination_protocol'] is None:
                    self._errors['destination_protocol'] = self.error_class(
                        [msg])
                    del cleaned_data["destination_protocol"]
                else:
                    d_protocol = cleaned_data["destination_protocol"]

                if cleaned_data['destination_public_port'] is None:
                    self._errors['destination_public_port'] = self.error_class(
                        [msg])
                    del cleaned_data["destination_public_port"]
            else:
                port_alias = neutron_extensions_client.portalias_get(
                    self.request, cleaned_data['destination_port_alias'])
                cleaned_data['destination_protocol'] = port_alias['protocol']
                cleaned_data['destination_public_port'] = port_alias['port']
                d_protocol = port_alias['protocol']

        if s_protocol and d_protocol:
            if s_protocol != d_protocol:
                raise forms.ValidationError(
                    "The source and destination Port Aliases "
                    "must use the same protocol.")

        return cleaned_data
Beispiel #3
0
 def _get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = neutron_extensions_client.portalias_get(
                 self.request, self.kwargs['port_alias_id'])
         except:
             msg = _('Unable to retrieve port alias.')
             redirect = self.get_success_url()
             exceptions.handle(self.request, msg, redirect=redirect)
     return self._object
Beispiel #4
0
 def _get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = neutron_extensions_client.portalias_get(
                 self.request, self.kwargs['port_alias_id'])
         except:
             msg = _('Unable to retrieve port alias.')
             redirect = self.get_success_url()
             exceptions.handle(self.request, msg, redirect=redirect)
     return self._object