~ampelbein/ubuntu/oneiric/heartbeat/lp-770743

« back to all changes in this revision

Viewing changes to cim/mof/do_register.sh

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-10 19:29:25 UTC
  • mfrom: (5.2.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090810192925-9zy2llcbgavbskf7
Tags: 2.99.2+sles11r9-5ubuntu1
* New upstream snapshot
* Adjusted heartbeat.install and rules for documentation path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# Linux-HA: CIM Provider register tool 
4
 
#
5
 
# Author: Jia Ming Pan <jmltc@cn.ibm.com>
6
 
# Copyright (c) 2005 International Business Machines
7
 
# Licensed under the GNU GPL.
8
 
#
9
 
#
10
 
 
11
 
#---------- openwbem functions ---------------------------------------
12
 
 
13
 
openwbem_config=""
14
 
openwbem_http_port=5988
15
 
openwbem_https_port=5989
16
 
openwbem_get_config_pathname()
17
 
{
18
 
        owcimomd=`which owcimomd`
19
 
        prefix=`dirname $owcimomd`
20
 
        prefix=`dirname $prefix`
21
 
        echo config file: "$prefix/etc/openwbem/openwbem.conf"
22
 
        openwbem_config="$prefix/etc/openwbem/openwbem.conf"
23
 
}
24
 
 
25
 
openwbem_get_http_port()
26
 
{
27
 
        openwbem_get_config_pathname
28
 
        http_port=`grep -e "http_server.http_port.*=" $openwbem_config | sed -e 's/.*=\W*\(\D*\)/\1/'`
29
 
        if [ "X$http_port" != "X" ]; then
30
 
                openwbem_http_port=$http_port
31
 
        fi
32
 
        echo openwbem_http_port: $openwbem_http_port
33
 
}
34
 
 
35
 
openwbem_get_https_port()
36
 
{
37
 
        openwbem_get_config_pathname
38
 
        https_port=`grep -e "http_server.https_port.*=" $openwbem_config | sed -e 's/.*=\W*\(\D*\)/\1/'`
39
 
        if [ "X$https_port" != "X" ]; then
40
 
                openwbem_https_port=$https_port
41
 
        fi
42
 
        echo openwbem_https_port: $openwbem_https_port
43
 
}
44
 
 
45
 
openwbem_register ()
46
 
{
47
 
        mof_file=$1
48
 
        reg_file=$2
49
 
 
50
 
        ps -C owcimomd > /dev/null 2>&1
51
 
        if test $? != 0; then
52
 
                echo "owcimomd not running, start it first"
53
 
                exit
54
 
        fi
55
 
 
56
 
        OWMOFC=`which owmofc` 
57
 
        if test $? != 0; then
58
 
                echo "owmofc not found, OpenWbem not installed?"
59
 
        fi
60
 
        
61
 
        openwbem_get_http_port
62
 
        $OWMOFC -u "http://localhost:$openwbem_http_port/root/cimv2" $mof_file
63
 
}
64
 
 
65
 
openwbem_unregister ()
66
 
{
67
 
        mof_file=$1
68
 
        reg_file=$2
69
 
 
70
 
        ps -C owcimomd > /dev/null 2>&1
71
 
        if test $? != 0; then
72
 
                echo "owcimomd not running, start it first"
73
 
                exit
74
 
        fi
75
 
 
76
 
        OWMOFC=`which owmofc`
77
 
        if test $? != 0; then
78
 
                echo "owmofc not found, OpenWbem not installed?"
79
 
        fi
80
 
 
81
 
        openwbem_get_http_port
82
 
        $OWMOFC -u "http://localhost:$openwbem_http_port/root/cimv2" -r $mof_file
83
 
}
84
 
 
85
 
#---------- pegasus functions ----------------------------------------
86
 
 
87
 
pegasus_add_module ()
88
 
{
89
 
        mof_file=$1
90
 
        reg_file=$2
91
 
        out_file=$REGFILE
92
 
 
93
 
        modules=`cat $reg_file 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
94
 
        for module in $modules; do
95
 
cat >> $out_file <<EOF
96
 
instance of PG_ProviderModule
97
 
{
98
 
   Name = "$module";
99
 
   Location = "$module";
100
 
   Vendor = "LinuxHA";
101
 
   Version = "2.0.0";
102
 
   InterfaceType = "CMPI";
103
 
   InterfaceVersion = "2.0.0";
104
 
};
105
 
EOF
106
 
        done
107
 
 
108
 
}
109
 
 
110
 
pegasus_add_provider ()
111
 
{
112
 
        mof_file=$1
113
 
        reg_file=$2
114
 
        out_file=$REGFILE
115
 
 
116
 
        providers=`cat $reg_file 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 3-4 | sort | uniq`
117
 
        set -- $providers
118
 
        while test x$1 != x
119
 
        do
120
 
cat >> $out_file <<EOF
121
 
instance of PG_Provider
122
 
{
123
 
   Name = "$1";
124
 
   ProviderModuleName = "$2";
125
 
};
126
 
 
127
 
EOF
128
 
                shift 2
129
 
        done
130
 
 
131
 
}
132
 
 
133
 
 
134
 
pegasus_add_capability ()
135
 
{
136
 
        mof_file=$1
137
 
        reg_file=$2
138
 
        out_file=$REGFILE
139
 
 
140
 
        capid=0
141
 
        cat $reg_file | grep -v '^[[:space:]]*#.*' | \
142
 
        while read classname namespace providername providermodule types
143
 
        do
144
 
                capid=`expr $capid + 1`
145
 
                provider_types=""
146
 
                type_no=0
147
 
                for type in $types; do
148
 
                        case $type in
149
 
                                instance)    type_no=2;;
150
 
                                association) type_no=3;;
151
 
                                indication)  type_no=4;;
152
 
                                method)      type_no=5;;
153
 
                                *)           echo "Unknown provider type: $type"
154
 
                                             exit;;
155
 
                        esac
156
 
                        if test "x$provider_types" = "x"; then
157
 
                                provider_types="$type_no"
158
 
                        else
159
 
                                provider_types="$provider_types, $type_no" 
160
 
                        fi
161
 
                done  # for
162
 
 
163
 
cat >> $out_file << EOF
164
 
instance of PG_ProviderCapabilities
165
 
{
166
 
   ProviderModuleName = "$providermodule";
167
 
   ProviderName = "$providername";
168
 
   ClassName = "$classname";
169
 
   ProviderType = { $provider_types };
170
 
   Namespaces = {"$namespace"};
171
 
   SupportedProperties = NULL;
172
 
   SupportedMethods = NULL;
173
 
   CapabilityID = "$capid";
174
 
};
175
 
 
176
 
EOF
177
 
        done  # while
178
 
 
179
 
}
180
 
 
181
 
pegasus_register ()
182
 
{
183
 
        mof_file=$1
184
 
        reg_file=$2
185
 
 
186
 
        if ps -C cimserver > /dev/null 2>&1
187
 
        then
188
 
                CIMMOF=cimmof
189
 
                state=active
190
 
        else
191
 
                CIMMOF=cimmofl
192
 
                PEGASUSREPOSITORY="/opt/tog-pegasus/repository"
193
 
                CIMMOF="$CIMMOF -R $PEGASUSREPOSITORY"
194
 
                state=inactive
195
 
        fi
196
 
 
197
 
        pegasus_add_module $mof_file $reg_file
198
 
        pegasus_add_provider $mof_file $reg_file
199
 
        pegasus_add_capability $mof_file $reg_file
200
 
 
201
 
        $CIMMOF -n root/cimv2 $mof_file
202
 
        $CIMMOF -n root/PG_Interop $REGFILE
203
 
}
204
 
 
205
 
pegasus_unregister ()
206
 
{
207
 
        echo "FixME"
208
 
        exit
209
 
}
210
 
 
211
 
 
212
 
#---------- sfcb functions -------------------------------------------
213
 
sfcb_transform ()
214
 
{
215
 
        old_file=$1
216
 
        new_file=$2
217
 
 
218
 
        cat $old_file | grep -v '^[[:space:]]*#.*' | \
219
 
        while read classname namespace providername providermodule types
220
 
        do
221
 
cat >> $new_file <<EOF
222
 
[$classname]
223
 
    provider: $providername
224
 
    location: $providermodule
225
 
    type: $types
226
 
    namespace: $namespace
227
 
 
228
 
EOF
229
 
        done
230
 
 
231
 
 
232
 
}
233
 
 
234
 
sfcb_running_check () 
235
 
{
236
 
        ps -C sfcbd > /dev/null 2>&1
237
 
        if [ $? -eq 0 ];
238
 
        then
239
 
                echo "sfcbd is running, please stop it first."
240
 
                exit
241
 
        fi
242
 
}
243
 
 
244
 
sfcb_register () 
245
 
{
246
 
        mof_file=$1
247
 
        reg_file=$2
248
 
        
249
 
        sfcb_running_check
250
 
 
251
 
        new_reg_file=/tmp/`basename $2`.reg
252
 
        sfcb_transform $reg_file $new_reg_file  
253
 
 
254
 
        ## register
255
 
        echo register to sfcb ...
256
 
        sfcbstage -r $new_reg_file $mof_file
257
 
        
258
 
        if [ $? -eq 1 ]; then
259
 
                echo failed to register, exit
260
 
                exit
261
 
        fi
262
 
 
263
 
        echo rebuild sfcb repository ...
264
 
        sfcbrepos -f
265
 
        if [ $? -eq 1 ]; then
266
 
                echo failed to rebuild sfcb, exit
267
 
                exit
268
 
        fi
269
 
 
270
 
        rm -rf $new_reg_file 
271
 
272
 
 
273
 
sfcb_unregister () 
274
 
{
275
 
        mof_file=$1
276
 
        reg_file=$2
277
 
 
278
 
        sfcb_running_check
279
 
 
280
 
        new_reg_file=/tmp/`basename $2`.reg
281
 
 
282
 
        sfcb_transform $reg_file $new_reg_file
283
 
 
284
 
        ## register
285
 
        echo unregister to sfcb ...
286
 
        sfcbunstage -r $new_reg_file $mof_file
287
 
 
288
 
        if [ $? -eq 1 ]; then
289
 
                echo failed to unregister, exit
290
 
                exit
291
 
        fi
292
 
 
293
 
        echo rebuild sfcb repository ...
294
 
        sfcbrepos -f
295
 
        if [ $? -eq 1 ]; then
296
 
                echo failed to rebuild sfcb, exit
297
 
                exit
298
 
        fi
299
 
 
300
 
        rm -rf $new_reg_file
301
 
}
302
 
 
303
 
#========== main ============================================
304
 
 
305
 
mof_file=""
306
 
reg_file=""
307
 
unregister="no"
308
 
cimom=""
309
 
 
310
 
usage () {
311
 
        echo "usage: $0 [-t cimserver] [-u] -r regfile -m mof"
312
 
        echo $'\t'-t cimserver: specify cimserver "[pegasus|openwbem|sfcb]".
313
 
        echo $'\t'-u: Unregister 
314
 
        echo $'\t'-r regfile: specify reg file.
315
 
        echo $'\t'-m moffile: specify mof file. 
316
 
 
317
 
        exit 0
318
 
}
319
 
 
320
 
args=`getopt hut:r:m: $*`
321
 
 
322
 
 
323
 
if test $? != 0; then
324
 
        usage
325
 
fi
326
 
 
327
 
while [ -n "$1" ]; do
328
 
        case $1 in
329
 
                -h) usage;;
330
 
                -u) unregister="yes"
331
 
                    shift;;
332
 
                -t) shift
333
 
                    if test "x$cimom" = "x"; then
334
 
                        cimom=$1
335
 
                    else
336
 
                        echo CIM server already set, ignore [$1]
337
 
                    fi
338
 
                    shift;;
339
 
                -m) shift
340
 
                    if test "x$mof_file" = "x"; then
341
 
                        mof_file=$1
342
 
                    else
343
 
                        echo MOF file already set, ignore [$1]
344
 
                    fi
345
 
                    shift;;
346
 
                -r) shift
347
 
                    if test "x$reg_file" = "x"; then
348
 
                        reg_file=$1
349
 
                    else
350
 
                        echo Reg file already set, ignore [$1]
351
 
                    fi
352
 
                    shift;;
353
 
                --) break;;
354
 
        esac
355
 
done
356
 
 
357
 
 
358
 
if test "x$unregister" != "xyes"; then
359
 
echo registering providers ...
360
 
else
361
 
echo unregistering providers ...
362
 
fi
363
 
 
364
 
echo CIM Server: $cimom
365
 
echo mof file  :  $mof_file
366
 
echo registration file  :  $reg_file
367
 
 
368
 
case $cimom in
369
 
        pegasus) ;;
370
 
        sfcb)    ;;
371
 
        openwbem);;
372
 
        *)  usage;;
373
 
esac
374
 
 
375
 
REG_FUNC=${cimom}_register
376
 
UNREG_FUNC=${cimom}_unregister
377
 
 
378
 
if test "x$unregister" != "xyes"; then
379
 
        $REG_FUNC $mof_file $reg_file
380
 
else
381
 
        $UNREG_FUNC $mof_file $reg_file
382
 
fi
383
 
 
384
 
 
385
 
#============== end of file =======================================