-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsrvctl_12.2.bash
More file actions
2275 lines (1919 loc) · 47.5 KB
/
srvctl_12.2.bash
File metadata and controls
2275 lines (1919 loc) · 47.5 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# bash completion support for srvctl 12.1.0.2.0
# vim: ts=4:sw=4:filetype=sh:cc=81
# Copyright © 2016,2017 Philippe Leroux <philippe.lrx@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ============================================================================
# Pour mémo :
# COMP_WORDS is an array of words in the current command line.
# COMP_CWORD is the index of the current word in the command line.
# COMPREPLY is a list of replies.
# ============================================================================
# ============================================================================
# Functions for debug
# Work only with : export SRVCTL_LOG=yes
function _srvctl_log
{
if [ "$SRVCTL_LOG" == yes ]
then # One log per user.
typeset log_name=/tmp/srvctl_completion_${USER}.log
if [ "$1" == "-n" ]
then
echo -n "${@:2}" >> $log_name
else
echo "$@" >> $log_name
fi
fi
}
# ============================================================================
# Tools functions
# return 0 if $1 is a function, else return 1
function _function_exists
{
[ "$(type -t "$1")" == "function" ] && return 0 || return 1
}
# print the number of nodes to stdout
function _count_nodes
{
wc -l<<<"$(olsnodes)"
}
# return 0 if cluster, 1 if standalone server
function _is_cluster
{
test $(_count_nodes) -gt 1
}
# print to stdout dbname or empty string if not found.
function _get_dbname
{
for i in $( seq $ifirstoption ${#COMP_WORDS[@]} )
do
case "${COMP_WORDS[i]}" in
-db|-database)
if [ x"${COMP_WORDS[i+1]}" == x ]
then # no name after -db|-database
echo ""
else
echo "${COMP_WORDS[i+1]}"
fi
return
;;
esac
done
# -db|-database not found.
echo ""
}
# return 0 if $1 is used in COMP_WORDS, else return 1
function _option_is_used
{
typeset -r opt="$1"
typeset i
for i in $( seq $ifirstoption ${#COMP_WORDS[@]} )
do
[ "$opt" == "${COMP_WORDS[i]}" ] && return 0 || true
done
return 1 # not found
}
# ============================================================================
# build the reply : COMPREPLY is set.
function _reply
{
COMPREPLY=( $( compgen -W "$@" -- ${COMP_WORDS[COMP_CWORD]} ) )
}
# ============================================================================
# Functions to build objects for a command
# Generated by script : all_objects_for_cmd.sh
# Built object_list for current command
# srvctl version: 12.1.0.2.0
function _build_object_list_cluster
{
case "$command" in
relocate)
typeset -g object_list="database service server vip scan scan_listener oc4j rhpserver rhpclient gns cvu mgmtdb filesystem asm havip"
;;
downgrade)
typeset -g object_list="database"
;;
export)
typeset -g object_list="gns"
;;
stop)
typeset -g object_list="database instance service nodeapps vip asm listener scan scan_listener oc4j rhpserver rhpclient havip exportfs home filesystem volume diskgroup gns cvu mgmtdb mgmtlsnr mountfs"
;;
import)
typeset -g object_list="gns"
;;
add)
typeset -g object_list="database instance service service nodeapps vip network asm listener scan scan_listener srvpool oc4j rhpserver rhpclient havip exportfs filesystem gns cvu mgmtdb mgmtlsnr mountfs"
;;
start)
typeset -g object_list="database instance service nodeapps vip asm listener scan scan_listener oc4j rhpserver rhpclient havip exportfs home filesystem volume diskgroup gns cvu mgmtdb mgmtlsnr mountfs"
;;
status)
typeset -g object_list="database instance service nodeapps vip listener asm scan scan_listener srvpool server oc4j rhpserver rhpclient home filesystem volume diskgroup cvu gns mgmtdb mgmtlsnr exportfs havip mountfs"
;;
remove)
typeset -g object_list="database instance service nodeapps vip network asm listener scan scan_listener srvpool oc4j rhpserver rhpclient havip exportfs filesystem diskgroup gns cvu mgmtdb mgmtlsnr mountfs"
;;
config)
typeset -g object_list="database service nodeapps vip network asm listener scan scan_listener srvpool oc4j rhpserver rhpclient filesystem volume gns cvu exportfs mgmtdb mgmtlsnr mountfs"
;;
predict)
typeset -g object_list="database service asm diskgroup filesystem vip network listener scan scan_listener oc4j"
;;
unsetenv)
typeset -g object_list="database nodeapps vip listener asm mgmtdb mgmtlsnr"
;;
upgrade)
typeset -g object_list="database"
;;
setenv)
typeset -g object_list="database nodeapps vip listener asm mgmtdb mgmtlsnr"
;;
enable)
typeset -g object_list="database instance service asm listener nodeapps vip scan scan_listener oc4j rhpserver rhpclient filesystem volume diskgroup gns cvu mgmtdb mgmtlsnr exportfs havip mountfs"
;;
disable)
typeset -g object_list="database instance service asm listener nodeapps vip scan scan_listener oc4j rhpserver rhpclient filesystem volume diskgroup gns cvu mgmtdb mgmtlsnr exportfs havip mountfs"
;;
convert)
typeset -g object_list="database database"
;;
getenv)
typeset -g object_list="database nodeapps vip listener asm mgmtdb mgmtlsnr"
;;
modify)
typeset -g object_list="database instance service service service service asm nodeapps listener network scan scan_listener srvpool oc4j rhpserver rhpclient filesystem gns cvu mgmtdb mgmtlsnr exportfs havip mountfs"
;;
update)
typeset -g object_list="listener scan_listener database mgmtdb instance gns"
;;
*)
_srvctl_log "$command not supported."
typeset -g object_list=""
esac
}
# Generated by script : all_objects_for_cmd.sh
# Built object_list for current command
# srvctl version: 12.1.0.2.0
function _build_object_list_standalone
{
case "$command" in
downgrade)
typeset -g object_list="database"
;;
stop)
typeset -g object_list="database service asm listener diskgroup ons home"
;;
add)
typeset -g object_list="database service asm listener ons"
;;
start)
typeset -g object_list="database service asm listener diskgroup ons home"
;;
status)
typeset -g object_list="database service asm listener diskgroup ons home"
;;
remove)
typeset -g object_list="database service asm listener diskgroup ons"
;;
config)
typeset -g object_list="database service asm listener ons"
;;
unsetenv)
typeset -g object_list="database asm listener"
;;
upgrade)
typeset -g object_list="database"
;;
setenv)
typeset -g object_list="database asm listener"
;;
enable)
typeset -g object_list="database service asm listener diskgroup ons"
;;
disable)
typeset -g object_list="database service asm listener diskgroup ons"
;;
getenv)
typeset -g object_list="database asm listener"
;;
modify)
typeset -g object_list="database service asm listener ons"
;;
update)
typeset -g object_list="database"
;;
*)
_srvctl_log "$command not supported."
typeset -g object_list=""
esac
}
# init global variable object_list with all objects for the current command.
# reply with object_list
function _reply_with_object_list
{
if _is_cluster
then
_build_object_list_cluster
else
_build_object_list_standalone
fi
_reply "$object_list"
}
# ============================================================================
# Function to do a reply with a set of options.
# $@ option_list
# print to stdout option_list with used options removed.
function _remove_used_options
{
typeset option_list="$@"
for i in $( seq $ifirstoption ${#COMP_WORDS[@]} )
do
if [[ x"${COMP_WORDS[i]}" != x && $i -ne $COMP_CWORD
&& "$option_list" == *"${COMP_WORDS[i]}"* ]]
then
option_list=${option_list/${COMP_WORDS[i]}/}
fi
done
echo $option_list
}
# Ex : srvctl stop service -db db_name [-node | -instance]
# You can use -node or -instance, together it's an error.
#
# $1 list options
# print new list options to stdout.
function _remove_exclusive_options
{
typeset option_list="$@"
typeset -A exclusive_options
exclusive_options+=( [list_1]="-db -serverpool -thisversion -thishome" )
exclusive_options+=( [list_2]="-instance -node" )
exclusive_options+=( [list_3]="-all -netnum -scannumber" )
#BUG -service and -startoption valid together, remove list_4.
#exclusive_options+=( [list_4]="-service -startoption" )
exclusive_options+=( [list_5]="-listener -asmlistener -leaflistener" )
exclusive_options+=( [list_6]="-env -envs" ) # order is important.
typeset -r cur_word="${COMP_WORDS[COMP_CWORD]}"
for id in ${!exclusive_options[@]}
do
typeset exclu_opt_list=${exclusive_options[$id]}
typeset option
for option in $exclu_opt_list
do
if [ "$option" != "$cur_word" ] && _option_is_used "$option"
then
typeset o2r # option to removed.
for o2r in ${exclu_opt_list/$option/}
do # cannot use option $o2r with $option, remove it.
option_list=${option_list/$o2r/}
done
break
fi
done
done
echo "$option_list"
}
# $1 option_list
# before to reply :
# - remove options already in use.
# - remove incompatible options.
#
# Callback functions on command should use this function, not _reply. Else
# completion never stop.
function _reply_with_options
{
typeset option_list="$@"
if [ $COMP_CWORD -ne $ifirstoption ]
then
# Call order is important !
option_list="$(_remove_exclusive_options $option_list)"
option_list="$(_remove_used_options $option_list)"
fi
_reply "$option_list"
}
# ============================================================================
# Callback functions : _reply_with_[option]_list (option without dash)
# Return values for an option or nothing if user must provide a value.
# All this functions are called by _reply_for_option.
function _reply_with_database_list
{
_reply "$(crsctl stat res |\
grep "\.db$" |\
sed "s/NAME=ora\.\(.*\).db/\1/g" |\
xargs)"
}
function _reply_with_diskgroup_list
{
_reply "$(crsctl stat res |\
grep -E "ora.*.dg$" |\
sed "s/NAME=ora.\(.*\).dg/\1/g" |\
xargs)"
}
function _reply_with_listener_list
{
# For RAC database we must exclude listener for scan vips.
_reply "$(crsctl stat res |\
grep -E "NAME=ora.*.lsnr$" |\
grep -v "SCAN" |\
sed "s/NAME=ora.\(.*\).lsnr/\1/g" |\
xargs)"
}
function _reply_with_oraclehome_list
{
_reply "$(cat /etc/oratab |\
grep -E "^(\+|[A-Z])" |\
sed "s/.*:\(.*\):[Y|N].*/\1/g" |\
xargs)"
}
function _reply_with_vip_list
{
_reply "$(crsctl stat res |\
grep -E "NAME=ora.*.vip$" |\
grep -v "scan" |\
sed "s/NAME=ora.\(.*\).vip/\1/g" |\
xargs)"
}
function _reply_with_netnum_list
{
_reply "{1..$(crsctl stat res|grep -E "\.network$"|wc -l)}"
}
function _reply_with_scannumber_list
{
_reply "1 2 3"
}
function _reply_all_node_numbers
{
_reply "{1..$(_count_nodes)}"
}
alias _reply_with_startconcurrency_list=_reply_all_node_numbers
alias _reply_with_stopconcurrency_list=_reply_all_node_numbers
function _reply_with_node_list
{
_reply "$(olsnodes | xargs)"
}
alias _reply_with_preferred_list=_reply_with_node_list
alias _reply_with_available_list=_reply_with_node_list
alias _reply_with_servers_list=_reply_with_node_list
alias _reply_with_server_list=_reply_with_node_list
alias _reply_with_targetnode_list=_reply_with_node_list
alias _reply_with_currentnode_list=_reply_with_node_list
alias _reply_with_oldinst_list=_reply_with_node_list
alias _reply_with_newinst_list=_reply_with_node_list
alias _reply_with_homenode_list=_reply_with_node_list
function _reply_with_service_list
{
typeset dbname=$(_get_dbname)
if [ x"$dbname" == x ]
then # return all services
_reply "$(crsctl stat res |\
grep -E "ora.*.svc$" |\
sed "s/NAME=ora\..*\.\(.*\)\.svc/\1/g" |\
xargs)"
else # return services for specified database.
typeset -r dbname=$(tr [:upper:] [:lower:]<<<"$dbname")
_reply "$(crsctl stat res |\
grep -E "ora.$dbname.*.svc$" |\
sed "s/NAME=ora\.${dbname}\.\(.*\)\.svc/\1/g" |\
xargs)"
fi
}
function _reply_with_instance_list
{
typeset -r dbname=$(_get_dbname)
if [ x"$dbname" == x ]
then
COMPREPLY=()
return 0
fi
if [ -v instance_list_cache ]
then
if [ $(( SECONDS - tt_instance_list_cache )) -lt $(( 60 * 2 )) ]
then
_reply "$instance_list_cache"
return 0
fi
# cache to old.
fi
typeset cmd="srvctl status database -db $dbname"
cmd="$cmd | sed 's/Instance \(.*\) is.*/\1/g' | xargs"
_srvctl_log "cmd='$cmd'"
typeset -g instance_list_cache="$(eval $cmd)"
typeset -gi tt_instance_list_cache=$SECONDS
_reply "$instance_list_cache"
}
function _reply_with_startoption_list
{
case "${COMP_WORDS[COMP_CWORD]}" in
"'"*) # word is like ' or 'r or 're or 'rea or 'read
COMPREPLY=( "'read only'" )
;;
*)
_reply "open mount \'read"
esac
}
function _reply_with_stopoption_list
{
_reply "normal transactional immediate abort"
}
# user must provide a value.
function _reply_wait_user_input
{
COMPREPLY=()
}
# For this options user must provide a value.
alias _reply_with_statefile_list=_reply_wait_user_input
alias _reply_with_volume_list=_reply_wait_user_input
alias _reply_with_device_list=_reply_wait_user_input
alias _reply_with_name_list=_reply_wait_user_input
alias _reply_with_id_list=_reply_wait_user_input
alias _reply_with_envs_list=_reply_wait_user_input
alias _reply_with_env_list=_reply_wait_user_input
alias _reply_with_failoverdelay_list=_reply_wait_user_input
alias _reply_with_failoverretry_list=_reply_wait_user_input
alias _reply_with_edition_list=_reply_wait_user_input
alias _reply_with_pdb_list=_reply_wait_user_input
alias _reply_with_maxlag_list=_reply_wait_user_input
alias _reply_with_sql_translation_profile_list=_reply_wait_user_input
alias _reply_with_retention_list=_reply_wait_user_input
alias _reply_with_replay_init_time_list=_reply_wait_user_input
alias _reply_with_pqservice_list=_reply_wait_user_input
alias _reply_with_pqpool_list=_reply_wait_user_input
alias _reply_with_gsmflags_list=_reply_wait_user_input
alias _reply_with_address_list=_reply_wait_user_input
alias _reply_with_subnet_list=_reply_wait_user_input
alias _reply_with_nettype_list=_reply_wait_user_input
alias _reply_with_pingtarget_list=_reply_wait_user_input
alias _reply_with_pwfile_list=_reply_wait_user_input
alias _reply_with_proxy_list=_reply_wait_user_input
alias _reply_with_timeout_list=_reply_wait_user_input
alias _reply_with_domain_list=_reply_wait_user_input
alias _reply_with_spfile_list=_reply_wait_user_input
alias _reply_with_dbname_list=_reply_wait_user_input
alias _reply_with_acfspath_list=_reply_wait_user_input
alias _reply_with_emport_list=_reply_wait_user_input
alias _reply_with_onslocalport_list=_reply_wait_user_input
alias _reply_with_onsremoteport_list=_reply_wait_user_input
alias _reply_with_remoteservers_list=_reply_wait_user_input
alias _reply_with_clientdata_list=_reply_wait_user_input
alias _reply_with_count_list=_reply_wait_user_input
alias _reply_with_endpoints_list=_reply_wait_user_input
alias _reply_with_invitednodes_list=_reply_wait_user_input
alias _reply_with_invitedsubnets_list=_reply_wait_user_input
alias _reply_with_scanname_list=_reply_wait_user_input
alias _reply_with_min_list=_reply_wait_user_input
alias _reply_with_max_list=_reply_wait_user_input
alias _reply_with_importance_list=_reply_wait_user_input
alias _reply_with_category_list=_reply_wait_user_input
alias _reply_with_storage_list=_reply_wait_user_input
alias _reply_with_network_number_list=_reply_wait_user_input
alias _reply_with_description_list=_reply_wait_user_input
alias _reply_with_path_list=_reply_wait_user_input
alias _reply_with_options_list=_reply_wait_user_input
alias _reply_with_clients_list=_reply_wait_user_input
alias _reply_with_user_list=_reply_wait_user_input
alias _reply_with_fsoptions_list=_reply_wait_user_input
alias _reply_with_appid_list=_reply_wait_user_input
alias _reply_with_auxvolumes_list=_reply_wait_user_input
alias _reply_with_checkinterval_list=_reply_wait_user_input
alias _reply_with_exportserver_list=_reply_wait_user_input
alias _reply_with_exportpath_list=_reply_wait_user_input
alias _reply_with_mountoptions_list=_reply_wait_user_input
alias _reply_with_dbtype_list=_reply_wait_user_input
alias _reply_with_rmiport_list=_reply_wait_user_input
alias _reply_with_httpport_list=_reply_wait_user_input
alias _reply_with_port_list=_reply_wait_user_input
alias _reply_with_resolve_list=_reply_wait_user_input
alias _reply_with_verify_list=_reply_wait_user_input
alias _reply_with_parameter_list=_reply_wait_user_input
function _reply_with_fstype_list
{
# Only for linux EXT. ?
_reply "ACFS EXT3 EXT4"
}
function _reply_with_autostart_list
{
_reply "ALWAYS NEVER RESTORE"
}
function _reply_with_serverpool_list
{
if [ -v serverpool_list_cache ]
then
if [ $(( SECONDS - tt_serverpool_list_cache )) -lt $(( 60 * 2 )) ]
then
_reply "$serverpool_list_cache"
return 0
fi
# cache to old.
fi
typeset -g serverpool_list_cache="$(srvctl status srvpool |\
grep "^Server pool name:" |\
awk '{ print $4 }' |\
xargs)"
typeset -gi tt_serverpool_list_cache=$SECONDS
_reply "$serverpool_list_cache"
}
function _reply_with_policy_list
{
_reply "automatic manual norestart"
}
function _reply_with_role_list
{
_reply "primary physical_standby logical_standby snapshot_standby far_sync"
}
function _reply_with_failovertype_list
{
_reply "none session select transaction"
}
function _reply_with_failovermethod_list
{
_reply "none basic"
}
function _reply_with_clbgoal_list
{
_reply "short long"
}
function _reply_with_rlbgoal_list
{
_reply "service_time throughput none"
}
function _reply_true_false
{
_reply "true false"
}
alias _reply_with_notification_list=_reply_true_false
alias _reply_with_global_list=_reply_true_false
alias _reply_with_commit_outcome_list=_reply_true_false
alias _reply_with_dtp_list=_reply_true_false
function _reply_with_session_state_list
{
_reply "static dynamic"
}
function _reply_with_cardinality_list
{
_reply "uniform singleton"
}
function _reply_with_tafpolicy_list
{
_reply "none basic preconnect"
}
function _reply_for_iptype_list
{
_reply "IPV4 IPV6 BOTH"
}
function _reply_with_loglevel_list
{
_reply "{1..6}"
}
# $1 option name, if not begin with a dash return 1.
#
# If a callback like _reply_with_[option]_list (the dash is removed) exist
# its called and return 0, if no callback exist return 1.
#
# -db is translated to -database and -s is translated to -service
function _reply_for_option
{
typeset option="$1"
[ "${option:0:1}" != "-" ] && return 1 || true
case $option in
-s)
option="-service"
;;
-db)
option="-database"
;;
esac
typeset cb_name="_reply_with_${option:1}_list"
case "$(type -t "$cb_name")" in
function)
:
;;
alias)
# if cb_name is an alias name the call don't work even with option
# shopt -s expand_aliases, work only when alias name called directly.
_srvctl_log "_reply_for_option : translate alias $cb_name"
cb_name=$(alias $cb_name |cut -d\' -f2)
;;
*)
_srvctl_log "_reply_for_option option $option not found"
return 1
;;
esac
_srvctl_log "_reply_for_option call : $cb_name"
$cb_name
return 0
}
# ============================================================================
# Callback functions for commands
# _reply_for_cmd_<command_name>
# _next_reply_for_cmd<command_name>
# only if generic function _next_reply_for_cmd is not suitable.
# reply for command status
function _reply_for_cmd_status
{
case "$object_name" in
database)
if _is_cluster
then
_reply_with_options "-db -serverpool -thisversion -thishome
-force -verbose"
else
# TODO : mettre à jour les exclusions :
# -home | -thisversion | -thishome
_reply_with_options "-db -sid -home -thisversion -thishome
-force -verbose"
fi
;;
instance)
_reply_with_options "-db -node -instance -force -verbose"
;;
service)
# TODO : mettre à jour les exclusions :
# -service | -pdb
_reply_with_options "-db -service -pdb -force -verbose"
;;
nodeapps)
_reply_with_options "-node"
;;
vip)
_reply_with_options "-node -vip -verbose"
;;
listener)
_reply_with_options "-listener -verbose"
;;
asm)
_reply_with_options "-detail -verbose"
;;
scan|scan_listener)
_reply_with_options "-netnum -scannumber -all -verbose"
;;
srvpool)
_reply_with_options "-serverpool -detail"
;;
server)
_reply_with_options "-servers -detail"
;;
oc4j)
_reply_with_options "-node -verbose"
;;
rhpserver)
COMPREPLY=()
;;
rhpclient)
COMPREPLY=()
;;
home)
if _is_cluster
then
_reply_with_options "-node -oraclehome -statefile"
else
_reply_with_options "-oraclehome -statefile"
fi
;;
oraclehome)
# TODO : l'option -name attend le nom d'un service du type :
# ora.NAME.home
_reply_with_options "-name"
;;
filesystem)
_reply_with_options "-device -verbose"
;;
volume)
_reply_with_options "-volume -diskgroup -device -node -all"
;;
diskgroup)
if _is_cluster
then
_reply_with_options "-diskgroup -node -detail -verbose"
else
_reply_with_options "-diskgroup -detail -verbose"
fi
;;
cvu)
_reply_with_options "-node"
;;
gns)
_reply_with_options "-node -verbose"
;;
mgmtdb)
_reply_with_options "-verbose"
;;
mgmtlsnr)
_reply_with_options "-verbose"
;;
exportfs)
_reply_with_options "-name -id"
;;
havip)
_reply_with_options "-id"
;;
mountfs)
_reply_with_options "-name"
;;
ons)
_reply_with_options "-verbose"
;;
*)
_srvctl_log "error object '$object_name' unknow."
COMPREPLY=()
;;
esac
}
function _next_reply_for_cmd_start
{
if ! _reply_for_option $prev_word
then
typeset -r l_cur_word=${COMP_WORDS[COMP_CWORD]}
case "$prev_word" in
open)
if [ "$prev_word" == open ]
then
if [[ "${l_cur_word:0:1}" == "'" ]]
then
COMPREPLY="read only"
else
_reply "\'read -verbose"
fi
return 0
fi
;;
esac
_reply_for_cmd_start
fi
}
function _reply_for_cmd_start
{
case "$object_name" in
database)
if _is_cluster
then
# -node only for RAC On Node
# -eval for policy managed
_reply_with_options "-db -startoption -startconcurrency
-eval -verbose"
else
_reply_with_options "-db -startoption -verbose"
fi
;;
instance) # cluster only
_reply_with_options "-db -node -instance -startoption"
;;
service)
if _is_cluster
then
_reply_with_options "-db -service -serverpool -node -instance
-pq -global_override -startoption -eval
-verbose"
else
_reply_with_options "-db -service -startoption -global_override
-verbose"
fi
;;
asm)
if _is_cluster
then
_reply_with_options "-startoption -force -proxy -node"
else
_reply_with_options "-startoption -force"
fi
;;
listener)
if _is_cluster
then
_reply_with_options "-listener -force"
else
_reply_with_options "-listener"
fi
;;
diskgroup)
if _is_cluster
then
_reply_with_options "-diskgroup -node"
else
_reply_with_options "-diskgroup"
fi
;;
ons) # standalone only
_reply_with_options "-verbose"
;;
home)
if _is_cluster
then
_reply_with_options "-oraclehome -statefile -node"
else
_reply_with_options "-oraclehome -statefile"
fi
;;
exportfs)
_reply_with_options "-name -id"
;;
mgmtlsnr)
_reply_with_options "-node"
;;
rhpclient)
_reply_with_options "-node"
;;
cvu)
_reply_with_options "-node"
;;
filesystem)
_reply_with_options "-device -node"
;;
mountfs)
_reply_with_options "-name -node"
;;
rhpserver)
_reply_with_options "-node"
;;
vip)
_reply_with_options "-node -vip -netnum -relocate -verbose"
;;
gns)
_reply_with_options "-loglevel -node -verbose"
;;
nodeapps)
_reply_with_options "-node -adminhelper -onsonly -verbose"
;;
scan)
_reply_with_options "-netnum -scannumber -node"
;;
volume)
_reply_with_options "-volume -diskgroup -device -node"
;;
havip)
_reply_with_options "-id -node"
;;
mgmtdb)
_reply_with_options "-startoption -node"
;;
oc4j)
_reply_with_options "-node -verbose"
;;
scan_listener)
_reply_with_options "-netnum -scannumber -node"
;;
*)
_srvctl_log "_reply_for_cmd_start $object_name : todo"
COMPREPLY=()
;;
esac
}