-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenstack_swift_Ring_modify.sh
More file actions
843 lines (831 loc) · 51.9 KB
/
Copy pathopenstack_swift_Ring_modify.sh
File metadata and controls
843 lines (831 loc) · 51.9 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
#!/bin/bash
# OpenStack Swift Ring Modify scripts
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 1. device_config_path配置规范: action_type|ring_builder_name|region|zone|host|port|device_name|weight|increment_value|
# action_type: 设备的操作类型,支持 add improve reduce
# ring_builder_name: ring环的类型,可选项为 account container object
# region: 域,必须为大于0的正整数
# zone: 区,必须为大于0的正整数
# host: 设备IP地址
# port: ring环对应的服务端口
# device_name: 设备名称,如:sdb1
# weight: 权重值,必须为大于0的正整数,当设置为0时被标记为remove设备
# increment_value: 权重的递增值,必须为大于0的正整数,建议尽量小
#示例:
# add|account|1|1|172.16.1.100|6002|sdb1|3000|1|
# add|container|1|1|172.16.1.100|6001|sdb1|3000|1|
# add|object|1|1|172.16.1.100|6000|sdb1|3000|1|
#
# 2. all_datanode_list配置规范: 存储节点IP地址.
#示例:
# 172.16.1.100
# 172.16.1.101
# 172.16.1.102
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# basepath
basepath=$(cd `dirname $0`;pwd)
# log file
log_dir="${basepath}/swift_ring_modify.log"
# ring host/device information configuration file
device_config_path="${basepath}/swift_ring_config_device.conf"
# all datanode host list
all_datanode_list="${basepath}/swift_datanode_host.conf"
# swift ring files path
swift_ring_path="/etc/swift"
# openstack swift account.builder file
swift_account_builder="account.builder"
# openstack swift account ring.gz file
swift_account_ring_file="${swift_ring_path}/account.ring.gz"
# openstack swift container.builder file
swift_container_builder="container.builder"
# openstack swift container ring.gz file
swift_container_ring_file="${swift_ring_path}/container.ring.gz"
# openstack swift object.builder file
swift_object_builder="object.builder"
# openstack swift object ring.gz file
swift_object_ring_file="${swift_ring_path}/object.ring.gz"
# openstack swift ring-builder command
swift_ring_builder="/usr/bin/swift-ring-builder"
# time wait value(sec)
sleep_time=3600
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start Swift Ring Modify scripts." >> ${log_dir}
# 检查脚本所需的运行环境
check_files (){
# 检查设备配置列表文件是否存在
if [ ! -f ${device_config_path} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${device_config_path} file not found." >> ${log_dir}
exit 1
fi
# 检查存储节点列表文件是否存在
if [ ! -f ${all_datanode_list} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${all_datanode_list} file not found." >> ${log_dir}
exit 1
fi
# 检查ring配置文件目录是否存在
if [ ! -d ${swift_ring_path} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_ring_path} path not found." >> ${log_dir}
exit 1
fi
# 检查account.builder是否存在
if [ ! -f ${swift_ring_path}/${swift_account_builder} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_ring_path}/${swift_account_builder} file not found." >> ${log_dir}
exit 1
fi
# 检查container.builder是否存在
if [ ! -f ${swift_ring_path}/${swift_container_builder} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_ring_path}/${swift_container_builder} file not found." >> ${log_dir}
exit 1
fi
# 检查object.builder是否存在
if [ ! -f ${swift_ring_path}/${swift_object_builder} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_ring_path}/${swift_object_builder} file not found." >> ${log_dir}
exit 1
fi
# 检查swift-ring-builder是否存在
if [ ! -f ${swift_ring_builder} ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_ring_builder} command not found." >> ${log_dir}
exit 1
fi
}
# 检查传入参数的合规性
check_parameter (){
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start check parameter , parameter is ${ring_device}." >> ${log_dir}
# 平衡ring环的间隔时间
if [ ${sleep_time} -lt 3600 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${sleep_time} value less than 1 hour." >> ${log_dir}
exit 1
fi
# 检查设备操作类型
if [[ ${action_type} == add ]] || [[ ${action_type} == improve ]] || [[ ${action_type} == reduce ]]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${action_type}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${action_type} , value exception." >> ${log_dir}
continue
fi
# 检查ring环类型
if [[ ${ring_builder_name} == account ]] || [[ ${ring_builder_name} == container ]] || [[ ${ring_builder_name} == object ]]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${ring_builder_name}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${ring_builder_name} , value exception." >> ${log_dir}
continue
fi
# 检查region值
if [ "${region_num}" -gt 0 ] 2>/dev/null; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${region_num}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${region_num} , value exception." >> ${log_dir}
continue
fi
# 检查zone值
if [ "${zone_num}" -gt 0 ] 2>/dev/null; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${zone_num}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${zone_num} , value exception." >> ${log_dir}
continue
fi
# 检查设备IP地址合规性
if [[ "${host}" =~ ^([0-9]{1,3}.){3}[0-9]{1,3}$ ]]; then
local FIELD1=$(echo ${host}|cut -d. -f1)
local FIELD2=$(echo ${host}|cut -d. -f2)
local FIELD3=$(echo ${host}|cut -d. -f3)
local FIELD4=$(echo ${host}|cut -d. -f4)
if [ $FIELD1 -eq 0 -a $FIELD2 -eq 0 -a $FIELD3 -eq 0 -a $FIELD4 -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${host} , value exception." >> ${log_dir}
continue
fi
if [ $FIELD1 -le 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${host}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${host} , value exception." >> ${log_dir}
continue
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${host} , value exception." >> ${log_dir}
continue
fi
# 检查IP地址端口
if [ "${port}" -gt 0 ] 2>/dev/null; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${port}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${port} , value exception." >> ${log_dir}
continue
fi
# 检查设备名称
if [ ! -z "${device_name}" ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${device_name}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${device_name} , null value." >> ${log_dir}
continue
fi
# 检查权重值
if [ "${weight_num}" -ge 0 ] 2>/dev/null; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${weight_num}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${weight_num} , value exception." >> ${log_dir}
continue
fi
# 检查递增值
if [ "${increment_value}" -gt 0 ] 2>/dev/null; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check parameter ok , value is ${increment_value}." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${increment_value} , value exception." >> ${log_dir}
continue
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended check parameter." >> ${log_dir}
}
# 检查search value参数在ring环中的存在情况
check_search_value (){
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start check search value, parameter is ${search_value}." >> ${log_dir}
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
# 在account中检查
if [[ ${ring_builder_name} == account ]]; then
local value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check ${swift_account_builder} search value NULL , value is ${search_value}." >> ${log_dir}
elif [ ${value1} -eq 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_account_builder} search value existing , value is ${search_value}." >> ${log_dir}
elif [ ${value1} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_account_builder} search value are multiple , value is ${search_value}." >> ${log_dir}
continue
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: check ${swift_account_builder} search value failed , value is ${search_value}." >> ${log_dir}
continue
fi
fi
# 在container中检查
if [[ ${ring_builder_name} == container ]]; then
local value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check ${swift_container_builder} search value NULL , value is ${search_value}." >> ${log_dir}
elif [ ${value2} -eq 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_container_builder} search value existing , value is ${search_value}." >> ${log_dir}
elif [ ${value2} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_container_builder} search value are multiple , value is ${search_value}." >> ${log_dir}
continue
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: check ${swift_container_builder} search value failed , value is ${search_value}." >> ${log_dir}
continue
fi
fi
# 在object中检查
if [[ ${ring_builder_name} == object ]]; then
local value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: check ${swift_object_builder} search value NULL , value is ${search_value}." >> ${log_dir}
elif [ ${value3} -eq 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_object_builder} search value existing , value is ${search_value}." >> ${log_dir}
elif [ ${value3} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: check ${swift_object_builder} search value are multiple , value is ${search_value}." >> ${log_dir}
continue
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: check ${swift_object_builder} search value failed , value is ${search_value}." >> ${log_dir}
continue
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended check search value." >> ${log_dir}
}
# ring环文件复制到存储节点
ring_file_copy (){
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start Swift ring copy to datanode scripts." >> ${log_dir}
if [ -f ${swift_account_ring_file} ]; then
if [ -f ${swift_container_ring_file} ]; then
if [ -f ${swift_object_ring_file} ]; then
while read datanode_device
do
if [ ! -z `echo ${datanode_device} |sed '/^#/d' |sed '/^$/d'` ]; then
local var_retval=0
datanode_host=`echo $datanode_device |awk '{print $1}'`
if [[ ${ring_builder_name} == account ]]; then
scp ${swift_account_ring_file} ${datanode_device}:/etc/swift/
var_retval=$?
if [ ${var_retval} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: ${swift_account_ring_file} copy ring.gz file to ${datanode_device} successed." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_account_ring_file} copy ring.gz file to ${datanode_device} failed." >> ${log_dir}
break
fi
fi
if [[ ${ring_builder_name} == container ]]; then
scp ${swift_container_ring_file} ${datanode_device}:/etc/swift/
var_retval=$?
if [ ${var_retval} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: ${swift_container_ring_file} copy ring.gz file to ${datanode_device} successed." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_container_ring_file} copy ring.gz file to ${datanode_device} failed." >> ${log_dir}
break
fi
fi
if [[ ${ring_builder_name} == object ]]; then
scp ${swift_object_ring_file} ${datanode_device}:/etc/swift/
var_retval=$?
if [ ${var_retval} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: ${swift_object_ring_file} copy ring.gz file to ${datanode_device} successed." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_object_ring_file} copy ring.gz file to ${datanode_device} failed." >> ${log_dir}
break
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: load datanode host list failed." >> ${log_dir}
fi
done < ${all_datanode_list}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_object_ring_file} ring.gz files not found." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_container_ring_file} ring.gz files not found." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${swift_account_ring_file} ring.gz files not found." >> ${log_dir}
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended Swift ring copy to datanode scripts." >> ${log_dir}
}
# 修改ring环中设备的权重或平衡环
ring_device_set_weight(){
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start modify ring ." >> ${log_dir}
local action_target=$1
local action_value=$2
local weight_value=$3
local var_retval=0
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
case ${action_value} in
add|set_weight)
if [ ! -z ${action_target} ] && [ ! -z ${action_value} ] && [ ! -z ${weight_value} ]; then
${swift_ring_builder} ${action_target} ${action_value} ${search_value} ${weight_value}
var_retval=$?
if [ ${var_retval} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: ring.builder value is ${action_target} , action value is ${action_value} , search value is ${search_value} , weight value is ${weight_value} , modify device weight to ring file successed." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ring.builder value is ${action_target} , action value is ${action_value} , search value is ${search_value} , weight value is ${weight_value} , modify device weight to ring file failed." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: value1 is ${action_target} , value2 is ${action_value} , value3 is ${weight_value} , value reading failed." >> ${log_dir}
fi
;;
rebalance)
if [ ! -z ${action_target} ] && [ ! -z ${action_value} ]; then
${swift_ring_builder} ${action_target} ${action_value}
var_retval=$?
if [ ${var_retval} -eq 0 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: ${action_target} ${action_value} , rebalance ring successed." >> ${log_dir}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${action_target} ${action_value} , rebalance ring failed." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: value1 is ${action_target} , value2 is ${action_value} , value reading failed." >> ${log_dir}
fi
;;
*)
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: value1 is ${action_target} , value2 is ${action_value} , value unrecognized parameters." >> ${log_dir}
;;
esac
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended modify ring ." >> ${log_dir}
}
# 向ring环中新增设备
ring_add_new_device (){
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
if [[ ${ring_builder_name} == account ]]; then
local value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 0 ]; then
for (( tmp_weight_value = increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 0 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} add ${tmp_weight_value}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} add ${weight_num}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
elif [ ${value1} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
continue
fi
elif [[ ${ring_builder_name} == container ]]; then
local value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 0 ]; then
for (( tmp_weight_value = increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 0 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} add ${tmp_weight_value}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} add ${weight_num}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
elif [ ${value2} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
continue
fi
elif [[ ${ring_builder_name} == object ]]; then
local value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 0 ]; then
for (( tmp_weight_value = increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 0 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} add ${tmp_weight_value}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} add ${weight_num}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
elif [ ${value3} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: add value to ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
continue
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
}
# 减少当前设备的权重的方法
ring_reduce_device_weight(){
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
if [[ ${ring_builder_name} == account ]]; then
local value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 1 ]; then
local account_current_weight=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${account_current_weight} -gt ${weight_num} ]; then
for (( tmp_weight_value = account_current_weight - increment_value ; tmp_weight_value > weight_num - increment_value ; tmp_weight_value -= increment_value )); do
value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 1 ]; then
if [ ${tmp_weight_value} -ge ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -lt ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${account_current_weight} -lt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
continue
fi
elif [[ ${ring_builder_name} == container ]]; then
local value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 1 ]; then
local container_current_weight=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${container_current_weight} -gt ${weight_num} ]; then
for (( tmp_weight_value = container_current_weight - increment_value ; tmp_weight_value > weight_num - increment_value ; tmp_weight_value -= increment_value )); do
value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 1 ]; then
if [ ${tmp_weight_value} -ge ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -lt ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${container_current_weight} -lt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
continue
fi
elif [[ ${ring_builder_name} == object ]]; then
local value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 1 ]; then
local object_current_weight=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${object_current_weight} -gt ${weight_num} ]; then
for (( tmp_weight_value = object_current_weight - increment_value ; tmp_weight_value > weight_num - increment_value ; tmp_weight_value -= increment_value )); do
value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 1 ]; then
if [ ${tmp_weight_value} -ge ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -lt ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${object_current_weight} -lt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
continue
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
}
# 提高当前设备的权重的方法
ring_improve_device_weight(){
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
if [[ ${ring_builder_name} == account ]]; then
local value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 1 ]; then
local account_current_weight=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${account_current_weight} -lt ${weight_num} ]; then
for (( tmp_weight_value = account_current_weight + increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_account_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_account_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${account_current_weight} -gt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_account_builder} is failed , search value is ${search_value} , value1 is ${value1}." >> ${log_dir}
fi
elif [[ ${ring_builder_name} == container ]]; then
local value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 1 ]; then
local container_current_weight=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${container_current_weight} -lt ${weight_num} ]; then
for (( tmp_weight_value = container_current_weight + increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_container_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_container_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${container_current_weight} -gt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_container_builder} is failed , search value is ${search_value} , value2 is ${value2}." >> ${log_dir}
fi
elif [[ ${ring_builder_name} == object ]]; then
local value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 1 ]; then
local object_current_weight=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep -iv "Device" |awk '{print $9}' |awk -F'.' '{print $1}')
if [ ${object_current_weight} -lt ${weight_num} ]; then
for (( tmp_weight_value = object_current_weight + increment_value ; tmp_weight_value < weight_num + increment_value ; tmp_weight_value += increment_value )); do
value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 1 ]; then
if [ ${tmp_weight_value} -le ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${tmp_weight_value}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
elif [ ${tmp_weight_value} -gt ${weight_num} ]; then
ring_device_set_weight ${swift_object_builder} set_weight ${weight_num}
ring_device_set_weight ${swift_object_builder} rebalance
ring_file_copy
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start sleep ${sleep_time} ." >> ${log_dir}
sleep ${sleep_time}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: tmp_weight_value has Exception string , value is ${tmp_weight_value}." >> ${log_dir}
break
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
break
fi
done
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: current weight value less than new weight value , ${object_current_weight} -gt ${weight_num} has exception." >> ${log_dir}
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: change value for ${swift_object_builder} is failed , search value is ${search_value} , value3 is ${value3}." >> ${log_dir}
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
}
# 检查设备列表在ring环中的存在情况
ring_check_device_list(){
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Start ring device list check." >> ${log_dir}
cd ${swift_ring_path}
local var_retval=$?
if [ ${var_retval} -eq 0 ]; then
if [[ ${ring_builder_name} == account ]]; then
local value1=$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value1} -eq 1 ]; then
echo "$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep -iv "Device")"
elif [ ${value1} -eq 0 ]; then
echo "${search_value} not found."
elif [ ${value1} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: there are multiple values"
echo "$(${swift_ring_builder} ${swift_account_builder} search ${search_value} |grep -iv "Device")"
fi
elif [[ ${ring_builder_name} == container ]]; then
local value2=$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value2} -eq 1 ]; then
echo "$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep -iv "Device")"
elif [ ${value2} -eq 0 ]; then
echo "${search_value} not found."
elif [ ${value2} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: there are multiple values"
echo "$(${swift_ring_builder} ${swift_container_builder} search ${search_value} |grep -iv "Device")"
fi
elif [[ ${ring_builder_name} == object ]]; then
local value3=$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep ${host} |grep ${port} |grep ${device_name} |wc -l)
if [ ${value3} -eq 1 ]; then
echo "$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep -iv "Device")"
elif [ ${value3} -eq 0 ]; then
echo "${search_value} not found."
elif [ ${value3} -gt 1 ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` WARNING: there are multiple values"
echo "$(${swift_ring_builder} ${swift_object_builder} search ${search_value} |grep -iv "Device")"
fi
fi
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: switch to ${swift_ring_path} path failed." >> ${log_dir}
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended ring device list check." >> ${log_dir}
}
input_value=$1
if [ -f ${device_config_path} ]; then
while read ring_device
do
check_files
if [ ! -z `echo ${ring_device} |sed '/^#/d' |sed '/^$/d'` ]; then
# 从设备列表配置文件中读取信息
# 设备的操作类型,可选项为 add improve reduce
action_type=`echo $ring_device |awk -F '|' '{print $1}'`
# ring环的类型,可选项为 account container object
ring_builder_name=`echo $ring_device |awk -F '|' '{print $2}'`
# region值,必须为大于0的正整数
region_num=`echo $ring_device |awk -F '|' '{print $3}'`
# zone值,必须为大于0的正整数
zone_num=`echo $ring_device |awk -F '|' '{print $4}'`
# 设备的IP地址
host=`echo $ring_device |awk -F '|' '{print $5}'`
# ring环对应的服务端口,一般为 6000 6001 6002
port=`echo $ring_device |awk -F '|' '{print $6}'`
# 需要操作的挂载设备名称
device_name=`echo $ring_device |awk -F '|' '{print $7}'`
# 设置设备的权重值,必须为大于0的正整数,当设置为0时被标记为remove设备
weight_num=`echo $ring_device |awk -F '|' '{print $8}'`
# 权重的递增值,必须为大于0的正整数,建议尽量小
increment_value=`echo $ring_device |awk -F '|' '{print $9}'`
echo " all value is: ${action_type} r${region_num}z${zone_num}-${host}:${port}/${device_name} ${weight_num}" >> ${log_dir}
# 检查参数是否符合标准
check_parameter
# 组合search value
search_value="r${region_num}z${zone_num}-${host}:${port}/${device_name}"
# 检查search value在ring环中的存在情况
check_search_value
case ${input_value} in
start)
case ${action_type} in
add)
# 新增设备的方法
ring_add_new_device
;;
improve)
# 提高当前设备的权重的方法
ring_improve_device_weight
;;
reduce)
# 减少当前设备的权重的方法
ring_reduce_device_weight
;;
*)
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: parameter value is ${action_type} , unable to match the parameters." >> ${log_dir}
;;
esac
;;
check)
# 检查设备列表在ring环中的存在情况
ring_check_device_list
;;
*)
echo -e $"\nUsage: $0 {start|check}\n"
;;
esac
fi
done < ${device_config_path}
else
echo "`date +'%Y-%m-%d %H:%M:%S'` ERROR: ${device_config_path} file not found." >> ${log_dir}
exit 1
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` INFO: Ended Swift Ring Modify scripts." >> ${log_dir}