improved dahdi_span_types dumpconfig

* Better defaults:
  - A wildcard match:
    - If '--line-mode' option is given, generate a wildcard entry.
      (existing behavior).

    - Otherwise, if *all spans* are of the same type (E1/T1),
      generate a wildcard entry for this type.
      This is the most common use-case and now it work without
      any command line flags.

    - Otherwise (mixed E1/T1 spans), do not generate a wildcard entry.
      This isn't common case (except from our labs), but regardless
      without '--line-mode' any guess could be wrong.

  - Specific device matches:
    - If all spans are of the same type, generate commented out
      specific entries (for manual overrides).

    - If spans have mixed E1/T1 types, generate specific entries
      In this case, specific entries MUST NOT be commented out
      otherwise, the configuration file is wrong!

* Generated header with better organization:
  - Shows what is generated:
    - Generating wildcard / Not generating wildcard
    - Generating specific lines / Generating *commented-out* specific lines

  - For each decision, show *why* it was taken.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
Acked-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
Oron Peled 2014-03-31 19:48:30 +03:00 committed by Tzafrir Cohen
parent 1292ea9078
commit f2628eeedd
1 changed files with 47 additions and 18 deletions

View File

@ -188,28 +188,57 @@ show_spantypes() {
done
}
list_pri_spantypes() {
find $DEVICES -follow -maxdepth 1 -name spantype | \
xargs cat | \
sed -n '/:[ETJ]1$/s/^.*://p' | \
sort -u | \
tr '\n' ' ' | \
sed -e 's/^ *//' -e 's/ *$//'
}
dump_config() {
pri_spantypes=`list_pri_spantypes`
num_spantypes=`echo "$pri_spantypes" | wc -w`
gen_default=''
echo '#'
echo "# Autogenerated by $0 on `date`"
echo "# Map PRI DAHDI devices to span types for E1/T1/J1"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo "# Was run with '--line-mode=$DEFAULT_LINE_MODE' -- so will:"
echo "# * Generate default wildcard entry"
echo "# * Generate commented-out device list (for overrides)"
fi
echo ''
fmt="%-65s %s\n"
printf "$fmt" '# @location/hardware_id' 'span_type'
echo "#"
echo "# Summary:"
if [ "$DEFAULT_LINE_MODE" != '' ]; then
echo ""
echo "# Wildcard line-mode $DEFAULT_LINE_MODE".
printf "$fmt" "*" "*:$DEFAULT_LINE_MODE"
echo ""
echo "# A list of commented out configurations for spans."
echo "# Each item may be un-commented to provide an override."
gen_default="$DEFAULT_LINE_MODE"
echo "# * Generating wildcard match of $gen_default."
echo "# - Was run with '--line-mode=$DEFAULT_LINE_MODE'"
elif [ "$num_spantypes" -eq 1 ]; then
gen_default="$pri_spantypes"
echo "# * Generating wildcard match of $gen_default."
echo "# - Spans were $pri_spantypes"
else
echo "# * Not generating wildcard match."
echo "# - Was run without '--line-mode' option and span were of mixed types [$pri_spantypes]"
fi
echo "#"
if [ "$num_spantypes" -eq 1 ]; then
echo "# * Generating a list of commented out configurations for spans."
echo "# - Spans were $pri_spantypes"
echo "# - Uncomment for specific overrides"
else
echo "# * Generating a list of specific span configurations."
echo "# - Spans were of mixed types: $pri_spantypes"
fi
echo "#"
echo ''
fmt="%-65s %s"
printf "$fmt\n" '# @location/hardware_id' 'span_type'
if [ "$gen_default" != '' ]; then
printf "$fmt\t\t# Wildcard line-mode" "*" "*:$gen_default"
echo ""
fi
echo ""
for device in $DEVICES
do
devpath=`cd "$device" && pwd -P`
@ -226,10 +255,10 @@ dump_config() {
cat "$device/spantype" | while read st; do
case "$st" in
*:[ETJ]1)
if [ "$DEFAULT_LINE_MODE" != '' ]; then
printf "#$fmt" "$id" "$st"
if [ "$num_spantypes" -eq 1 ]; then
printf "#$fmt\n" "$id" "$st"
else
printf "$fmt" "$id" "$st"
printf "$fmt\n" "$id" "$st"
fi
;;
*)
@ -237,7 +266,7 @@ dump_config() {
;;
esac
done | sort -n
#echo ''
echo ''
done
}