Create an rdma.zsh command

For controlling remote RDMA devices

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2021-12-02 17:44:04 -05:00
parent ab780cd3a8
commit 6cc073bd87
2 changed files with 75 additions and 0 deletions

9
completions/_rdma.zsh Normal file
View File

@ -0,0 +1,9 @@
#compdef rdma.zsh
function _rdma.zsh() {
_arguments \
'1:operation:(rxe siw info start status stop off)' \
'*:remote host: _alternative
"hosts:hosts: _ssh_hosts"
"domains:domains:($(virsh list --all --name))"'
}

66
rdma.zsh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/zsh
if [ "$#" -lt 2 ]; then
echo "Usage: $0 {rxe,siw,info,start,status,stop,off} {remote host,...}"
fi
rdma_ip() {
getent hosts $1 | head -n 1 | awk '{print $1}'
}
rdma_dev() {
ssh $1 ip addr show to $(rdma_ip $1) | awk -F': ' '{print $2}'
}
rdma_cur() {
ssh $1 rdma link | awk -F '[0-9 ]' '{print $2}'
}
rdma_start() {
cur=$(rdma_cur $1)
if [[ "$cur" != "$3" ]]; then
if [[ ! -z "$cur" ]]; then
rdma_stop $1
fi
ssh $1 "sudo rdma link add "$3"0 type $3 netdev $(rdma_dev $1)"
fi
rdma_status $1 $2
}
rdma_info() {
ssh $1 "sudo ibv_devinfo" 2>&1 | sed "s/^/$2 /g"
}
rdma_status() {
link=$(ssh $1 rdma link show)
if [ ! -z $link ]; then
echo "$2 $link($(rdma_ip $1))"
else
echo "$2 stopped"
fi
}
rdma_stop() {
ssh $1 "sudo rdma link delete siw0 2>/dev/null"
ssh $1 "sudo rdma link delete rxe0 2>/dev/null"
}
tags=($(python /home/anna/bin/colors/vm.py ${@:2}))
for vm in "${@:2}"; do
index=${@[(ie)$vm]}
tag=${tags[index-1]}
case $1 in
"rxe") rdma_start $vm $tag "rxe" ;;
"siw" | "start") rdma_start $vm $tag "siw" ;;
"info") rdma_info $vm $tag ;;
"status") rdma_status $vm $tag ;;
"stop" | "off")
rdma_stop $vm
rdma_status $vm $tag
;;
*)
echo "SoftRoCE, SoftiWARP, Status, or Off?"
exit 1
;;
esac
done