def get_free_namespace_port(protocol, namespace=None, start=1024, end=None):
 if (protocol == n_const.PROTO_NAME_TCP):
  param = '-tna'
 elif (protocol == n_const.PROTO_NAME_UDP):
  param = '-una'
 else:
  raise ValueError(('Unsupported protocol %s' % protocol))
 ip_wrapper = ip_lib.IPWrapper(namespace=namespace)
 output = ip_wrapper.netns.execute(['ss', param])
 used_ports = _get_source_ports_from_ss_output(output)
 return get_unused_port(used_ports, start, end)

def get_free_namespace_port ( protocol , namespace = None , start = 1024 , end = None ) : if ( protocol == n_const . PROTO_NAME_TCP ) : param = '-tna' elif ( protocol == n_const . PROTO_NAME_UDP ) : param = '-una' else : raise ValueError ( ( 'Unsupported protocol %s' % protocol ) ) ip_wrapper = ip_lib . IPWrapper ( namespace = namespace ) output = ip_wrapper . netns . execute ( [ 'ss' , param ] ) used_ports = _get_source_ports_from_ss_output ( output ) return get_unused_port ( used_ports , start , end )
return an unused port from given namespace warning: this function returns a port that is free at the execution time of this function .