Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rbd-replay-many
1 #!/bin/bash
2
3 original_image=
4 hosts=
5 image_prefix=
6 prog=rbd-replay
7 delay=0
8
9 while test -n "$1"; do
10   case "$1" in
11     --original-image)
12         original_image="$2"
13         shift
14         ;;
15     --original-image=*)
16         original_image="${1#--original-image=}"
17         ;;
18     --image-prefix)
19         image_prefix="$2"
20         shift
21         ;;
22     --image-prefix=*)
23         image_prefix="${1#--image-prefix=}"
24         ;;
25     --exec)
26         prog="$2"
27         shift
28         ;;
29     --exec=*)
30         prog="${1#--exec=}"
31         ;;
32     --delay)
33         delay="$2"
34         shift
35         ;;
36     --delay=*)
37         delay="${1#--delay=}"
38         ;;
39     --help|-h)
40         echo "Usage: $0 [options] --original-image=<name> <host1> [<host2> [...]] -- <rbd-replay-args>"
41         echo "Options:"
42         echo "  --original-image=name  Name (and snap) of the image that was originally traced"
43         echo "  --image-prefix=prefix  Prefix of the image names to replay against"
44         echo "  --exec=program         Path to the rbd-replay executable"
45         echo "  --delay=seconds        Wait <seconds> between starting each replay"
46         exit 0
47         ;;
48     --)
49         # remaining args are passed directly to rbd-replay
50         shift
51         break
52         ;;
53     -*)
54         echo "Unrecognized argument: $1" >&2
55         echo "(If you want to pass an argument directly to rbd-replay, use it after '--'.)" >&2
56         exit 1
57         ;;
58     *)
59         hosts="$hosts $1"
60         ;;
61   esac
62   shift
63 done
64
65 if test -z "$original_image"; then
66    echo "Specify the original image name with --original-image." >&2
67    exit 1
68 fi
69
70 if test -z "$hosts"; then
71    echo "No hosts specified." >&2
72    exit 1
73 fi
74
75 if test -z "$image_prefix"; then
76    image_prefix="$original_image"
77 fi
78
79 index=0
80 for host in $hosts; do
81     echo ssh $host "'$prog'" --map-image "'${original_image}=${image_prefix}-${index}'" "$@"
82     ssh $host "'$prog'" --map-image "'${original_image}=${image_prefix}-${index}'" "$@" &
83     index=$((index + 1))
84     if [ $delay -gt 0 ]; then
85        sleep $delay
86     fi
87 done
88 wait