-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapi_monitor.sh
executable file
·4883 lines (4663 loc) · 188 KB
/
api_monitor.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
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
#!/bin/bash
# api_monitor.sh
#
# Test script testing the reliability and performance of OpenStack API
# It works by doing a real scenario test: Setting up a real environment
# With routers, nets, jumphosts, disks, VMs, ...
#
# We collect statistics on API call performance as well as on resource
# creation times.
# Failures are noted and alarms are generated.
#
# Status:
# - Errors not yet handled everywhere
# - Live Volume and NIC attachment not yet implemented
# - Log too verbose for permament operation ...
# - Script allows to create multiple nets/subnets independent from no of AZs,
# which may need more testing.
# - Done: Convert from neutron/cinder/nova/... to openstack (-o / -O)
#
# TODO:
# - Align sendalarm with Grafana database entries
#
# (c) Kurt Garloff <kurt.garloff@t-systems.com>, 2/2017-7/2017
# (c) Kurt Garloff <kurt@garloff.de>, 2019
# (c) Kurt Garloff <scs@garloff.de>, 2020
# License: CC-BY-SA (4.0)
#
# General approach:
# - create router (VPC)
# - create 1+$NONETS (1+2) nets -- $NONETS is normally the # of AZs
# - create 1+$NONETS subnets
# - create security groups
# - create virtual IP (for outbound SNAT via JumpHosts)
# - create SSH keys
# - create $NOAZS JumpHost VMs by
# a) creating disks (from image)
# b) creating ports
# c) creating VMs
# - associating a floating IP to each Jumphost
# - configuring the virtIP as default route
# - JumpHosts do SNAT for outbound traffic and port forwarding for inbound
# (this used to require SUSE images with SFW2-snat package to work, but now
# should work on most images, assuming iptables rules can be configured)
# - create N internal VMs striped over the nets and AZs by
# a) creating disks (from image) -- if option -d is not used
# b) creating a port -- if option -P is not used
# c) creating VM (from volume or from image, dep. on -d)
# (Steps a and c take long, so we do many in parallel and poll for progress)
# d) do some property changes to VMs
# - after everything is complete, we wait for the VMs to be up
# - we ping them, log in via ssh and see whether they can ping to the outside world (dns.google)
#
# - Finally, we clean up ev'thing in reverse order
# (We have kept track of resources to clean up.
# We can also identify them by name, which helps if we got interrupted, or
# some cleanup action failed.)
#
# So we end up testing: Router, incl. default route (for SNAT instance),
# networks, subnets, and virtual IP, security groups and floating IPs,
# volume creation from image, deletion after VM destruction
# VM creation from bootable volume (and from image if -d is given)
# Metadata service (without it ssh key injection fails of course)
# Images (we use openSUSE for the jumphost for SNAT/port-fwd and CentOS7 by dflt for VMs)
# Waiting for volumes and VMs
# Destroying all of these resources again
#
# We do some statistics on the duration of the steps (min, avg, median, 95% quantile, max)
# We of course also note any errors and timeouts and report these, optionally sending
# email or (on OTC) SMN alarms.
#
# This takes rather long, as typical CLI calls take b/w 1 and 5s on OpenStack clouds
# (including the round trip to keystone for the token).
#
# Future enhancements:
# - dynamically attach an additional disk
# - test DNS (designate)
# - test object storage (swift/s3)
#
# Optimization possibilities:
# - DONE: Cache token and reuse when creating a large number of resources in a loop
# Use option -O (not used for volume create, LB create and image stuff)
#
# Prerequisites:
# - Working python-XXXclient tools (openstack, glance, neutron, nova, cinder)
# - Optionally otc.sh from otc-tools (only if using optional SMN -m and project creation -p)
# - Optionally sendmail (only if email notification is requested)
# - jq (for JSON processing)
# - python2 or 3 for math used to calc statistics
# - SUSE image with SNAT/port-fwd (SuSEfirewall2-snat pkg) for the JumpHosts recommended
# (but we can do manual iptables settings otherwise nowadays)
# - Any image for the VMs that allows login as user DEFLTUSER (linux) with injected key
# (If we use -2/-3/-4, we also need a SUSE image to have the cloud-multiroute pkg in there.)
#
# Example:
# Run 100 loops deploying (and deleting) 2+8 VMs (including nets, volumes etc.),
# booting VMs directly from images (and creating ports implicitly), but with single calls (no -D).
# with daily statistics sent to SMN...APIMon-Notes and Alarms to SMN...APIMonitor
# ./api_monitor.sh -n 8 -d -P -s -m urn:smn:eu-de:0ee085d22f6a413293a2c37aaa1f96fe:APIMon-Notes -m urn:smn:eu-de:0ee085d22f6a413293a2c37aaa1f96fe:APIMonitor -i 100
# (SMN is OTC specific notification service that supports sending SMS.)
VERSION=1.112
APIMON_ARGS="$@"
# debugging
if test "$1" == "--debug"; then set -x; shift; fi
# Sanitize locale
export LANG=en_US.UTF-8
export LC_ALL=C # en_US.UTF-8
export LC_NUMERIC=C #en_US.UTF-8
# TODO: Document settings that can be ovverriden by environment variables
# such as PINGTARGET, ALARMPRE, FROM, [JH]IMG, [JH]IMGFILT, JHDEFLTUSER, DEFLTUSER, [JH]FLAVOR
# User settings
#export TZ=UTC
#if test -z "$PINGTARGET"; then PINGTARGET=f-ed2-i.F.DE.NET.DTAG.DE; fi
if test -z "$PINGTARGET"; then PINGTARGET=google-public-dns-b.google.com; fi
if test -z "$PINGTARGET2"; then PINGTARGET2=dns.quad9.net; fi
# Prefix for test resources
FORCEDEL=NONONO
STARTDATE=$(date +%s)
if test -z "$RPRE"; then RPRE="APIMonitor_${STARTDATE}_"; fi
if test "$RPRE" == "${RPRE%_}"; then echo "Need trailing _ for prefix RPRE"; exit 1; fi
SHORT_DOMAIN="${OS_USER_DOMAIN_NAME##*OTC*00000000001000}"
SHPRJ="${OS_PROJECT_NAME%_Project}"
ALARMPRE="${SHORT_DOMAIN:3:3}/${OS_REGION_NAME}/${SHPRJ#*_}"
SHORT_DOMAIN=${SHORT_DOMAIN:-$OS_PROJECT_NAME}
GRAFANANM="${GRAFANANM:-api-monitoring}"
WAITLB=${WAITLB:-16}
KPTYPE=${KPTYPE:-rsa}
# Find python openstackclient install
# Returns comppy
find_ostclient_compute()
{
ostclient=`type -p openstack`
ostdir=`dirname $ostclient`
for dir in ~/.local/python3.* ~/.local/python3 \
${ostdir%/*}/lib/python3.*/site-packages ${ostdir%/*}/lib/python3/site-packages \
${ostdir%/*}/lib/python3.*/dist-packages ${ostdir%/*}/lib/python3/dist-packages \
${ostdir%/*}/lib/python3.*; do
comppy=`ls -d ${dir}/openstackclient/compute 2>/dev/null`
if test -d "$comppy"; then return 0; fi
done
if ! test -d "$comppy"; then echo "INFO: Can not find openstackclient $comppy" 2>&1; unset comppy; return 1; fi
}
# Patch openstackclient to support booting with --block-device
patch_openstackclient_disklessboot()
{
find_ostclient_compute || return
srvpy=$comppy/v2/server.py
if grep -A1 'disk_group = parser.add_mutually_excl' $srvpy 2>/dev/null | grep 'required=True' 2>/dev/null >/dev/null; then
echo "INFO: patching openstackclient $srvpy ..."
sudo cp -p $srvpy $srvpy.orig
sudo sed -i '/disk_group = parser\.add_mutually_excl/{n
s@required=True@required=False@
b exit
}
:exit' $srvpy
echo "INFO: openstackclient patched $?"
fi
}
# Patch openstackclient to support availabiliy zone list --compute as project member
patch_openstackclient_computeazlist()
{
ostackver=$(openstack --version | sed 's/^openstack //')
find_ostclient_compute || return
case $ostackver in
6.3.0|6.4.0)
;;
*)
return;;
esac
avz=${comppy%/*}/common/availability_zone.py
if test ! -r "$avz"; then echo "No such file $avz to patch" 1&>2; return 1; fi
if grep 'ForbiddenException' $avz >/dev/null 2>&1; then return 0; fi
echo "INFO: patching openstackclient $avz ..."
sudo cp -p $avz $avz.orig
sudo sed -i 's/nova_exceptions/sdk_exceptions/g' $avz
sudo sed -i '/from novaclient import exceptions/{
i from openstack import exceptions as openstack_exceptions
}' $avz
sudo sed -i 's/sdk_exceptions\.Forbidden:/(sdk_exceptions.Forbidden,openstack_exceptions.ForbiddenException):/g' $avz
sudo sed -i 's/data = compute_client\.availability_zones(details=True)/data = list(compute_client.availability_zones(details=True))/' $avz
sudo sed -i 's/data = volume_client\.availability_zones()/data = list(volume_client.availability_zones())/' $avz
}
# Number of VMs and networks
if test -z "$AZS"; then
#AZS=$(nova availability-zone-list 2>/dev/null| grep -v '\-\-\-' | grep -v 'not available' | grep -v '| Name' | sed 's/^| \([^ ]*\) *.*$/\1/' | sort -n)
#AZS=$(openstack availability zone list 2>/dev/null| grep -v '\-\-\-' | grep -v 'not available' | grep -v '| Name' | grep -v '| Zone Name' | sed 's/^| \([^ ]*\) *.*$/\1/' | sort -n)
AZS=$(openstack availability zone list --compute -f json 2>/dev/null | jq '.[] | select(."Zone Status" == "available")."Zone Name"' | tr -d '"' | sort -u)
if test -z "$AZS"; then AZS=$(otc.sh vm listaz 2>/dev/null | grep -v region | sort -u); fi
if test -z "$AZS"; then
# Dangerous territory, guard it by PATCHOSTACK
if test -n "$PATCHOSTACK"; then
echo "ERROR: Broken openstack client 6.3/6.4 (openstack availability zone list --compute fails). Trying to patch." 1>&2
patch_openstackclient_computeazlist
AZS=$(openstack availability zone list --compute -f json 2>/dev/null | jq '.[] | select(."Zone Status" == "available")."Zone Name"' | tr -d '"' | sort -u)
fi
if test -z "$AZS"; then
echo "ERROR: openstack client still broken. Working around with curl ..." 1>&2
if test -n "$OS_CACERT"; then CURLARG="--cacert $OS_CACERT"; else unset CURLARG; fi
NOVAEP=$(openstack catalog list -f json | jq '.[] | select(.Name == "nova") | .Endpoints[] | select(.interface == "public") | .url' | tr -d '"')
TKN=$(openstack token issue -f value -c id)
RESP=$(curl $CURLARG -H "Accept: application/json" -H "X-Auth-Token: $TKN" -X GET "$NOVAEP/os-availability-zone" 2>/dev/null)
unset TKN
if test -n "$RESP"; then
AZS=$(echo "$RESP" | jq '.availabilityZoneInfo[] | select(.zoneState.available == true) | .zoneName' | tr -d '"')
fi
fi
if test -z "$AZS"; then echo "ERROR: Still no luck. Pass AZS manually or install openstackclient-6.5+" 1>&2; exit 1; fi
fi
fi
AZS=($AZS)
#echo "${#AZS[*]} AZs: ${AZS[*]}"; exit 0
NOAZS=${#AZS[*]}
if test -z "$VAZS"; then
#VAZS=$(cinder availability-zone-list 2>/dev/null| grep -v '\-\-\-' | grep -v 'not available' | grep -v '| Name' | sed 's/^| \([^ ]*\) *.*$/\1/' | sort -n)
#VAZS=$(openstack availability zone list --volume 2>/dev/null| grep -v '\-\-\-' | grep -v 'not available' | grep -v '| Name' | grep -v '| Zone Name' | sed 's/^| \([^ ]*\) *.*$/\1/' | sort -n)
VAZS=$(openstack availability zone list --volume -f json | jq '.[] | select(."Zone Status" == "available")."Zone Name"' | tr -d '"' | sort -u)
fi
if test -z "$VAZS"; then VAZS=(${AZS[*]}); else VAZS=($VAZS); fi
NOVAZS=${#VAZS[*]}
if test $NOAZS -gt 1 -a -z "$NAZS"; then
NAZS=$(openstack availability zone list --network -f json | jq '.[] | select(."Zone Status" == "available")."Zone Name"' | tr -d '"' | sort -u)
fi
if test -n "$NAZS"; then NAZS=($NAZS); fi
NONAZS=${#NAZS[*]}
#echo "AZs: ${AZS[*]}, VAZs: ${VAZS[*]}, NAZs: ${NAZS[*]}"
NOVMS=12
NONETS=$NOAZS
MANUALPORTSETUP=1
ROUTERITER=1
if test -z "$DEFAULTNAMESERVER"; then
if [[ $OS_AUTH_URL == *otc*t-systems.com* ]]; then
NAMESERVER=${NAMESERVER:-100.125.4.25}
fi
if test -z "$NAMESERVER"; then NAMESERVER=8.8.8.8; fi
fi
MAXITER=-9999
ERRWAIT=1
VMERRWAIT=2
unset DISASSOC
# API timeouts
NETTIMEOUT=26
FIPTIMEOUT=36
NOVATIMEOUT=28
NOVABOOTTIMEOUT=48
CINDERTIMEOUT=32
GLANCETIMEOUT=32
DEFTIMEOUT=22
TIMEOUTFACT=1
REFRESHPRJ=0
SUCCWAIT=${SUCCWAIT:-5}
DOMAIN=$(grep '^search' /etc/resolv.conf | awk '{ print $2; }'; exit ${PIPESTATUS[0]}) || DOMAIN=otc.t-systems.com
HOSTNAME=$(hostname)
FQDN=$(hostname -f 2>/dev/null) || FQDN=$HOSTNAME.$DOMAIN
echo "Running api_monitor.sh v$VERSION on host $FQDN with arguments $APIMON_ARGS"
if test -z "$OS_PROJECT_NAME"; then
TRIPLE="$OS_CLOUD"
STRIPLE="$OS_CLOUD"
ALARMPRE="$OS_CLOUD"
CLOUDDIR="$OS_CLOUD"
else
TRIPLE="$OS_USER_DOMAIN_NAME/$OS_PROJECT_NAME/$OS_REGION_NAME"
STRIPLE="$SHORT_DOMAIN/$SHPRJ/$OS_REGION_NAME"
ALARMPRE="$STRIPLE"
CLOUDDIR="$SHPRJ"
fi
if ! echo "$@" | grep '\(CLEANUP\|CONNTEST\)' >/dev/null 2>&1; then
echo "Using $RPRE prefix for resrcs on $TRIPLE (${AZS[*]})"
fi
# Images, flavors, disk sizes defaults -- these can be overriden
# Ideally have SUSE image with SuSEfirewall2-snat for JumpHosts, will be detected
# otherwise raw iptables commands will set up SNAT.
#JHIMG="${JHIMG:-Standard_openSUSE_15_latest}"
JHIMG="${JHIMG:-Ubuntu 22.04}"
# Pass " " to filter if you don't need the optimization of image filtering
#JHIMGFILT="${JHIMGFILT:---property-filter __platform=OpenSUSE}"
# For 2nd interface (-2/3/4), use also SUSE image with cloud-multiroute
IMG="${IMG:-Ubuntu 22.04}"
#IMGFILT="${IMGFILT:---property-filter __platform=CentOS}"
# ssh login names with injected key
if test "${IMG:0:6}" = "Ubuntu"; then
DEFLTUSER=${DEFLTUSER:-ubuntu}
else
DEFLTUSER=${DEFLTUSER:-linux}
fi
if test "${JHIMG:0:6}" = "Ubuntu"; then
JHDEFLTUSER=${JHDEFLTUSER:-ubuntu}
else
JHDEFLTUSER=${JHDEFLTUSER:-linux}
fi
# SCS flavor names as defaults
#JHFLAVOR=${JHFLAVOR:-computev1-1}
JHFLAVOR=${JHFLAVOR:-SCS-1V-2}
FLAVOR=${FLAVOR:-SCS-1L-1}
# Optionally increase JH and VM volume sizes beyond image size
# (slows things down due to preventing quick_start and growpart)
ADDJHVOLSIZE=${ADDJHVOLSIZE:-0}
ADDVMVOLSIZE=${ADDVMVOLSIZE:-0}
DATADIR="${DATADIR:-$PWD/$CLOUDDIR}"
if ! test -d "$DATADIR"; then mkdir "$DATADIR"; fi
LOGFILE="$DATADIR/${RPRE%_}.log"
SSHHOSTSFILE="$DATADIR/known_hosts.${RPRE%_}"
declare -i APIERRORS=0
declare -i APITIMEOUTS=0
declare -i APICALLS=0
declare -i TOTERR=0
declare -a ALARMBUFFER=()
declare -i BUFFEREDALARMS=0
# Nothing to change below here
BOLD="\e[0;1m"
REV="\e[0;3m"
NORM="\e[0;0m"
RED="\e[0;31m"
GREEN="\e[0;32m"
YELLOW="\e[0;33m"
# python3?
if test -n "$(type -p python3)"; then PYTHON3=$(type -p python3); else unset PYTHON3; fi
usage()
{
#echo "Usage: api_monitor.sh [-n NUMVM] [-l LOGFILE] [-p] CLEANUP|DEPLOY"
echo "Usage: api_monitor.sh [options]"
echo " --debug Use set -x to print every line executed"
echo " -n N number of VMs to create (beyond #AZ JumpHosts, def: 12)"
echo " -N N number of networks/subnets/jumphosts to create (def: # AZs)"
echo " -l LOGFILE record all command in LOGFILE"
echo " -a N send at most N alarms per iteration (first plus N-1 summarized)"
echo " -R send recovery email after a completely successful iteration and alarms before"
echo " -e ADR sets eMail address for notes/alarms (assumes working MTA)"
echo " second -e splits eMails; notes go to first, alarms to second eMail"
echo " -E exit on error (for CONNTEST)"
echo " -m URN sets notes/alarms by SMN (pass URN of queue)"
echo " second -m splits notifications; notes to first, alarms to second URN"
echo " -s [SH] sends stats as well once per day (or every SH hours), not just alarms"
echo " -S [NM] sends stats to grafana via local telegraf http_listener (def for NM=api-monitoring)"
echo " -q do not send any alarms"
echo " -d boot Directly from image (not via volume)"
echo " -vt TP use volumetype TP (overrides env VOLUMETYPE)"
echo " -z SZ boots VMs from volume of size SZ"
echo " -Z do not create volume for JHs separately"
echo " -P do not create Port before VM creation"
echo " -D create all VMs with one API call (implies -d -P)"
echo " -i N sets max number of iterations (def = -1 = inf)"
echo " -r N only recreate router after each Nth iteration"
echo " -g N increase VM volume size by N GB (ignored for -d/-D)"
echo " -G N increase JH volume size by N GB"
echo " -w N sets error wait (API, VM): 0-inf seconds or neg value for interactive wait"
echo " -W N sets error wait (VM only): 0-inf seconds or neg value for interactive wait"
echo " -V N set success wait: Stop for N seconds (neg val: interactive) before tearing down"
echo " -p N use a new project every N iterations"
echo " -c noColors: don't use bold/red/... ASCII sequences"
echo " -C full Connectivity check: Every VM pings every other"
echo " -o translate nova/cinder/neutron/glance into openstack client commands"
echo " -O like -o, but use token_endpoint auth (after getting token)"
echo " -x assume eXclusive project, clean all floating IPs found"
echo " -I dIsassociate floating IPs before deleting them"
echo " -L create HTTP Loadbalancer (LBaaSv2/octavia) and test it"
echo " -LL create TCP Loadbalancer (LBaaSv2/octavia) and test it"
echo " -LP PROV create TCP LB with provider PROV test it (-LO is short for -LP ovn)"
echo " -LR reverse order of LB healthmon and member creation and deletion"
echo " -b run a simple compute benchmark (4k pi with bc)"
echo " -B measure TCP BW b/w VMs (iperf3)"
echo " -M measure disk I/O bandwidth & latency (fio)"
echo " -t long Timeouts (2x, multiple times for 3x, 4x, ...)"
echo " -T assign tags to resources; use to clean up floating IPs"
echo " -2 Create 2ndary subnets and attach 2ndary NICs to VMs and test"
echo " -3 Create 2ndary subnets, attach, test, reshuffle and retest"
echo " -4 Create 2ndary subnets, reshuffle, attach, test, reshuffle and retest"
echo " -R2 Recreate 2ndary ports after detaching (OpenStack <= Mitaka bug)"
echo "Or: api_monitor.sh [-f] [-o/-O] CLEANUP XXX to clean up all resources with prefix XXX"
echo " Option -f forces the deletion"
echo "Or: api_monitor.sh [Options] CONNTEST XXX for full conn test for existing env XXX"
echo " Options: [-2/3/4] [-o/O] [-i N] [-e ADR] [-E] [-w/W/V N] [-l LOGFILE]"
echo "You need to have the OS_ variables set to allow OpenStack CLI tools to work."
echo "You can override defaults by exporting the environment variables AZS, VAZS, NAZS, RPRE,"
echo " PINGTARGET, PINGTARGET2, GRAFANANM, [JH]IMG, [JH]IMGFILT, [JH]FLAVOR, [JH]DEFLTUSER,"
echo " ADDJHVOLSIZE, ADDVMVOLSIZE, SUCCWAIT, ALARMPRE, FROM, ALARM_/NOTE_EMAIL_ADDRESSES, VOLUMETYPE,"
echo " NAMESERVER/DEFAULTNAMESERVER, SWIFTCONTAINER, FIPWAITPORTDEVOWNER, EXTSEARCH, OS_EXTRA_PARAMS."
echo "Typically, you should configure OS_CLOUD, [JH]IMG, [JH]FLAVOR, [JH]DEFLTUSER."
exit 0
}
while test -n "$1"; do
case $1 in
"-n") NOVMS=$2; shift;;
"-n"*) NOVMS=${1:2};;
"-N") NONETS=$2; shift;;
"-l") LOGFILE="$2"; shift;;
"help"|"-h"|"--help") usage;;
"-s") SENDSTATS=1
if test -n "$2" -a "$2" != "CLEANUP" -a "$2" != "DEPLOY" -a "${2:0:1}" != "-"; then SENDSTATHR="$2"; shift; fi;;
"-S") GRAFANA=1;
if test -n "$2" -a "$2" != "CLEANUP" -a "$2" != "DEPLOY" -a "${2:0:1}" != "-"; then GRAFANANM="$2"; shift; fi;;
"-P") unset MANUALPORTSETUP;;
"-d") BOOTFROMIMAGE=1;;
"-vt") VOLUMETYPE=$2; shift;;
"-z") VMVOLSIZE=$2; shift;;
"-Z") NOJHVOL=1;;
"-D") BOOTALLATONCE=1; BOOTFROMIMAGE=1; unset MANUALPORTSETUP;;
"-e") if test -z "$EMAIL"; then EMAIL="$2"; else EMAIL2="$2"; fi; shift;;
"-m") if test -z "$SMNID"; then SMNID="$2"; else SMNID2="$2"; fi; shift;;
"-q") NOALARM=1;;
"-a") MAXALARMS=$2; shift;;
"-R") SENDRECOVERY=1;;
"-i") MAXITER=$2; shift;;
"-g") ADDVMVOLSIZE=$2; shift;;
"-G") ADDJHVOLSIZE=$2; shift;;
"-w") ERRWAIT=$2; VMERRWAIT=$2; shift;;
"-W") VMERRWAIT=$2; shift;;
"-V") SUCCWAIT=$2; shift;;
"-f") FORCEDEL=XDELX;;
"-p") REFRESHPRJ=$2; shift;;
"-c") NOCOL=1;;
"-C") FULLCONN=1;;
"-o") OPENSTACKCLIENT=1;;
"-O") OPENSTACKCLIENT=1; OPENSTACKTOKEN=1;;
"-x") CLEANALLFIPS=1;;
"-I") DISASSOC=1;;
"-r") ROUTERITER=$2; shift;;
"-L") LOADBALANCER=1;;
"-LL") LOADBALANCER=1; TCP_LB=1;;
"-LP") LOADBALANCER=1; TCP_LB=1; LB_PROVIDER="--provider $2"; shift;;
"-LO") LOADBALANCER=1; TCP_LB=1; LB_PROVIDER="--provider ovn";;
"-LR") REVERSEHMMEMBER=1 ;;
"-b") BCBENCH=1;;
"-B") IPERF=1;;
"-M") FIOBENCH=1;;
"-t") let TIMEOUTFACT+=1;;
"-T") TAG=1; TAGARG="--tag ${RPRE%_}";;
"-R2") SECONDRECREATE=1;;
"-2") SECONDNET=1;;
"-3") SECONDNET=1; RESHUFFLE=1;;
"-4") SECONDNET=1; RESHUFFLE=1; STARTRESHUFFLE=1;;
"-E") EXITERR=1;;
"--debug") set -x;;
"--os-cloud") export OS_CLOUD="$2"; shift;;
"--os-cloud="*) export OS_CLOUD="${1#--os-cloud=}";;
"CLEANUP") break;;
"CONNTEST") if test "$MAXITER" == "-9999"; then MAXITER=1; fi; break;;
*) echo "Unknown argument \"$1\""; exit 1;;
esac
shift
done
if test "$1" != "CONNTEST"; then
trap exithandler SIGINT
if test -n "$SECONDNET" -a -z "$FULLCONN"; then
echo "Warning: 2ndary interfaces (-2/3/4) without full conn test (-C)?"
fi
fi
# Test precondition
type -p openstack >/dev/null 2>&1
if test $? != 0; then
echo "Need openstack client installed"
exit 1
fi
OSTACKVERSION=$(openstack --version | sed 's/^[^0-9]*\([0-9\.]*\).*$/\1/')
OSTACKVERMAJ=${OSTACKVERSION%%.*}
OSTACKVERREST=${OSTACKVERSION#*.}
OSTACKVERSION=$((10000*$OSTACKVERMAJ+100*${OSTACKVERREST%.*}+${OSTACKVERREST#*.}))
type -p jq >/dev/null 2>&1
if test $? != 0; then
echo "Need jq installed"
exit 1
fi
type -p bc >/dev/null 2>&1
if test $? != 0; then
echo "Need bc installed"
exit 1
fi
type -p nc >/dev/null 2>&1
if test $? != 0; then
echo "Need nc (netcat) installed"
exit 1
fi
type -p otc.sh >/dev/null 2>&1
if test $? != 0 -a -n "$SMNID"; then
echo "Need otc.sh for SMN notifications"
exit 1
fi
test -x /usr/sbin/sendmail
if test $? != 0 -a -n "$EMAIL"; then
echo "Need /usr/sbin/sendmail for email notifications"
exit 1
fi
if test -z "$OS_USERNAME" -a -z "$OS_CLOUD" -a -z "$OS_APPLICATION_CREDENTIAL_ID"; then
echo "source OS_ settings file before running this test, preferrably OS_CLOUD"
exit 1
fi
if ! openstack router list >/dev/null; then
echo "openstack neutron call failed, exit"
exit 2
fi
if test -n "$LOGFILE"; then
echo "Running api_monitor.sh v$VERSION on host $FQDN with arguments $APIMON_ARGS" >> "$LOGFILE"
fi
if test "$NOCOL" == "1"; then
BOLD="**"
REV="__"
NORM=" "
RED="!!"
GREEN="++"
YELLOW=".."
fi
# For sed expressions without confusing vim
SQ="'"
# openstackclient/XXXclient compat
if test -n "$OPENSTACKCLIENT"; then
PORTFIXED="s/^.*ip_address=$SQ\([0-9a-f:.]*\)$SQ.*$/\1/"
PORTFIXED2="s/ip_address=$SQ\([0-9a-f:.]*\)$SQ.*$/\1/"
FLOATEXTR='s/^|[^|]*| \([0-9:.]*\).*$/\1/'
VOLSTATCOL=2
else
PORTFIXED='s/^.*"ip_address": "\([0-9a-f:.]*\)".*$/\1/'
FLOATEXTR='s/^|[^|]*|[^|]*| \([0-9:.]*\).*$/\1/'
VOLSTATCOL=1
fi
LBWAIT=""
if test -n "$OPENSTACKCLIENT" -a -n "$LOADBALANCER"; then
openstack loadbalancer member create --help | grep -- --wait >/dev/null 2>&1
if test $? == 0; then LBWAIT="--wait"; fi
fi
# Sanity checks
# Last subnet is for the JumpHosts, thus we have 63 /22 networks avail within 10.250/16
if test ${NONETS} -gt 63; then
echo "Can not create more than 63 (sub)networks"
exit 1
fi
# We reserve 6 IPs, so allow max 1018 in our /22 net
if test $((NOVMS/NONETS)) -gt 1018; then
echo "Can not create more than 1018 VMs per (sub)net"
echo " Please decrease -n or increase -N"
exit 1
fi
# Test from availability of timeout binary
if ! type -p timeout >/dev/null 2>&1; then
echo "Need to install the timeout tool (coreutils)" 1>&2
exit 1
fi
# Alarm notification
# $1 => return code
# $2 => invoked command
# $3 => command output
# $4 => timeout (for rc=137)
reallysendalarm()
{
local KIND RES RM URN TOMSG
local RECEIVER_LIST RECEIVER
DATE=$(date)
SRPRE=${RPRE%_}
SRPREL=${RPRE%_}/$((loop+1))
if test $1 = 0 -o $1 -lt 0; then
KIND="Note"
RES=""
echo -e "$BOLD$PRE on $ALARMPRE/$SRPREL on $HOSTNAME: $2\n$DATE\n$3$NORM" 1>&2
elif test $1 -gt 123; then
KIND="TIMEOUT $4"
RES=" => $1"
echo -e "$RED$PRE on $ALARMPRE/$SRPREL on $HOSTNAME: $2\n$DATE\n$3$NORM" 1>&2
else
KIND="ALARM $1"
RES=" => $1"
echo -e "$RED$PRE on $ALARMPRE/$SRPREL on $HOSTNAME: $2\n$DATE\n$3$NORM" 1>&2
fi
TOMSG=""
if test "$4" != "0" -a $1 != 0 -a $1 != 1; then
TOMSG="(Timeout: ${4}s)"
echo -e "$BOLD$PRE(Timeout: ${4}s)$NORM" 1>&2
fi
if test -n "$NOALARM"; then return; fi
if test $1 != 0; then
RECEIVER_LIST=("${ALARM_EMAIL_ADDRESSES[@]}")
else
RECEIVER_LIST=("${NOTE_EMAIL_ADDRESSES[@]}")
fi
if test -n "$EMAIL"; then
if test -n "$EMAIL2" -a $1 != 0; then EM="$EMAIL2"; else EM="$EMAIL"; fi
RECEIVER_LIST=("$EM" "${RECEIVER_LIST[@]}")
fi
FROM="${FROM:-$LOGNAME@$FQDN}"
for RECEIVER in "${RECEIVER_LIST[@]}"
do
echo "From: $SRPREL $HOSTNAME <$FROM>
To: $RECEIVER
Subject: $ALARMPRE/$SRPREL: $KIND $2
Date: $(date -R)
$KIND on $STRIPLE
$SRPREL on $HOSTNAME:
$2
$3
$TOMSG" | /usr/sbin/sendmail -t -f $FROM
done
if test $1 != 0; then
RECEIVER_LIST=("${ALARM_MOBILE_NUMBERS[@]}")
else
RECEIVER_LIST=("${NOTE_MOBILE_NUMBERS[@]}")
fi
if test -n "$SMNID"; then
if test -n "$SMNID2" -a $1 != 0; then URN="$SMNID2"; else URN="$SMNID"; fi
RECEIVER_LIST=("$URN" "${RECEIVER_LIST[@]}")
fi
for RECEIVER in "${RECEIVER_LIST[@]}"
do
echo "$STRIPLE/${SRPREL}: $KIND $2
${SRPREL#APIMonitor_} on $HOSTNAME:
$2
$3
$TOMSG
$DATE" | otc.sh notifications publish $RECEIVER "$HOSTNAME/$ALARMPRE/${SRPREL#APIMonitor_}: $KIND"
done
}
# Alarm notification wrapper.
# $1 => return code
# $2 => invoked command
# $3 => command output
# $4 => timeout (for rc=137)
sendalarm()
{
LASTERRITER=$loop
if test -z "$MAXALARMS" || test $((SENTALARMS+1)) -lt $MAXALARMS; then
let SENTALARMS+=1
reallysendalarm "$@"
else
TO=""
if test -n "$4" -a "$4" != "0"; then TO=" (timeout $4)"; fi
ALARMBUFFER[$BUFFEREDALARMS]="Error $((BUFFEREDALARMS+1)): $2 => $1\n $3$TO\n"
echo -e "${YELLOW}Deferred error $((BUFFEREDALARMS+1)): $2 => $1\n $3$TO${NORM}"
let BUFFEREDALARMS+=1
fi
}
sendbufferedalarms()
{
if test -z "$ALARMBUFFER"; then return; fi
#echo "Debug: Buffered ${ALARMBUFFER[*]}"
CMDOUT=""
for no in $(seq 0 $((BUFFEREDALARMS-1)) ); do
CMDOUT="${CMDOUT}${ALARMBUFFER[$no]}\n"
done
CMDOUT=$(echo -e "$CMDOUT")
reallysendalarm $BUFFEREDALARMS "Deferred alarms" "$CMDOUT" 0
#let SENTALARMS+=1
SENTALARMS=0
BUFFEREDALARMS=0
}
sendrecoveryalarm()
{
if test $VMERRORS -gt 0 -o $WAITERRORS -gt 0 -o $APIERRORS -gt 0 -o $APITIMEOUTS -gt 0 -o $THISRUNTIME -gt $MAXCYC; then LASTERRITER=$loop; return; fi
if test $((LASTERRITER+1)) = $loop; then
loop=$LASTERRITER
sendalarm -1 "Successful iteration $((loop+2))" "Cloud seems to have recovered (or never was *systematically* broken)" $THISRUNTIME
let loop+=1
fi
}
rc2bin()
{
if test $1 = 0; then echo 0; return 0; else echo 1; return 1; fi
}
# Map return code to 2 (timeout), 1 (error), or 0 (success) for Grafana
# $1 => input (RC), returns global var GRC
rc2grafana()
{
if test $1 == 0; then GRC=0; elif test $1 -ge 124; then GRC=2; else GRC=1; fi
}
updAPIerr()
{
let APIERRORS+=$(rc2bin $1);
if test $1 -ge 124; then let APITIMEOUTS+=1; fi
}
declare -i EXITED=0
exithandler()
{
#loop=$(($MAXITER-1))
INTERRUPTED=1
if test "$EXITED" = "0"; then
echo -e "\n${REV}SIGINT received, exiting after this iteration$NORM"
elif test "$EXITED" = "1"; then
echo -e "\n$BOLD OK, cleaning up right away $NORM"
FORCEDEL=NONONO
cleanup
if test "$REFRESHPRJ" != 0; then cleanprj; fi
kill -TERM 0
else
echo -e "\n$RED OK, OK, exiting without cleanup. Use api_monitor.sh CLEANUP $RPRE to do so.$NORM"
if test "$REFESHPRJ" != 0; then echo -e "${RED}export OS_PROJECT_NAME=$OS_PROJECT_NAME before doing so$NORM"; fi
kill -TERM 0
fi
let EXITED+=1
}
errwait()
{
if test $1 -lt 0; then
local ans
echo -en "${YELLOW}ERROR: Hit Enter to continue: $NORM"
read ans
else
sleep $1
fi
}
# Helper: get $2th element of $1
# $1 => "Space separated array"
# $2 => index
arrelem()
{
local i=0
rst="$1"
while test -n "$rst"; do
if test $i = $2; then echo "${rst%% *}"; break; fi
if test "$rst" == "${rst#* }"; then break
else rst="${rst#* }"
fi
let i+=1
done
}
# Helper: get $2th element of $1
# $1 => "Newline separated array"
# $2 => index
arrline()
{
local i=0
while read line; do
if test $i = $2; then echo "$line"; break; fi
let i+=1
done < <(echo "$1")
}
NOVA_EP="${NOVA_EP:-novaURL}"
CINDER_EP="${CINDER_EP:-cinderURL}"
#OCTAVIA_EP="${NEUTRON_EP:-octaviaURL}"
OCTAVIA_EP="${OCTAVIA_EP:${NEUTRON_EP:-octaviaURL}}"
NEUTRON_EP="${NEUTRON_EP:-neutronURL}"
GLANCE_EP="${GLANCE_EP:-glanceURL}"
SWIFT_EP="${SWIFT_EP:-swiftURL}"
OSTACKCMD=""; EP=""
# Translate nova/cinder/neutron ... to openstack commands
translate()
{
local no DEFCMD=""
unset MYTAG
ORIGCMD="$1"
CMDS=(nova cinder neutron glance octavia swift)
OSTDEFS=(server volume network image loadbalancer object)
EPS=($NOVA_EP $CINDER_EP $NEUTRON_EP $GLANCE_EP $OCTAVIA_EP $SWIFT_EP)
for no in $(seq 0 $((${#CMDS[*]}-1))); do
if test ${CMDS[$no]} == $1; then
EP=${EPS[$no]}
DEFCMD=${OSTDEFS[$no]}
break
fi
done
OSTACKCMD=("$@")
if test "$1" == "myopenstack" -a -z "$OPENSTACKTOKEN"; then shift; OSTACKCMD=("openstack" "$@"); return 0; fi
if test "$1" == "openstack" -a -z "$OPENSTACKTOKEN"; then shift; OSTACKCMD=("openstack" "$@"); return 0; fi
if test -z "$EP"; then if test "$1" != "openstack"; then echo "No translation for $@" 1>&2; fi; return 0; fi
if test -z "$OPENSTACKCLIENT" -o "$1" == "openstack" -o "$1" == "myopenstack"; then return 0; fi
if test -n "$LOGFILE"; then echo "#DEBUG: $@" >> "$LOGFILE"; fi
#echo "#DEBUG: $@" 1>&2
if test -z "$DEFCMD"; then echo "ERROR: Unknown cmd $@" 1>&2; return 1; fi
local OPST
#if test -n "$OPENSTACKTOKEN" -a "$DEFCMD" != "image"; then OPST=myopenstack; else OPST=openstack; fi
if test -n "$OPENSTACKTOKEN"; then OPST=myopenstack; else OPST=openstack; fi
shift
CMD=${1##*-}
# External nets are not managed by us and thus not tagged; ports created via nova are neither
# (Also routers and loadbalancer may not be tagged reliably?)
if test $ORIGCMD == neutron && test $CMD == create -o $CMD == list && test -z "$NOFILTERTAG" && test "$1" != "net-external-list" -a "$1" != "port-list" -a "$1" != "router-list" -a "$1" != "lbaas-loadbalancer-list"; then
MYTAG="$TAGARG"
fi
if test "$CMD" == "$1"; then
# No '-'
shift
OSTACKCMD=($OPST $DEFCMD $CMD $MYTAG "$@")
if test "$DEFCMD" == "volume" -a "$CMD" == "create"; then
ARGS=$(echo "$@" | sed -e 's/\-\-image\-id/--image/' -e 's/\-\-volume\-type/--type/' -e 's/\-\-name \([^ ]*\) *\([0-9]*\) *$/--size \2 \1/')
#OSTACKCMD=($OPST $DEFCMD $CMD $ARGS)
# No token_endpoint auth for volume creation (need to talk to image service as well?)
OSTACKCMD=(openstack $DEFCMD $CMD $ARGS)
# Try to force volume deletion (restricted to admin on most platforms)
#elif test "$DEFCMD" == "volume" -a "$CMD" == "delete"; then
# OSTACKCMD=($OPST $DEFCMD $CMD --force "$@")
# Optimization: Avoid image and flavor name lookups in server list when polling
elif test "$DEFCMD" == "server" -a "$CMD" == "list"; then
ARGS=$(echo "$@" | sed -e 's@\-\-sort display_name:asc@--sort-column Name@')
OSTACKCMD=($OPST $DEFCMD $CMD $ARGS -n)
elif test "$DEFCMD" == "volume" -a "$CMD" == "rename"; then
OSTACKCMD=($OPST $DEFCMD set --name "$@")
# Optimization: Avoid Attachment name lookup in volume list when polling
elif test "$DEFCMD" == "volume" -a "$CMD" == "list"; then
if [[ "$@" != *Attached* ]] && [[ "$@" != *-c* ]]; then
OSTACKCMD=("${OSTACKCMD[@]}" -c ID -c Name -c Status -c Size)
elif [[ "$@" == *Attached* ]]; then
#OSTACKCMD=($OPST $DEFCMD $CMD $MYTAG)
# Use token that allows cinder to query nova for names
OSTACKCMD=(openstack $DEFCMD $CMD $MYTAG)
fi
#echo "#DEBUG: ${OSTACKCMD[@]}" 1>&2
elif test "$DEFCMD" == "server" -a "$CMD" == "boot"; then
if test $OSTACKVERSION -lt 50500; then
## FIXME: openstack server create does not seem to support vol from image with delete_on_termination=true
case "$*" in
*"--block-device "*)
OSTACKCMD=(nova boot "$@")
echo -e "${YELLOW}#WARNING: Outdated openstackclient, trying to boot with nova (needs OS_USERNAME/PASSWORD)${NORM}" 1>&2
return
esac
fi
# Only handles one SG
ARGS=$(echo "$@" | sed -e 's@\-\-boot\-volume@--volume@' -e 's@\-\-security\-groups@--security-group@' -e 's@\-\-min\-count@--min@' -e 's@\-\-max\-count@--max@' -e 's@shutdown=remove@delete_on_termination=true@' -e 's@volumetype=@volume_type=@' -e 's@\-\-block\-device id=@ --block-device uuid=@' -e 's@,source=@,source_type=@' -e 's@,dest=@,destination_type=@' -e 's@,bootindex=@,boot_index=@' -e 's@,size=@,volume_size=@')
if test "$DEFCMD" == "server" -a "$CMD" == "boot"; then
if [[ $ARGS = *delete_on_termination* ]]; then VOLNEEDSTAG=1; else VOLNEEDSTAG=0; fi
#if test "$TAG" == "1"; then ARGS=$(echo "--os-compute-api-version 2.72 $ARGS" | sed "s/delete_on_termination=true/delete_on_termination=true,tag=${RPRE%_}/g"); fi
if [[ $ARGS = *volume_type=* ]]; then ARGS=$(echo "--os-compute-api-version 2.67 $ARGS"); fi
fi
#OSTACKCMD=($OPST $DEFCMD create $ARGS)
# No token_endpoint auth for server creation (need to talk to neutron/cinder/glance as well)
OSTACKCMD=(openstack $DEFCMD create $ARGS)
elif test "$DEFCMD" == "server" -a "$CMD" == "meta"; then
# nova meta ${VMS[$no]} set deployment=$CFTEST server=$no
ARGS=$(echo "$@" | sed -e 's@set @@' -e 's@\([a-zA-Z_0-9]*=[^ ]*\)@--property \1@g')
OSTACKCMD=($OPST $DEFCMD set $ARGS)
elif test "$DEFCMD" == "object" -a "$CMD" == "upload"; then
if test "$1" == "--object-name"; then ON="--name"; else ON="$1"; fi
shift
OSTACKCMD=($OPST $DEFCMD create "$ON" "$@")
fi
else
C1=${1%-*}
if test "$C1" == "net"; then C1="network"; fi
if test "$C1" == "floatingip"; then C1="floating ip"; fi
if test "$C1" == "keypair" -a "$CMD" == "add"; then CMD="create"; fi
C1=${C1//-/ }
shift
if test "$CMD" == "show" -o "$CMD" == "list"; then LWAIT=""; else LWAIT="$LBWAIT"; fi
if test "$C1" == "console" -a CMD=="log"; then CMD="log show"; fi
#OSTACKCMD=($OPST $C1 $CMD $MYTAG "$@")
ARGS=$(echo "${@//--property-filter/--property}" | sed -e 's/\-\-pub\-key/--public-key/')
OSTACKCMD=($OPST $C1 $CMD $MYTAG "$ARGS")
#if test "$C1" == "keypair" -a "$CMD" == "create"; then
# OSTACKCMD=(openstack $C1 $CMD $MYTAG "${@//--property-filter/--property}")
#fi
if test "$C1" == "subnet" -a "$CMD" == "create"; then
ARGS=$(echo "$@" | sed -e 's@\-\-disable-dhcp@--no-dhcp@' -e 's@\-\-name \([^ ]*\) *\([^ ]*\) *\([^ ]*\)@--network \2 --subnet-range \3 \1@')
OSTACKCMD=($OPST $C1 $CMD $MYTAG ${ARGS})
elif test "$C1" == "floating ip" -a "$CMD" == "create"; then
ARGS=$(echo "$@" | sed 's@\-\-port\-id@--port@')
OSTACKCMD=($OPST $C1 $CMD $MYTAG ${ARGS})
elif test "$C1" == "net external"; then
OSTACKCMD=($OPST network $CMD $MYTAG --external "$@")
elif test "$C1" == "port" -a "$CMD" == "create"; then
ARGS=$(echo "$@" | sed -e 's@subnet_id=@subnet=@g' -e 's@\-\-name \([^ ]*\) *\([^ ]*\)@--network \2 \1@')
OSTACKCMD=($OPST $C1 $CMD $MYTAG ${ARGS})
elif test "$C1" == "port" -a "$CMD" == "update"; then
# --allowed-address-pairs type=dict list=true ip_address=0.0.0.0/1 ip_address=128.0.0.0/1)
ARGS=$(echo "$@" | sed -e 's@\-\-allowed-address-pairs type=dict list=true@@' -e 's@ip_address=\([^ ]*\)@--allowed-address ip-address=\1@g')
OSTACKCMD=($OPST $C1 set ${ARGS})
elif test "$C1" == "router" -a "$CMD" == "update"; then
# --routes type=dict list=true destination=0.0.0.0/0,nexthop=$VIP
ARGS=$(echo "$@" | sed -e 's@\-\-routes type=dict list=true@@' -e 's@destination=\([^ ,]*\),nexthop=\([^ ,]*\)@--route destination=\1,gateway=\2@g' -e 's/\-\-no\-routes/--no-route/')
OSTACKCMD=($OPST $C1 set ${ARGS})
elif test "$C1" == "router interface" -a "$CMD" == "add"; then
OSTACKCMD=($OPST router add subnet "$@")
elif test "$C1" == "router interface" -a "$CMD" == "delete"; then
OSTACKCMD=($OPST router remove subnet "$@")
elif test "$C1" == "router gateway" -a "$CMD" == "set"; then
#neutron router-gateway-set ${ROUTERS[0]} $EXTNET
ARGS=$(echo "$@" | sed 's/\([^-][^ ]*\) *\([^ ]*\)/--external-gateway \2 \1/')
OSTACKCMD=($OPST router set "${ARGS[@]}")
elif test "$C1" == "security group rule" -a "$CMD" == "create"; then
ARGS=$(echo "$@" | sed -e 's/\-\-direction ingress/--ingress/' -e 's/\-\-direction egress/--egress/' -e 's/\-\-remote\-ip\-prefix/--remote-ip/' -e 's/\-\-remote\-group\-id/--remote-group/' -e 's/\-\-protocol tcp *\-\-port\-range\-min \([0-9]*\) *\-\-port\-range\-max \([0-9]*\)/--protocol tcp --dst-port \1:\2/' -e 's/\-\-protocol icmp *\-\-port\-range\-min \([0-9]*\) *\-\-port\-range\-max \([0-9]*\)/--protocol icmp --icmp-type \1 --icmp-code \2/')
if ! echo "$ARGS" | grep '\-\-protocol' >/dev/null 2>&1; then ARGS="$ARGS --protocol any"; fi
OSTACKCMD=($OPST $C1 $CMD $ARGS)
# No token_endpoint auth for vNIC at/detachment
elif test "$C1" == "interface" -a "$CMD" == "attach"; then
C1="server"; CMD="add port"; OPST="openstack"
ARGS=$(echo "$@" | sed -e 's@\-\-port\-id \([^ ]*\) *\([^ ]*\)$@\2 \1@')
OSTACKCMD=($OPST $C1 $CMD $ARGS)
elif test "$C1" == "interface" -a "$CMD" == "detach"; then
C1="server"; CMD="remove port"; OPST="openstack"
# The interface-detach syntax is not symmetric to interface-attach, ouch!
#ARGS=$(echo "$@" | sed -e 's@--port-id \([^ ]\) *\([^ ]*\)$@\2 \1@')
#OSTACKCMD=($OPST $C1 $CMD $ARGS)
OSTACKCMD=($OPST $C1 $CMD $@)
elif test "$C1" == "lbaas loadbalancer"; then
EP="$OCTAVIA_EP"
# FIXME: Don't use octaviaclient-2.2
if test -n "$OLD_OCTAVIA"; then
ARGS=$(echo "$@" | sed -e 's/\-\-vip\-network\-id/--vip_network_id/g' -e 's/\-\-vip\-subnet\-id/--vip_subnet_id/g')
else
ARGS=$(echo "$@")
fi
OSTACKCMD=(openstack loadbalancer $CMD $ARGS)
elif test "$C1" == "lbaas pool"; then
if test -n "$OLD_OCTAVIA"; then
#ARGS=$(echo "$@" | sed -e 's/\-\-lb\-algorithm=/--lb_algorithm /g' -e "s/\-\-session\-persistence type=\([^ ]*\)/--session_persistence '{ \"type\": \"\1\" }'/g" -e 's/\-\-loadbalancer /--loadbalancer_id /g')
ARGS=$(echo "$@" | sed -e 's/\-\-lb\-algorithm=/--lb_algorithm /g' -e "s/\-\-session\-persistence type=\([^ ]*\)//g" -e 's/\-\-loadbalancer /--loadbalancer_id /g')
else
ARGS=$(echo "$@")
fi
EP="$OCTAVIA_EP"
OSTACKCMD=($OPST loadbalancer pool $CMD $LWAIT $ARGS)
elif test "$C1" == "lbaas listener"; then
EP="$OCTAVIA_EP"
if test -n "$OLD_OCTAVIA"; then
ARGS=$(echo "$@" | sed -e 's/\-\-protocol\-port/--protocol_port/g' -e 's/\-\-default\-pool/--default_pool/g' -e 's/\-\-loadbalancer / /g')
else
ARGS=$(echo "$@" | sed 's/\-\-loadbalancer / /')
fi
OSTACKCMD=($OPST loadbalancer listener $CMD $LWAIT $ARGS)
elif test "$C1" == "lbaas member"; then
EP="$OCTAVIA_EP"
if test -n "$OLD_OCTAVIA"; then
ARGS=$(echo "$@" | sed -e 's/\-\-protocol\-port/--protocol_port/g' -e 's/\-\-subnet\-id/--subnet_id/g')
else
if test -z "$LB_PROVIDER"; then
# amphorae don't need subnet-id
ARGS=$(echo "$@" | sed -e 's/\-\-subnet\-id [^ ]*/ /g')
else
ARGS=$(echo "$@")
fi
fi
if [[ "$ARGS" == *"--subnet-id"* ]]; then
# If we talk directly to octavia, the --subnet-id option won't work
# We could try to use the proxy via neutron or just do the std dance
#EP="$NEUTRON_EP"
#OSTACKCMD=($OPST loadbalancer member $CMD $LWAIT $ARGS)
OSTACKCMD=(openstack loadbalancer member $CMD $LWAIT $ARGS)
else
OSTACKCMD=($OPST loadbalancer member $CMD $LWAIT $ARGS)
fi
elif test "$C1" == "lbaas healthmonitor"; then
EP="$OCTAVIA_EP"
if test -n "$OLD_OCTAVIA"; then
ARGS=$(echo "$@" | sed -e 's/\-\-max\-retries/--max_retries/g' -e 's/\-\-url\-path/--url_path/g' -e 's/\-\-pool //g')
else
ARGS=$(echo "$@" | sed 's/\-\-pool //')
fi
OSTACKCMD=($OPST loadbalancer healthmonitor $CMD $LWAIT $ARGS)
fi
#echo "#DEBUG: ${OSTACKCMD[@]}" 1>&2
fi
if test -n "$LOGFILE"; then echo "#=> : ${OSTACKCMD[@]}" >> "$LOGFILE"; fi
return 0
}
# Do some math (python syntax)
# $1 => formatting
# $2 => math expr
math()