def validate_bgp_server_hosts(hosts): for host in hosts: if not ip.valid_ipv4(host) and not ip.valid_ipv6(host): raise ConfigTypeError(desc=('Invalid bgp sever hosts ' 'configuration value %s' % hosts)) return hosts
def validate_router_id(cluster_id): if not isinstance(cluster_id, str): raise ConfigTypeError(conf_name=CLUSTER_ID) if not is_valid_ipv4(cluster_id): raise ConfigValueError(desc='Invalid cluster id %s' % cluster_id) return cluster_id
def validate_local_port(port): if not isinstance(port, (int, long)): raise ConfigTypeError(desc='Invalid local port: %s' % port) if port < 1025 or port > 65535: raise ConfigValueError(desc='Invalid local port value: %s, has to be' ' between 1025 and 65535' % port) return port
def validate_allow_local_as_in_count(count): if not isinstance(count, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be ' 'integral type' % ALLOW_LOCAL_AS_IN_COUNT)) if count < 0: raise ConfigValueError(desc='Invalid local AS count %s' % count) return count
def validate_refresh_stalepath_time(rst): if not isinstance(rst, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be ' 'integral type' % REFRESH_STALEPATH_TIME)) if rst < 0: raise ConfigValueError(desc='Invalid refresh stalepath time %s' % rst) return rst
def validate_refresh_max_eor_time(rmet): if not isinstance(rmet, numbers.Integral): raise ConfigTypeError(desc=('Configuration value for %s has to be of ' 'integral type ' % REFRESH_MAX_EOR_TIME)) if rmet < 0: raise ConfigValueError(desc='Invalid refresh stalepath time %s' % rmet) return rmet
def validate_bgp_server_port(server_port): if not isinstance(server_port, numbers.Integral): raise ConfigTypeError(desc=('Invalid bgp sever port configuration ' 'value %s' % server_port)) if server_port < 0 or server_port > 65535: raise ConfigValueError(desc='Invalid server port %s' % server_port) return server_port
def valid_filter(filter_): if isinstance(filter_, Filter): return filter_ if not isinstance(filter_, dict): raise ConfigTypeError(desc='Invalid filter: %s' % filter_) if 'type' not in filter_: raise ConfigTypeError(desc='Invalid filter: %s, needs \'type\' field' % filter_) if not filter_['type'] in SUPPORTED_FILTER_VALIDATORS: raise ConfigTypeError( desc='Invalid filter type: %s, supported filter' ' types are %s' % (filter_['type'], SUPPORTED_FILTER_VALIDATORS.keys())) return SUPPORTED_FILTER_VALIDATORS[filter_['type']](filter_)
def valdiate_rd(route_disc): if not isinstance(route_disc, str): raise ConfigTypeError(conf_name=ROUTE_DISTINGUISHER, conf_value=route_disc) if not validation.is_valid_route_disc(route_disc): raise ConfigValueError(conf_name=ROUTE_DISTINGUISHER, conf_value=route_disc) return route_disc
def validate_router_id(router_id): if not router_id: raise MissingRequiredConf(conf_name=ROUTER_ID) if not isinstance(router_id, str): raise ConfigTypeError(conf_name=ROUTER_ID) if not is_valid_ipv4(router_id): raise ConfigValueError(desc='Invalid router id %s' % router_id) return router_id
def validate_bgp_conn_retry_time(bgp_conn_retry_time): if not isinstance(bgp_conn_retry_time, numbers.Integral): raise ConfigTypeError(desc=('Invalid bgp conn. retry time ' 'configuration value %s' % bgp_conn_retry_time)) if bgp_conn_retry_time < 10: raise ConfigValueError(desc=('Invalid bgp connection retry time' ' configuration value %s' % bgp_conn_retry_time)) return bgp_conn_retry_time
def validate_tcp_conn_timeout(tcp_conn_timeout): # TODO(apgw-dev) made-up some valid values for this settings, check if we # have a standard value in any routers if not isinstance(tcp_conn_timeout, numbers.Integral): raise ConfigTypeError(desc=('Invalid tcp connection timeout ' 'configuration value %s' % tcp_conn_timeout)) if tcp_conn_timeout < 10: raise ConfigValueError(desc=('Invalid tcp connection timeout' ' configuration value %s' % tcp_conn_timeout)) return tcp_conn_timeout
def validate_import_rts(import_rts): if not isinstance(import_rts, list): raise ConfigTypeError(conf_name=IMPORT_RTS, conf_value=import_rts) if not (len(import_rts) <= MAX_NUM_IMPORT_RT): raise ConfigValueError(desc='Max. import RT is limited to %s' % MAX_NUM_IMPORT_RT) if not all(validation.is_valid_ext_comm_attr(rt) for rt in import_rts): raise ConfigValueError(conf_name=IMPORT_RTS, conf_value=import_rts) # Check if we have duplicates unique_rts = set(import_rts) if len(unique_rts) != len(import_rts): raise ConfigValueError(desc='Duplicate value provided %s' % import_rts) return import_rts
def validate_export_rts(export_rts): if not isinstance(export_rts, list): raise ConfigTypeError(conf_name=EXPORT_RTS, conf_value=export_rts) if not (len(export_rts) <= MAX_NUM_EXPORT_RT): raise ConfigValueError(desc='Max. import RT is limited to %s' % MAX_NUM_EXPORT_RT) try: ExtCommunity.validate_supported_attributes(export_rts) except Exception: raise ConfigValueError(conf_name=EXPORT_RTS, conf_value=export_rts) # Check if we have duplicates unique_rts = set(export_rts) if len(unique_rts) != len(export_rts): raise ConfigValueError(desc='Duplicate value provided in %s' % (export_rts)) return export_rts
def validate_remote_port(port): if not isinstance(port, numbers.Integral): raise ConfigTypeError(desc='Invalid remote port: %s' % port) return port
def validate_max_path_ext_rtfilter_all(max_path_ext_rtfilter_all): if max_path_ext_rtfilter_all not in (True, False): raise ConfigTypeError(desc=('Invalid max_path_ext_rtfilter_all' ' configuration value %s' % max_path_ext_rtfilter_all)) return max_path_ext_rtfilter_all
def validate_max_path_ext_rtfilter_all(max_path_ext_rtfilter_all): if not isinstance(max_path_ext_rtfilter_all, bool): raise ConfigTypeError(desc=('Invalid max_path_ext_rtfilter_all' ' configuration value %s' % max_path_ext_rtfilter_all)) return max_path_ext_rtfilter_all
def validate_local_pref(local_pref): if not isinstance(local_pref, numbers.Integral): raise ConfigTypeError(desc=('Invalid local_pref' ' configuration value %s' % local_pref)) return local_pref
def valid_attribute_map(attribute_map): if not isinstance(attribute_map, AttributeMap): raise ConfigTypeError(desc='Invalid AttributeMap: %s' % attribute_map) else: return attribute_map