[asterisk-dev] [PATCH] dahdi_span_assignments: compare subcommand
Tzafrir Cohen
tzafrir.cohen at xorcom.com
Mon May 7 10:40:00 CDT 2018
dahdi_span_assignments compare, similar to dahdi_span_types compare.
Signed-off-by: Tzafrir Cohen <tzafrir.cohen at xorcom.com>
---
dahdi_span_assignments | 45 ++++++++++++++++++++++++++++++++++++
doc/dahdi_span_assignments.8 | 22 +++++++++++++++++-
2 files changed, 66 insertions(+), 1 deletion(-)
diff --git a/dahdi_span_assignments b/dahdi_span_assignments
index 9b4f305..5387c81 100755
--- a/dahdi_span_assignments
+++ b/dahdi_span_assignments
@@ -67,6 +67,7 @@ usage() {
echo >&2 " remove - unassign spans"
echo >&2 " list - human-readable list of all spans"
echo >&2 " matched - found spans matched in configuration"
+ echo >&2 " compare - show config values that differ from system"
echo >&2 " unmatched - found spans not matched in configuration"
echo >&2 " dumpconfig - dump current state as new configuration"
echo >&2 ""
@@ -85,6 +86,8 @@ if [ $? != 0 ]; then
usage
fi
+compare=false
+
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
@@ -233,6 +236,10 @@ filter_conf() {
sed -e 's/#.*//' -e '/^[ \t]*$/d' "$DAHDISASSIGNEDSPANSCONF"
}
+dump_compare() {
+ echo "$*" >> "$compare_results_file"
+}
+
assign_device_spans() {
device="$1"
for s in $spanspecs
@@ -244,6 +251,28 @@ assign_device_spans() {
echo "(dry-run) assign $device: $s"
continue
fi
+
+ if [ "$compare" = 'true' ]; then
+ spanno_file=$(grep -l "^$local_spanno\$" "$device/span-"*"/local_spanno")
+ if [ -f "$spanno_file" ]; then
+ # Exactly one file matched
+ cur_spanno=$(echo "$spanno_file" | sed -e 's,/local_spanno,,' -e 's,^.*/span-,,')
+ cur_basechan=`cat $device/span-$cur_spanno/basechan`
+ if [ "$spanno" = "$cur_spanno" ]; then
+ cur_s="$local_spanno:$spanno:$cur_basechan"
+ if [ "$s" != "$cur_s" ]; then
+ dump_compare "$device: $s: current settings: $cur_s"
+ fi
+ else
+ cur_s="$local_spanno:$cur_spanno:$cur_basechan"
+ dump_compare "$device: $s: modified settings: $cur_s"
+ fi
+ else
+ dump_compare "$device: $s: not set"
+ fi
+ continue
+ fi
+
if [ -d "$span" ]; then
span_local_spanno=`cat "$span/local_spanno"`
if [ "$span_local_spanno" != "$local_spanno" ]; then
@@ -252,6 +281,7 @@ assign_device_spans() {
echo >&2 "$device [$local_spanno] already assigned to span $spanno. Skipping..."
continue
fi
+
echo >&2 "assign $device: $s"
if ! echo "$s" > "$device/assign_span"; then
echo >&2 "$0: failed assigning '$s' to '$device'"
@@ -300,6 +330,16 @@ assign_devices() {
do
match_device "$device"
done
+ if [ "$compare" = 'true' ]; then
+ if [ -s "$compare_results_file" ]; then
+ echo "# Some spans are not configured the same as file "
+ cat "$compare_results_file"
+ rm -f "$compare_results_file"
+ exit 5
+ fi
+ rm -f "$compare_results_file"
+ exit 0
+ fi
}
auto_assign_devices() {
@@ -392,6 +432,11 @@ matched)
unmatched)
list_devices "unmatched"
;;
+compare)
+ compare=true
+ compare_results_file=`mktemp`
+ assign_devices
+ ;;
*)
echo >&2 "Bad action='$action'"
usage
diff --git a/doc/dahdi_span_assignments.8 b/doc/dahdi_span_assignments.8
index 52e0391..dd0a95a 100644
--- a/doc/dahdi_span_assignments.8
+++ b/doc/dahdi_span_assignments.8
@@ -6,7 +6,7 @@ dahdi_span_assignments \- handle DAHDI spans assignments
.B dahdi_span_assignments [\-v|\-\-verbose] [\-n|\-\-dry\-run] <add|remove|auto> \fB[\fIdevpath\fB...]
-.B dahdi_span_assignments [\-v|\-\-verbose] list \fB[\fIdevpath\fB...]
+.B dahdi_span_assignments [\-v|\-\-verbose] <list|matched|unmatched|compare> \fB[\fIdevpath\fB...]
.B dahdi_span_assignments [\-v|\-\-verbose] [\-k|\-\-key \fIkey\fB] dumpconfig
@@ -84,6 +84,16 @@ file doesn't affect these assignments.
List all spans in the system.
.RE
+.B matched
+.RS
+List spans in the system that were listed in the configuration file.
+.RE
+
+.B unmatched
+.RS
+List spans in the system that were not listed in the configuration file.
+.RE
+
.B dumpconfig
.RS
List all assigned spans in the system in a format fit to be used in
@@ -94,6 +104,16 @@ you have (automatically or manually) assigned all existing spans.
uses this command internally.
.RE
+.B compare
+.RS
+Compare the settings on the system to those in the configuration file.
+For each line that applies to a device on the system, print it if the
+value to be set and the active value on the system differ.
+
+The exit status is 0 if there is no difference and non-zero if a
+difference was detected.
+.RE
+
.SH OPTIONS
.B \-v \-\-verbose
--
2.17.0
More information about the asterisk-dev
mailing list