2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 22:45:18 +00:00

corrected and optimized cql_dump in kea-admin.in

This commit is contained in:
Andrei Pavel
2016-06-23 11:30:21 +03:00
committed by Tomek Mrugalski
parent 08343129b4
commit ab934d8b9b

View File

@@ -366,9 +366,6 @@ get_dump_query() {
pgsql) pgsql)
invoke="select * from" invoke="select * from"
;; ;;
cql)
invoke="select * from"
;;
*) *)
log_error "unsupported backend ${backend}" log_error "unsupported backend ${backend}"
usage usage
@@ -474,49 +471,42 @@ pgsql_dump() {
} }
cql_dump() { cql_dump() {
# Get the query appropriate to lease version. Explicitly specify all columns
# get the correct dump query # so that they are returned in expected order.
version=`cql_version`
retcode=$?
if [ $retcode -ne 0 ]
then
log_error "lease-dump: cql_version failed, exit code $retcode"
exit 1;
fi
# Fetch the correct SQL text. Note this function will exit
# if it fails.
select_where_clause=""
if [ $dump_type -eq 4 ]; then if [ $dump_type -eq 4 ]; then
dump_qry="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM lease4" dump_query="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM lease4"
select_where_clause=" WHERE address = 0" # invalid address
elif [ $dump_type -eq 6 ]; then elif [ $dump_type -eq 6 ]; then
dump_qry="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM lease6" dump_query="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM lease6"
select_where_clause=" WHERE address = '::'" # invalid address else
fi log_error "lease-dump: lease type ( -4 or -6 ) needs to be specified"
# Make sure they specified a file
if [ "$dump_file" = "" ]; then
log_error "you must specify an output file for lease-dump"
usage usage
exit 1 exit 1
fi fi
# If output file exists, notify user, allow them a chance to bail # Check if file was specified.
if [ "$dump_file" = "" ]; then
log_error "lease-dump: output file needs to be specified with -o"
usage
exit 1
fi
# If output file exists, notify user, allow them a chance to bail.
check_file_overwrite $dump_file check_file_overwrite $dump_file
cql_execute "${dump_qry}${select_where_clause}" | head -n 2 | tail -n 1 | sed -e 's/\s*//g' | sed -e 's/|/,/g' > $dump_file # Run query, check for failure.
if [ $? -ne 0 ]; then result=`cql_execute "$dump_query"`
log_error "lease-dump: cql_execute failed, exit code $retcode"; return_code=$?
if [ $return_code -ne 0 ]; then
log_error "lease-dump: cql_execute failed, exit code $return_code";
exit 1 exit 1
fi fi
cql_execute "${dump_qry}" | tail -n +4 | head -n -2 | sed -e 's/\s*//g' | sed -e 's/|/,/g' | sort -r >> $dump_file # Parse and display header.
if [ $? -ne 0 ]; then echo "$result" | head -n 2 | tail -n 1 | sed -e 's/\s*//g' | sed -e 's/|/,/g' > $dump_file
log_error "lease-dump: cql_execute failed, exit code $retcode";
exit 1 # Parse and display contents - done separately from header to allow sorting
fi # by address.
echo "$result" | tail -n +4 | head -n -2 | sed -e 's/\s*//g' | sed -e 's/|/,/g' | sort -r >> $dump_file
echo lease$dump_type successfully dumped to $dump_file echo lease$dump_type successfully dumped to $dump_file
exit 0 exit 0