-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathganesha-enablev3.sh
128 lines (121 loc) · 3.35 KB
/
ganesha-enablev3.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# 45Drives
# Brett Kelly
## FUNCTIONS
usage() { # Help
cat << EOF
Usage:
[-l] Update nfsv3 for selected export. Comma separated list of EXPORT_ID. <1,2,3>. Not required if "-a" flag is used
[-a] Update nfsv3 for all exports
[-e] Enable nfsv3 for selected export(s)
[-d] Disable nfsv3 for selected export(s)
[-s] Display list of current shares
[-h] Displays this message
EOF
exit 0
}
printerr(){
echo $1
exit 1
}
getExports(){
EXPORTS=( $(rados -p nfs_ganesha -N ganesha-export ls | grep export | sort) )
}
getExportConf(){
EXPORT_CONFIGS=( $(rados -p nfs_ganesha -N ganesha-export ls | grep conf | sort) )
}
printRow(){
printf "%-12s | %-12s | %-12s\n" "$1" "$2" "$3"
}
enableNFSV3(){
rados -p nfs_ganesha -N ganesha-export get $1 - |\
sed "s/protocols = 4;/protocols = 3,4;/g" |\
rados -p nfs_ganesha -N ganesha-export put $1 -
}
disableNFSV3(){
rados -p nfs_ganesha -N ganesha-export get $1 - |\
sed "s/protocols = 3,4;/protocols = 4;/g" |\
rados -p nfs_ganesha -N ganesha-export put $1 -
}
updateExport(){
if [ "$ENABLE_V3" == "true" ];then
enableNFSV3 $1
elif [ "$DISABLE_V3" == "true" ];then
disableNFSV3 $1
fi
}
notifyGanesha(){
rados -p nfs_ganesha -N ganesha-export notify $1 "" &> /dev/null
}
displayExports(){
getExports
printRow "EXPORT_ID" "EXPORT_PATH" "PROTOCOL_VERSION"
printRow "---------" "-----------" "----------------"
for export in ${EXPORTS[@]};do
export_object=$(rados -p nfs_ganesha -N ganesha-export get $export -)
export_id=$( echo "$export_object" | grep export_id | awk '{print $3}' | cut -d ";" -f1)
path=$( echo "$export_object" | grep path | awk '{print $3}' | cut -d '"' -f 2)
protocols=$( echo "$export_object" | grep protocols | awk '{print $3}' | cut -d ";" -f1)
printRow "$export_id" "$path" "$protocols"
done
}
#INIT
ENABLE_ALL="false"
ENABLE_V3="false"
DISABLE_V3="false"
# GET USER INPUT
while getopts 'adel:sh' OPTION; do
case ${OPTION} in
a)
ENABLE_ALL="true"
;;
d)
DISABLE_V3="true"
;;
e)
ENABLE_V3="true"
;;
l)
input=${OPTARG}
IFS=',' read -r -a _EXPORT_LIST <<< "$input"
EXPORT_LIST=$(printf '%s\n' "${_EXPORT_LIST[@]}" | awk '!a[$0]++')
;;
s)
displayExports
exit 0
;;
h)
usage
;;
esac
done
#VERIFY USER INPUT
if [ "$ENABLE_V3" == "false" ] && [ "$DISABLE_V3" == "false" ];then
printerr "Error: enable (-e) or (-d) flag is required"
fi
if [ "$ENABLE_V3" == "true" ] && [ "$DISABLE_V3" == "true" ];then
printerr "Error: Both enable and disable flags provided"
fi
if [ "$ENABLE_ALL" != "true" ] && [ -z "$EXPORT_LIST" ];then
printerr "Error: list of exports required"
fi
#MAIN
getExports
if [ "$ENABLE_ALL" == "true" ];then
for export in ${EXPORTS[@]};do
updateExport $export
done
else
for export_id in ${EXPORT_LIST[@]};do
for export in ${EXPORTS[@]};do
id=$( rados -p nfs_ganesha -N ganesha-export get $export - | grep export_id | awk '{print $3}' | cut -d ";" -f1)
if [ "$export_id" == "$id" ];then
updateExport $export
fi
done
done
fi
getExportConf
for conf in ${EXPORT_CONFIGS[@]};do
notifyGanesha $conf
done