~smoser/+junk/ppc64el-kvmhelpers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# ip4ppc64el. put this file in ~/bin/ip4ppc64el . make it executable.
#
# put the following in ~/.ssh/config:
# Host cameron* borbein* diamond* stilson* modoc* winton* wolfe* elco* pennsy* rockne* wahl* kinner* cutting* snyder* wichita*
#   User ubuntu
#   ProxyCommand nc -q0 $(ip4ppc64el %h) %p
#
# then you can do 'ssh winton-01' or 'ssh winton'

data="""
cameron 10.245.70.102 10.245.67.192/26
wichita 10.245.64.15  10.245.69.128/26
borbein 10.245.64.14  10.245.68.64/26
diamond 10.245.64.13  10.245.68.0/26
stilson 10.245.64.12  10.245.67.128/26
modoc   10.245.64.11  10.245.67.64/27
winton  10.245.64.10  10.245.67.0/26
wolfe   10.245.64.9   10.245.66.192/26
elco    10.245.64.8   10.245.66.128/26
pennsy  10.245.64.7   10.245.66.64/26
rockne  10.245.64.6   10.245.66.0/26
wahl    10.245.64.5   10.245.65.192/26
kinner  10.245.64.4   10.245.65.128/26
cutting 10.245.64.3   10.245.65.64/26
snyder  10.245.64.2   10.245.65.0/26
"""
#kelsey  10.245.64.11 10.245.67.64/26

guestfind='
$1 == hn {
  sub(/\/.*/,"", $3);
  split($3, t, ".")
  print(t[1]"."t[2]"."t[3]"."t[4]+n); }
'
hostfind='$1 == hn { print $2 }'

input=$1
host=${input%-*}
num=${input##*-}
case "$input" in
   *-[0-9]*) afind="$guestfind";;
   *) afind="$hostfind";;
esac

addr=$(echo "$data" | awk "$afind" "hn=$host" "n=$num")
[ -n "$addr" ] || { echo "failed to find ip for $input" 1>&1; exit 1; }
echo "$input -> $addr" 1>&2;
echo "$addr"