X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fsbin%2Fcirros-ds;fp=cirros-testvm%2Fsrc-cirros%2Fsrc%2Fsbin%2Fcirros-ds;h=6943bda3cf24672a182ee18b368b5e8dcef74161;hb=b0a0f15dfaa205161a7fcb20cf1b8cd4948c2ef3;hp=0000000000000000000000000000000000000000;hpb=c6ac3cd55ee2da956195eee393b0882105dfad4e;p=packages%2Ftrusty%2Fcirros-testvm.git diff --git a/cirros-testvm/src-cirros/src/sbin/cirros-ds b/cirros-testvm/src-cirros/src/sbin/cirros-ds new file mode 100755 index 0000000..6943bda --- /dev/null +++ b/cirros-testvm/src-cirros/src/sbin/cirros-ds @@ -0,0 +1,121 @@ +#!/bin/sh + +. ${CIRROS_LIB:=/lib/cirros/shlib_cirros} || + { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; } + +Usage() { + cat </dev/null 2>&1 + for tok in $cmdline; do + case "$tok" in + dslist=) cmdline_list=none;; + dslist=*) cmdline_list=${tok#dslist=};; + esac + done + if [ -n "${cmdline_list}" -a "${cmdline_list}" != "none" ]; then + IFS=","; set -- ${cmdline_list}; IFS="$oifs" + debug 2 "found datasource list on cmdline:" "$@" + else + set -- ${DATASOURCE_LIST} + debug 2 "found datasource list in config:" "$@" + fi + [ $# -ne 0 ] || { error "no datasource list configured?"; return 1; } + fi + + TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") || + { error "failed to make tempdir"; return 1; } + trap cleanup EXIT + + local ds result="" ret="" + + PATH="${DS_D}:$PATH" + for ds in "$@"; do + result="${TEMP_D}/${ds}/result" + read_uptime + debug 2 "running: $ds $ptv $mode $TEMP_D/${ds} [up ${_RET}]" + "$ds" $ptv "$mode" "${TEMP_D}/${ds}" > "${TEMP_D}/output" + ret=$? + if [ $ret -eq 0 ] && [ -r "$result" ]; then + rm -f "$result" + if $dryrun; then + error "$ds-$mode: datasource found" + else + rm -Rf "$RESULTS_D" && mkdir -p "${RESULTS_D%/*}" && + cp -a "${TEMP_D}/$ds/" "${RESULTS_D}" || { + error "failed to copy results from $ds to $RESULTS_D"; + return 1; + } + echo "$ds" > "$RESULTS_D/dsname" + echo "$mode" > "$RESULTS_D/dsmode" + fi + debug 1 "found datasource ($ds, $mode)" + return 0 + elif [ $ret -eq 0 ]; then + debug 2 "$ds-$mode: no datasource found" + else + error "$ds-$mode: returned error" + fi + done + + read_uptime + debug 1 "no results found for mode=$mode. up $_RET. searched:" "$@" + return 1 +} + +cirros_ds "$@" + +# vi: ts=4 noexpandtab