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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#!/bin/sh
#
# Copyright (C) 2012-2013 Red Hat, Inc. All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: Radek Novacek <rnovacek@redhat.com>
#
pegasus_repository="/var/lib/Pegasus/"
default_namespace="root/cimv2"
function usage()
{
printf "Usage: $0 [ --just-mofs ] [ -n namespace ] [ -c cimom ]
CMD <mof> [mof] [...] [reg]
CMD is one of [ register, unregister ]
Default namespace is $default_namespace, which can be changed with '-n' option.
Supported cimoms are sfcbd and tog-pegasus. Without \"-c\" argument, the
operation is processed for any cimom present on system (all of them).
--just-mofs option causes that all arguments after CMD will be
treated as mof files - no registration file is expected.
usage with --just-mofs:
$0 CMD <mof> [mof] [...]
usage without:
$0 CMD <mof> [mof] [...] <reg>\n"
}
function register()
{
if [ $JUST_MOFS -eq 0 ]; then
reg=$1
shift
fi
mofs="$@"
if [ $HAS_SFCBD -eq 1 ] && echo $cimom | grep -q 'all\|sfcbd';
then
/usr/bin/sfcbstage -n $namespace ${reg:+-r} $reg $mofs
/usr/bin/sfcbrepos -f
/usr/bin/systemctl reload-or-try-restart sblim-sfcb.service
fi
if [ $HAS_PEGASUS -eq 1 ] && echo $cimom | grep -q 'all\|tog-pegasus';
then
/usr/sbin/cimserver --status > /dev/null 2>&1
if [ $? -eq 0 ];
then
CIMMOF="/usr/bin/cimmof -aEV -n $namespace"
else
CIMMOF="/usr/bin/cimmofl -aEV -R $pegasus_repository -n $namespace"
fi
$CIMMOF -uc $mofs
if [ $JUST_MOFS -eq 0 ]; then
if [ -x $(dirname $0)/openlmi-register-pegasus ];
then
cat "$reg" | $(dirname $0)/openlmi-register-pegasus | $CIMMOF -uc -n root/PG_Interop
else
cat "$reg" | /usr/libexec/openlmi-register-pegasus | $CIMMOF -uc -n root/PG_Interop
fi
fi
fi
}
function unregister()
{
if [ $JUST_MOFS -eq 0 ]; then
reg=$1
shift
fi
declare -a mofs=("$@")
if [ $HAS_SFCBD -eq 1 ] && echo $cimom | grep -q 'all\|sfcbd';
then
# convert mofs to `basename mof`
declare -a bmofs
for ((i=0; i<${#mofs[@]}; i++)); do
bmofs[$i]=$(basename "${mofs[$i]}")
done
/usr/bin/sfcbunstage -n $namespace ${reg:+-r} $(basename "$reg") ${bmofs[@]}
/usr/bin/sfcbrepos -f
/usr/bin/systemctl reload-or-try-restart sblim-sfcb.service
fi
if [ $HAS_PEGASUS -eq 1 ] && echo $cimom | grep -q 'all\|tog-pegasus';
then
if [ -x $(dirname $0)/openlmi-cimmof ]; then
$(dirname $0)/openlmi-cimmof -n $namespace delete ${mofs[@]}
else
/usr/libexec/openlmi-cimmof -n $namespace delete ${mofs[@]}
fi
if [ -n "$reg" ];
then
for provider in $(sed -n 's/ *location: *//p' "$reg" | sort | uniq);
do
/usr/bin/cimprovider -d -m ${provider} && /usr/bin/cimprovider -r -m ${provider}
done
fi
fi
}
JUST_MOFS=0
optspec=":hn:c:-:"
while getopts "$optspec" optchar; do
case "$optchar" in
-) # long options parsing
case "$OPTARG" in
just-mofs)
JUST_MOFS=1
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Unknown option --${OPTARG}" >&2
exit 1
fi
;;
esac
;;
n)
namespace="$OPTARG"
;;
c)
cimom="$OPTARG"
if [ "$cimom" != "sfcbd" -a "$cimom" != "tog-pegasus" ]; then
echo "Not supported cimom: $cimom" >&2
exit 1
fi
;;
h)
usage;
exit 0;
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Non-option argument: '-${OPTARG}'" >&2
exit 1
fi
;;
esac
done
shift $(($OPTIND - 1))
namespace=${namespace:-$default_namespace}
cimom=${cimom:-all}
if [ $# -lt 2 ];
then
usage
exit 1
fi
if [ -e /usr/sbin/sfcbd ];
then
HAS_SFCBD=1
else
HAS_SFCBD=0
if [ $cimom = "sfcbd" ]; then
echo "Sfcbd not detected on system!" >&2
exit 1
fi
fi
if [ -e /usr/sbin/cimserver ];
then
HAS_PEGASUS=1
else
HAS_PEGASUS=0
if [ $cimom = "tog-pegasus" ]; then
echo "Pegasus not detected on system!" >&2
exit 1
fi
fi
# TODO: check if at least one server is installed
CMD=$1
shift
# parse the reg and mofs - use $@ and remove the last item
declare -a ARGS=("$@")
if [ $JUST_MOFS -eq 0 ];
then
LEN=$(( ${#ARGS[@]} -1 ))
REG=${ARGS[$LEN]}
MOFS=(${ARGS[@]:0:$(($LEN))})
else
MOFS=("$@")
fi
case $CMD in
register)
register $REG ${MOFS[@]}
;;
unregister)
unregister $REG ${MOFS[@]}
;;
**)
usage
exit 1
esac
|