os-cmpi-xen

view provider-register.sh @ 1:bdf24cd56bed

Initial change to make the provider work with libvirt and openwbem.
author jfehlig@jfehlig1.provo.novell.com
date Wed Apr 26 12:28:36 2006 -0600 (2006-04-26)
parents 72b83cde6b72
children 6137ddada5ca
line source
1 #!/bin/sh
2 # $Id: provider-register.sh,v 1.7 2006/01/04 06:49:46 bestor Exp $
3 # ==================================================================
4 # (C) Copyright IBM Corp. 2006
5 #
6 # THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
7 # ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
8 # CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
9 #
10 # You can obtain a current copy of the Common Public License from
11 # http://www.opensource.org/licenses/cpl1.0.php
12 #
13 # Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
14 # Contributors:
15 # Description: Script to install class definitions (MOFs) and
16 # registration data for a variety of supported CIMOMs
17 # ==================================================================
19 pegasus_repository()
20 {
21 for p in $PEGASUS_HOME /var/lib/Pegasus /var/lib/pegasus /usr/local/var/lib/pegasus \
22 /var/local/lib/pegasus /var/opt/tog-pegasus
23 do
24 if test -d $p/repository
25 then
26 echo $p/$1
27 return 0
28 fi
29 done
30 return 1
31 }
33 pegasus_path()
34 {
35 for p in $PEGASUS_HOME/bin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin \
36 /opt/tog-pegasus/bin /opt/tog-pegasus/sbin
37 do
38 if test -x $p/$1
39 then
40 echo $p/$1
41 return 0
42 fi
43 done
44 return 1
45 }
47 pegasus_transform()
48 {
49 OUTFILE=$1
50 shift
51 regfiles=$*
52 PROVIDERMODULES=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
53 if test x"$PROVIDERMODULES" = x
54 then
55 echo Failed to read registration files >&2
56 return 1
57 fi
58 PROVIDERS=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 3-4 | sort | uniq`
60 # produce ProviderModules
61 echo > $OUTFILE
62 chatter "Processing provider modules:" $PROVIDERMODULES
63 for pm in $PROVIDERMODULES
64 do
65 cat >> $OUTFILE <<EOFPM
66 instance of PG_ProviderModule
67 {
68 Name = "$pm";
69 Location = "$pm";
70 Vendor = "SBLIM";
71 Version = "2.0.0";
72 InterfaceType = "CMPI";
73 InterfaceVersion = "2.0.0";
74 };
76 EOFPM
77 done
79 # produce Providers
80 set -- $PROVIDERS
81 while test x$1 != x
82 do
83 cat >> $OUTFILE <<EOFP
84 instance of PG_Provider
85 {
86 Name = "$1";
87 ProviderModuleName = "$2";
88 };
90 EOFP
91 shift 2
92 done
94 #produce Capabilities
95 let serial=0
96 for rf in $regfiles
97 do
98 cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
99 do
100 let serial=serial+1
101 numcap=
102 for cap in $CAPS
103 do
104 case $cap in
105 instance)
106 if test x$numcap = x
107 then numcap=2
108 else numcap="$numcap,2"
109 fi;;
110 association)
111 if test x$numcap = x
112 then numcap=3
113 else numcap="$numcap,3"
114 fi;;
115 indication)
116 if test x$numcap = x
117 then numcap=4
118 else numcap="$numcap,4"
119 fi;;
120 method)
121 if test x$numcap = x
122 then numcap=5
123 else numcap="$numcap,5"
124 fi;;
125 **) echo unknown provider type $cap >&2
126 return 1;;
127 esac
128 done
129 cat >> $OUTFILE <<EOFC
130 instance of PG_ProviderCapabilities
131 {
132 ProviderModuleName = "$PROVIDERMODULE";
133 ProviderName = "$PROVIDERNAME";
134 ClassName = "$CLASSNAME";
135 ProviderType = { $numcap };
136 Namespaces = {"$NAMESPACE"};
137 SupportedProperties = NULL;
138 SupportedMethods = NULL;
139 CapabilityID = "$CLASSNAME-$serial";
140 };
142 EOFC
143 done
144 done
145 }
147 pegasus_install()
148 {
149 if ps -C cimserver > /dev/null 2>&1
150 then
151 CIMMOF=`pegasus_path cimmof`
152 if test $? != 0
153 then
154 echo "Error: cimmof not found" >&2
155 return 1
156 fi
157 state=active
158 else
159 CIMMOF=`pegasus_path cimmofl`
160 if test $? != 0
161 then
162 echo "Error: cimmofl not found" >&2
163 return 1
164 fi
165 PEGASUSREPOSITORY=`pegasus_repository`
166 if test $? != 0
167 then
168 echo "Error: pegasus repository not found" >&2
169 return 1
170 fi
171 CIMMOF="$CIMMOF -R $PEGASUSREPOSITORY"
172 state=inactive
173 fi
175 mofpath=
176 mymofs=
177 mregs=
178 mofmode=1
179 while test x$1 != x
180 do
181 if test $1 = ":"
182 then
183 mofmode=0
184 shift
185 continue
186 fi
187 if test $mofmode = 1
188 then
189 if test x$mofpath = x
190 then
191 mofpath=`dirname $1`
192 fi
193 mymofs="$mymofs $1"
194 else
195 myregs="$myregs $1"
196 fi
197 shift
198 done
200 for _TEMPDIR in /var/tmp /tmp
201 do
202 if test -w $_TEMPDIR
203 then
204 _REGFILENAME=$_TEMPDIR/$$.mof
205 break
206 fi
207 done
210 trap "rm -f $_REGFILENAME" EXIT
212 if pegasus_transform $_REGFILENAME $myregs
213 then
214 chatter Registering providers with $state cimserver
215 $CIMMOF -uc -I $mofpath -n root/cimv2 $mymofs &&
216 $CIMMOF -uc -n root/PG_Interop $_REGFILENAME
217 else
218 echo "Failed to build pegasus registration MOF." >&2
219 return 1
220 fi
221 }
223 pegasus_uninstall()
224 {
225 mymofs=
226 mregs=
227 mofmode=1
228 while test x$1 != x
229 do
230 if test $1 = ":"
231 then
232 mofmode=0
233 shift
234 continue
235 fi
236 if test $mofmode = 1
237 then
238 mymofs="$mymofs $1"
239 else
240 myregs="$myregs $1"
241 fi
242 shift
243 done
245 if ps -C cimserver > /dev/null 2>&1
246 then
247 PROVIDERMODULES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
248 if test x"$PROVIDERMODULES" = x
249 then
250 echo Failed to read registration files >&2
251 return 1
252 fi
253 CIMPROVIDER=`pegasus_path cimprovider`
254 if test $? != 0
255 then
256 echo "Error: cimprovider not found" >&2
257 return 1
258 fi
259 for pm in $PROVIDERMODULES
260 do
261 chatter "Remove provider module" $pm
262 $CIMPROVIDER -d -m $pm > /dev/null &&
263 $CIMPROVIDER -r -m $pm > /dev/null
264 done
265 WBEMEXEC=`pegasus_path wbemexec`
266 if test $? != 0
267 then
268 echo "Error: wbemexec not found" >&2
269 return 1
270 fi
271 CLASSES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 1 | grep -v '^CIM_'`
272 for cls in $CLASSES
273 do
274 chatter Delete CIM Class $cls
275 $WBEMEXEC > /dev/null <<EOFWX
276 <?xml version="1.0" encoding="utf-8" ?>
277 <CIM CIMVERSION="2.0" DTDVERSION="2.0">
278 <MESSAGE ID="4711" PROTOCOLVERSION="1.0">
279 <SIMPLEREQ>
280 <IMETHODCALL NAME="DeleteClass">
281 <LOCALNAMESPACEPATH>
282 <NAMESPACE NAME="root"></NAMESPACE>
283 <NAMESPACE NAME="cimv2"></NAMESPACE>
284 </LOCALNAMESPACEPATH>
285 <IPARAMVALUE NAME="ClassName">
286 <CLASSNAME NAME="$cls"/>
287 </IPARAMVALUE>
288 </IMETHODCALL>
289 </SIMPLEREQ>
290 </MESSAGE>
291 </CIM>
292 EOFWX
293 done
294 else
295 echo "Sorry, cimserver must be running to deregister the providers." >&2
296 return 1
297 fi
298 }
300 sfcb_transform()
301 {
302 OUTFILE=$1
303 shift
304 regfiles=$*
306 #produce sfcb registraion
307 for rf in $regfiles
308 do
309 cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
310 do
311 chatter "Registering class" $CLASSNAME
312 cat >> $OUTFILE <<EOFC
313 [$CLASSNAME]
314 provider: $PROVIDERNAME
315 location: $PROVIDERMODULE
316 type: $CAPS
317 namespace: $NAMESPACE
318 #
319 EOFC
320 done
321 done
322 }
324 sfcb_rebuild()
325 {
326 if ps -C sfcbd > /dev/null 2>&1
327 then
328 # sfcb is running -- need to restart
329 for INITSCRIPT in /etc/init.d/sfcb /usr/local/etc/init.d/sfcb none
330 do
331 if test -x $INITSCRIPT
332 then
333 break;
334 fi
335 done
336 chatter "Shutting down sfcb."
337 if test $INITSCRIPT = none
338 then
339 killall sfcbd
340 else
341 $INITSCRIPT stop
342 fi
343 t=0
344 while ps -C sfcbd > /dev/null 2>&1
345 do
346 sleep 1
347 t=`expr $t + 1`
348 if test $t -gt 10
349 then
350 echo "Timed out waiting for sfcb shutdown..." >&2
351 echo "Please stop sfcb manually and rebuild the repository using sfcbrepos." >&2
352 return 1
353 fi
354 done
355 chatter "Rebuilding repository."
356 sfcbrepos -f
357 if test $? != 0
358 then
359 echo "Repository rebuild failed." >&2
360 return 1
361 fi
363 if test $INITSCRIPT = none
364 then
365 echo "No init script found - you need to start sfcbd manually." >&2
366 return 1
367 else
368 chatter "Restarting sfcb."
369 $INITSCRIPT start
370 fi
371 else
372 # Not running - rebuild repository
373 chatter "Rebuilding repository."
374 sfcbrepos -f
375 fi
376 }
378 sfcb_install()
379 {
380 mymofs=
381 mregs=
382 mofmode=1
383 while test x$1 != x
384 do
385 if test $1 = ":"
386 then
387 mofmode=0
388 shift
389 baseregname=`basename $1 .registration`
390 continue
391 fi
392 if test $mofmode = 1
393 then
394 mymofs="$mymofs $1"
395 else
396 myregs="$myregs $1"
397 fi
398 shift
399 done
401 for _TEMPDIR in /var/tmp /tmp
402 do
403 if test -w $_TEMPDIR
404 then
405 _REGFILENAME=$_TEMPDIR/$baseregname.reg
406 break
407 fi
408 done
410 trap "rm -f $_REGFILENAME" EXIT
412 if sfcb_transform $_REGFILENAME $myregs
413 then
414 chatter "Staging provider registration."
415 sfcbstage -r $_REGFILENAME $mymofs
416 if test $? != 0
417 then
418 echo "Failed to stage provider registration." >&2
419 return 1
420 fi
421 sfcb_rebuild
422 else
423 echo "Failed to build sfcb registration file." >&2
424 return 1
425 fi
426 }
428 sfcb_uninstall()
429 {
430 mymofs=
431 while test x$1 != x
432 do
433 if test $1 = ":"
434 then
435 shift
436 baseregname=`basename $1 .registration`
437 break
438 fi
439 mymofs="$mymofs `basename $1`"
440 shift
441 done
443 # "Unstage" MOFs and the registration file
444 chatter "Unstaging provider registrations."
445 sfcbunstage -r $baseregname.reg $mymofs
447 # Rebuild repository
448 sfcb_rebuild
449 }
451 openwbem_transform()
452 {
453 OUTFILE=$1
454 shift
455 moffiles=$*
457 if rm -f $OUTFILE
458 then
459 for _f in $moffiles
460 do
461 sed "s/Provider *( *\"cmpi:/Provider(\"cmpi::/g" < $_f >> $OUTFILE
462 done
463 fi
464 }
466 openwbem_repository()
467 {
468 for p in /var/lib/openwbem /usr/local/var/openwbem
469 do
470 if test -f $p/schema.dat
471 then
472 echo $p
473 return 0
474 fi
475 done
476 return 1
477 }
479 openwbem_install()
480 {
481 CIMMOF=`which owmofc 2> /dev/null`
482 if test $? != 0
483 then
484 echo "Error: cimmof not found" >&2
485 return 1
486 fi
488 if ps -C owcimomd > /dev/null 2>&1
489 then
490 state=active
491 else
492 CIMMOF="$CIMMOF -d `openwbem_repository`"
493 if test $? != 0
494 then
495 echo "Error: OpenWBEM repository not found" >&2
496 return 1
497 fi
498 state=inactive
499 fi
501 if test -d /usr/share/mof/cim-current
502 then
503 CIMMOF="$CIMMOF -s /usr/share/mof/cim-current"
504 fi
506 for _TEMPDIR in /var/tmp /tmp
507 do
508 if test -w $_TEMPDIR
509 then
510 _REGFILENAME=$_TEMPDIR/$$.mof
511 break
512 fi
513 done
515 trap "rm -f $_REGFILENAME" EXIT
517 if openwbem_transform $_REGFILENAME $*
518 then
519 chatter Registering providers with $state owcimomd
520 $CIMMOF $_REGFILENAME > /dev/null
521 else
522 echo "Failed to build OpenWBEM registration MOF." >&2
523 return 1
524 fi
525 }
527 openwbem_uninstall()
528 {
529 CIMMOF=`which owmofc 2> /dev/null`
530 if test $? != 0
531 then
532 echo "Error: cimmof not found" >&2
533 return 1
534 fi
536 if ps -C owcimomd > /dev/null 2>&1
537 then
538 state=active
539 else
540 CIMMOF="$CIMMOF -d `openwbem_repository`"
541 if test $? != 0
542 then
543 echo "Error: OpenWBEM repository not found" >&2
544 return 1
545 fi
546 state=inactive
547 fi
549 for _TEMPDIR in /var/tmp /tmp
550 do
551 if test -w $_TEMPDIR
552 then
553 _REGFILENAME=$_TEMPDIR/$$.mof
554 break
555 fi
556 done
558 trap "rm -f $_REGFILENAME" EXIT
560 if openwbem_transform $_REGFILENAME $*
561 then
562 chatter Deregistering providers with $state owcimomd
563 $CIMMOF -r $_REGFILENAME > /dev/null
564 else
565 echo "Failed to build OpenWBEM registration MOF." >&2
566 return 1
567 fi
568 }
570 cim_server()
571 {
572 for exname in sfcbd cimserver owcimomd
573 do
574 if pegasus_path $exname > /dev/null
575 then
576 case $exname in
577 sfcbd) echo sfcb; return 0;;
578 cimserver) echo pegasus; return 0;;
579 owcimomd) echo openwbem; return 0;;
580 esac
581 break;
582 fi
583 done
584 echo unknown
585 return 1
586 }
588 usage()
589 {
590 echo "usage: $0 [-h] [-v] [-d] [-t <cimserver>] -r regfile ... -m mof ..."
591 }
593 chatter()
594 {
595 if test x$verbose != x
596 then
597 echo $*
598 fi
599 }
601 gb_getopt()
602 {
603 rmode=0
604 mmode=0
605 options=
606 moffiles=
607 registrations=
608 while [ -n "$1" ]
609 do
610 case $1 in
611 -r) mmode=0;
612 rmode=1;
613 shift;;
614 -m) mmode=1;
615 rmode=0;
616 shift;;
617 -*) mmode=0;
618 rmode=0;
619 options="$options $1";
620 shift;;
621 **) if [ $mmode = 1 ]
622 then moffiles="$moffiles $1"
623 elif [ $rmode = 1 ]
624 then registrations="$registrations -r $1"
625 else options="$options $1";
626 fi;
627 shift;;
628 esac
629 done
630 echo $options $registrations $moffiles
631 }
633 prepargs=`gb_getopt $*`
634 args=`getopt dvht:r: $prepargs`
635 rc=$?
637 if [ $rc = 127 ]
638 then
639 echo "warning: getopt not found ...continue without syntax check"
640 args=$prepargs
641 elif [ $rc != 0 ]
642 then
643 usage $0
644 exit 1
645 fi
647 set -- $args
649 while [ -n "$1" ]
650 do
651 case $1 in
652 -h) help=1;
653 shift;
654 break;;
655 -v) verbose=1;
656 shift;;
657 -d) deregister=1;
658 shift;;
659 -t) cimserver=$2;
660 shift 2;;
661 -r) regs="$regs $2";
662 shift 2;;
663 --) shift;
664 break;;
665 **) break;;
666 esac
667 done
669 mofs=$*
671 if [ "$help" = "1" ]
672 then
673 usage
674 echo -e "\t-h display help message"
675 echo -e "\t-v verbose mode"
676 echo -e "\t-d deregister provider and uninstall schema"
677 echo -e "\t-t specify cimserver type (pegasus|sfcb|openwbem|sniacimom)"
678 echo -e "\t-r specify registration files"
679 echo -e "\t-m specify schema mof files"
680 echo
681 echo Use this command to install schema mofs and register providers.
682 echo CIM Server Type is required as well as at least one registration file and one mof.
683 exit 0
684 fi
686 if test x"$mofs" = x || test x"$regs" = x
687 then
688 usage $0
689 exit 1
690 fi
692 if test x$cimserver = x
693 then
694 cimserver=`cim_server`
695 if test $? = 0
696 then
697 chatter "Autoselected CIM server type:" $cimserver
698 else
699 echo "CIM server type could not be determined, specify with -t." >&2
700 exit 1
701 fi
702 fi
704 if test x$deregister = x
705 then
706 case $cimserver in
707 pegasus) pegasus_install $mofs ":" $regs;;
708 sfcb) sfcb_install $mofs ":" $regs;;
709 openwbem) openwbem_install $mofs ;;
710 sniacimom) echo sniacimom not yet supported && exit 1 ;;
711 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
712 esac
713 else
714 case $cimserver in
715 pegasus) pegasus_uninstall $mofs ":" $regs;;
716 sfcb) sfcb_uninstall $mofs ":" $regs;;
717 openwbem) openwbem_uninstall $mofs ;;
718 sniacimom) echo sniacimom not yet supported && exit 1 ;;
719 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
720 esac
721 fi