3 # lustre_routes_conversion
4 # This script takes a file with routes configured as follows:
5 # <network> [<hop>] <gateway>@<exit network>[:<priority>];
12 # <network>: { gateway: <gateway>@<exit network> [hop: <hop>] [priority:
15 # The purpose of this script is to covert legacy route configuration
16 # syntax to the new route configuration syntax
18 ############################################################################
20 progname=$(basename $0)
24 convert legacy route config syntax to new route config syntax"
25 usage: $progname <legacy file> <new file>
26 -h|--help: display this message
30 while [ ! -f "$1" ]; do
32 -h|--help) usage; exit 0 ;;
37 [ -z "$1" ] || [ -z "$2" ] && usage && exit 1
39 # Usage: read_and_parse <file name>
40 # Read a routes_config file and parse it out, then feed the proper input
41 # int lcl --net <> add_route <> to configure a route.
48 # Split the input string at ';', since multiple routes on
49 # the same line are separated by ';'
53 # It is possible that one single line can contain multiple
56 echo "${multi_routes[@]}"
58 # Iterate over each of the routes on this line. This
59 # returns indicies from the routes[] array, which are
60 # dereferenced and split separately to avoid confusion
61 # between whitespaces of routes on the same line.
62 for index in "${!multi_routes[@]}"; do
63 # initialize variables.
70 # Split at ':' and ' ' to get the priority if it exists
71 # Also will split all the different tokens in the
74 tokens=(${multi_routes[$index]})
76 # Split at ' ' to separate the network from the gateway
78 gatewayorhop=${tokens[1]}
80 # since hop is an optional parameter after we get this
81 # position we need to check if we got the hop or gateway
82 # parameter. Set gateway is always of the form ip@intf,
83 # then we can simply check for the '@' character in the
84 # string. if it exists then we don't have a hop but a
85 # gateway. If we don't then we assume that a hop exists
86 # and a gateway follows it
87 if [[ "$gatewayorhop" == *@* ]]; then
96 if [ -z "$network" ] || [ -z "$gateway" ]; then
100 # Write the translated line into the file.
101 echo -n "$network: { gateway: $gateway"
102 [ -n "$hop" ] && echo -n ", hop: $hop"
103 [ -n "$priority" ] && echo -n ", priority: $priority"
107 echo "$progname: converted routes written to $outfile"