Ejemplo n.º 1
0
    def create(self, req, *args, **kwargs):
        context = req.context
        try:
            if len(args) != 1:
                raise BadRequest(resource="create packetfilter operation",
                                 msg=req.url)
            body_values = json.loads(req.body)
            valid_attributes = ['tenant_id', 'dc_name', 'network_zone',
                                'name', 'srczonename', 'dstzonename',
                                'vfwname']

            values = tools.validat_values(body_values, valid_attributes)
            if 'srcipobjips' in body_values.keys():
                for ipinfo in body_values['srcipobjips']:
                    if not tools._is_valid_ipv4_addr(ipinfo):
                        raise ParamValueError(param_name=ipinfo)
                values['srcipobjips'] = body_values['srcipobjips']
            if 'dstipobjips' in body_values.keys():
                for ipinfo in body_values['dstipobjips']:
                    if not tools._is_valid_ipv4_addr(ipinfo):
                        raise ParamValueError(param_name=ipinfo)
                values['dstipobjips'] = body_values['dstipobjips']
            if 'servicenames' in body_values.keys():
                values['servicenames'] = body_values['servicenames']
            valid_range = (0, 1)
            if 'action' in body_values.keys():
                if body_values['action'] not in valid_range:
                    raise ParamValueError(param_name='action')
                values['action'] = body_values['action']
            else:
                values['action'] = 0
            if 'log' in body_values.keys():
                if body_values['log'] not in valid_range:
                    raise ParamValueError(param_name='log')
                values['log'] = body_values['log']
            else:
                values['log'] = 0
            packetfilter_info = self.manager.create_packetfilter(context,
                                                                 values)
        except Nca47Exception as e:
            self.response.status = e.code
            LOG.error(_LE('Error exception! error info: %' + e.message))
            LOG.exception(e)
            self.response.status = e.code
            return tools.ret_info(e.code, e.message)
        except MessagingException as exception:
            self.response.status = 500
            message = exception.value
            return tools.ret_info(self.response.status, message)
        except Exception as exception:
            LOG.exception(exception)
            self.response.status = 500
            message = "the values of the body format error"
            return tools.ret_info(self.response.status, message)
        return packetfilter_info
Ejemplo n.º 2
0
 def create(self, req, *args, **kwargs):
     context = req.context
     try:
         if len(args) != 1:
             raise BadRequest(resource="create dnat operation",
                              msg=req.url)
         body_values = json.loads(req.body)
         valid_attributes = ['tenant_id', 'dc_name', 'network_zone',
                             'name', 'inifname', 'wanip', 'lanipstart',
                             'lanipend', 'lanport', 'slot', 'vfwname']
         values = tools.validat_values(body_values, valid_attributes)
         keys = body_values.keys()
         if not tools._is_valid_ipv4_addr(values['wanip']):
             raise ParamValueError(param_name='wanip')
         if not tools._is_valid_ipv4_addr(values['lanipstart']):
             raise ParamValueError(param_name='lanipstart')
         if not tools._is_valid_ipv4_addr(values['lanipend']):
             raise ParamValueError(param_name='lanipend')
         if values['lanport'] != "0":
             if not tools._is_valid_port(values['lanport']):
                 raise ParamValueError(param_name='lanport')
             if 'wantcpports' in keys and 'wanudpports' in keys:
                 raise BadRequest(resource="dnat", msg="Only have one"
                                  " between wantcpports and wanudpport")
         if 'wantcpports' in keys:
             for port_range in body_values['wantcpports']:
                 if not tools._is_valid_port_range(port_range):
                     raise BadRequest(resource="wantcpports",
                                      msg=port_range)
             values['wantcpports'] = body_values['wantcpports']
         if 'wanudpports' in keys:
             for port_range in body_values['wanudpports']:
                 if not tools._is_valid_port_range(port_range):
                     raise BadRequest(resource="wantcpports",
                                      msg=port_range)
             values['wanudpports'] = body_values['wanudpports']
         dnat_info = self.manager.create_dnat(context, values)
     except Nca47Exception as e:
         self.response.status = e.code
         LOG.error(_LE('Error exception! error info: %' + e.message))
         LOG.exception(e)
         self.response.status = e.code
         return tools.ret_info(e.code, e.message)
     except MessagingException as exception:
         self.response.status = 500
         message = exception.value
         return tools.ret_info(self.response.status, message)
     except Exception as exception:
         LOG.exception(exception)
         self.response.status = 500
         message = "the values of the body format error"
         return tools.ret_info(self.response.status, message)
     return dnat_info
Ejemplo n.º 3
0
 def firewall_params(self, dic, list_):
     dic = tools.filter_string_not_null(dic, list_)
     dic_key = dic.keys()
     for key in dic_key:
         val_key = dic[key]
         if key == "ifnames":
             flag = tools.is_or_not_list(val_key)
             if flag == "0":
                 raise ParamFormatError(param_name=key)
             elif flag == "1":
                 raise ParamNull(param_name=key)
         elif key == "ipaddr":
             flag = tools.is_or_not_list(val_key)
             if flag == "0":
                 raise ParamFormatError(param_name=key)
             elif flag == "1":
                 raise ParamNull(param_name=key)
             else:
                 for v in dic['ipaddr']:
                     v0 = v.split("/")[0]
                     if not tools._is_valid_ipv4_addr(v0):
                         raise ParamFormatError(param_name=key)
                     v1 = v.split("/")[1]
                     try:
                         v1 = int(v1)
                         if v1 < 0 or v1 > 32:
                             raise ParamFormatError(param_name=key)
                     except Exception:
                         raise ParamFormatError(param_name=key)
         else:
             continue
     return dic
Ejemplo n.º 4
0
 def validat_values(self, values, valid_keys):
     """Non null input parameters"""
     recom_msg = {}
     for key in valid_keys:
         if key == 'ipstart':
             if not tools._is_valid_ipv4_addr(values[key]):
                 raise ParamValueError(param_name=key)
         if key == 'ipend':
             if not tools._is_valid_ipv4_addr(values[key]):
                 raise ParamValueError(param_name=key)
         if key == 'slotip':
             if not tools._is_valid_slotip(values[key]):
                 raise ParamValueError(param_name=key)
         if key not in values.keys():
             raise NonExistParam(param_name=key)
         else:
             recom_msg[key] = values[key]
         if values[key] is None:
             raise ParamNull(param_name=key)
     return recom_msg