-
Notifications
You must be signed in to change notification settings - Fork 23
/
setup.py
executable file
·1805 lines (1642 loc) · 116 KB
/
setup.py
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
#!/usr/bin/python
import argparse
import ConfigParser
import platform
import os
import sys
import time
import re
import string
import socket
import netifaces, netaddr
import subprocess
import fnmatch
import struct
import shutil
import json
from pprint import pformat
import xml.etree.ElementTree as ET
import platform
import commonport
import tempfile
from fabric.api import local, env, run, settings
from fabric.operations import get, put
from fabric.context_managers import lcd, settings
from fabric.api import local, env, run
from fabric.operations import get, put
from fabric.context_managers import lcd, settings
sys.path.insert(0, os.getcwd())
class SetupCeph(object):
# Added global variables for the files.
# Use the variables instead of the filenames directly in the script
# to avoid typos and readability.
global CINDER_CONFIG_FILE
CINDER_CONFIG_FILE='/etc/cinder/cinder.conf'
global NOVA_CONFIG_FILE
NOVA_CONFIG_FILE='/etc/nova/nova.conf'
global CEPH_CONFIG_FILE
CEPH_CONFIG_FILE='/etc/ceph/ceph.conf'
def reset_mon_local_list(self):
local('echo "get_local_daemon_ulist() {" > /tmp/mon_local_list.sh')
local('echo "if [ -d \\"/var/lib/ceph/mon\\" ]; then" >> /tmp/mon_local_list.sh')
local('echo "for i in \`find -L /var/lib/ceph/mon -mindepth 1 -maxdepth 1 -type d -printf \'%f\\\\\\n\'\`; do" >> /tmp/mon_local_list.sh')
local('echo "if [ -e \\"/var/lib/ceph/mon/\$i/upstart\\" ]; then" >> /tmp/mon_local_list.sh')
local('echo "id=\`echo \$i | sed \'s/[^-]*-//\'\`" >> /tmp/mon_local_list.sh')
local('echo "sudo stop ceph-mon id=\$id" >> /tmp/mon_local_list.sh')
local('echo "fi done fi" >> /tmp/mon_local_list.sh')
local('echo "}" >> /tmp/mon_local_list.sh')
local('echo "get_local_daemon_ulist" >> /tmp/mon_local_list.sh')
local('echo "exit 0" >> /tmp/mon_local_list.sh')
local('chmod a+x /tmp/mon_local_list.sh')
local('/tmp/mon_local_list.sh')
def reset_osd_local_list(self):
local('echo "get_local_daemon_ulist() {" > /tmp/osd_local_list.sh')
local('echo "if [ -d \\"/var/lib/ceph/osd\\" ]; then" >> /tmp/osd_local_list.sh')
local('echo "for i in \`find -L /var/lib/ceph/osd -mindepth 1 -maxdepth 1 -type d -printf \'%f\\\\\\n\'\`; do" >> /tmp/osd_local_list.sh')
local('echo "if [ -e \\"/var/lib/ceph/osd/\$i/upstart\\" ]; then" >> /tmp/osd_local_list.sh')
local('echo "id=\`echo \$i | sed \'s/[^-]*-//\'\`" >> /tmp/osd_local_list.sh')
local('echo "sudo stop ceph-osd id=\$id" >> /tmp/osd_local_list.sh')
local('echo "fi done fi" >> /tmp/osd_local_list.sh')
local('echo "}" >> /tmp/osd_local_list.sh')
local('echo "get_local_daemon_ulist" >> /tmp/osd_local_list.sh')
local('echo "exit 0" >> /tmp/osd_local_list.sh')
local('chmod a+x /tmp/osd_local_list.sh')
local('/tmp/osd_local_list.sh')
def reset_mon_remote_list(self):
run('echo "get_local_daemon_ulist() {" > /tmp/mon_local_list.sh')
run('echo "if [ -d \\\\"/var/lib/ceph/mon\\\\" ]; then" >> /tmp/mon_local_list.sh')
run('echo "for i in \\\\`find -L /var/lib/ceph/mon -mindepth 1 -maxdepth 1 -type d -printf \'%f\\\\\\n\'\\\\`; do" >> /tmp/mon_local_list.sh')
run('echo "if [ -e \\\\"/var/lib/ceph/mon/\\\\$i/upstart\\\\" ]; then" >> /tmp/mon_local_list.sh')
run('echo "id=\\\\`echo \\\\$i | sed \'s/[^-]*-//\'\\\\`" >> /tmp/mon_local_list.sh')
run('echo "sudo stop ceph-mon id=\\\\$id" >> /tmp/mon_local_list.sh')
run('echo "fi done fi" >> /tmp/mon_local_list.sh')
run('echo "}" >> /tmp/mon_local_list.sh')
run('echo "get_local_daemon_ulist" >> /tmp/mon_local_list.sh')
run('echo "exit 0" >> /tmp/mon_local_list.sh')
run('chmod a+x /tmp/mon_local_list.sh')
run('/tmp/mon_local_list.sh')
def reset_osd_remote_list(self):
run('echo "get_local_daemon_ulist() {" > /tmp/osd_local_list.sh')
run('echo "if [ -d \\\\"/var/lib/ceph/osd\\\\" ]; then" >> /tmp/osd_local_list.sh')
run('echo "for i in \\\\`find -L /var/lib/ceph/osd -mindepth 1 -maxdepth 1 -type d -printf \'%f\\\\\\n\'\\\\`; do" >> /tmp/osd_local_list.sh')
run('echo "if [ -e \\\\"/var/lib/ceph/osd/\\\\$i/upstart\\\\" ]; then" >> /tmp/osd_local_list.sh')
run('echo "id=\\\\`echo \\\\$i | sed \'s/[^-]*-//\'\\\\`" >> /tmp/osd_local_list.sh')
run('echo "sudo stop ceph-osd id=\\\\$id" >> /tmp/osd_local_list.sh')
run('echo "fi done fi" >> /tmp/osd_local_list.sh')
run('echo "}" >> /tmp/osd_local_list.sh')
run('echo "get_local_daemon_ulist" >> /tmp/osd_local_list.sh')
run('echo "exit 0" >> /tmp/osd_local_list.sh')
run('chmod a+x /tmp/osd_local_list.sh')
run('/tmp/osd_local_list.sh')
def ceph_rest_api_service_add(self):
# check for ceph-rest-api.conf
# write /etc/init conf for service upstrart
# if service not running then replace app.ceph_port to 5005
# start the ceph-rest-api service
rest_api_conf_available=local('ls /etc/init/ceph-rest-api.conf 2>/dev/null | wc -l', capture=True)
if rest_api_conf_available == '0':
local('sudo echo description \\"Ceph REST API\\" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "start on started rc RUNLEVEL=[2345]" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "stop on runlevel [!2345]" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "respawn" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "respawn limit 5 30" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "limit nofile 16384 16384" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "pre-start script" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo " set -e" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo " test -x /usr/bin/ceph-rest-api || { stop; exit 0; }" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "end script" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "# this breaks oneiric" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "#usage \\"ceph-rest-api -c <conf-file> -n <client-name>\\"" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "exec ceph-rest-api -c /etc/ceph/ceph.conf -n client.admin" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "post-stop script" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "# nothing to do for now" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "end script" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
local('sudo echo "" >> /etc/init/ceph-rest-api.conf', shell='/bin/bash')
ceph_rest_api_process_running=local('ps -ef|grep -v grep|grep ceph-rest-api|wc -l', capture=True)
if ceph_rest_api_process_running == '0':
entry_present=local('grep \"app.run(host=app.ceph_addr, port=app.ceph_port)\" /usr/bin/ceph-rest-api | wc -l', capture=True)
if entry_present == '1':
local('sudo sed -i "s/app.run(host=app.ceph_addr, port=app.ceph_port)/app.run(host=app.ceph_addr, port=5005)/" /usr/bin/ceph-rest-api')
local('sudo service ceph-rest-api start', shell='/bin/bash')
def unconfigure_syslog(self):
# disable server:port syslog remote logging
for entries in self._args.collector_hosts:
syslog_present=local('grep "*.* @%s:%s" /etc/rsyslog.d/50-default.conf | wc -l' %(entries, commonport.SYSLOG_LOGPORT), capture=True)
if syslog_present == '1':
local('sed -i "/*.* @%s:%s/d" /etc/rsyslog.d/50-default.conf' %(entries, commonport.SYSLOG_LOGPORT))
# restart rsyslog service after remote logging enabled
local('service rsyslog restart')
# find and replace syslog port to default in collector
for entries, entry_token in zip(self._args.collector_hosts, self._args.collector_host_tokens):
with settings(host_string = 'root@%s' %(entries), password = entry_token):
syslog_port=run('grep "syslog_port=4514" /etc/contrail/contrail-collector.conf | wc -l')
if syslog_port == '1':
run('cat /etc/contrail/contrail-collector.conf | sed "s/syslog_port=4514/syslog_port=-1/" > /tmp/contrail-collector.conf; mv /tmp/contrail-collector.conf /etc/contrail/contrail-collector.conf')
# restart collector after syslog default port change
run('service contrail-collector restart')
def ceph_rest_api_service_remove(self):
# check the ceph-rest-api service
# if it is running then trigger ceph-rest-api stop
# finally removing ceph-rest-api.conf
ceph_rest_api_process_running=local('ps -ef|grep -v grep|grep ceph-rest-api|wc -l', capture=True)
if ceph_rest_api_process_running != '0':
local('sudo service ceph-rest-api stop', shell='/bin/bash')
rest_api_conf_available=local('ls /etc/init/ceph-rest-api.conf 2>/dev/null | wc -l', capture=True)
if rest_api_conf_available != '0':
local('sudo rm -rf /etc/init/ceph-rest-api.conf', shell='/bin/bash')
def set_pg_count_increment(self, pool, pg_count):
while True:
time.sleep(2);
creating_pgs=local('sudo ceph -s | grep creating | wc -l', capture=True)
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
local('sudo ceph -k /etc/ceph/ceph.client.admin.keyring osd pool set %s pg_num %d' %(pool, pg_count))
def set_pgp_count_increment(self, pool, pg_count):
while True:
time.sleep(2);
creating_pgs=local('sudo ceph -s | grep creating | wc -l', capture=True)
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
local('sudo ceph -k /etc/ceph/ceph.client.admin.keyring osd pool set %s pgp_num %d' %(pool, pg_count))
def set_pg_pgp_count(self, osd_num, pool, host_cnt):
# Calculate/Set PG count
# The pg/pgp set will not take into effect if ceph is already in the
# process of creating pgs. So its required to do ceph -s and check
# if the pgs are currently creating and if not set the values
# Set the num of pgs to 32 times the OSD count. This is based on
# Firefly release recomendation.
while True:
time.sleep(5);
creating_pgs=local('sudo ceph -s | grep creating | wc -l', capture=True)
if creating_pgs == '0':
break;
print 'Waiting for create pgs to complete'
cur_pg = local('sudo ceph -k /etc/ceph/ceph.client.admin.keyring osd pool get %s pg_num' %(pool), capture=True)
cur_pg_cnt = int(cur_pg.split(':')[1])
max_pg_cnt = 30 * osd_num
while True:
cur_pg_cnt = 30 * cur_pg_cnt
if cur_pg_cnt > max_pg_cnt:
self.set_pg_count_increment(pool, max_pg_cnt)
self.set_pgp_count_increment(pool, max_pg_cnt)
break;
else:
self.set_pg_count_increment(pool, cur_pg_cnt)
self.set_pgp_count_increment(pool, cur_pg_cnt)
# Create HDD/SSD Pool
# For HDD/SSD pool, the crush map has to be changed to accomodate the
# rules for the HDD/SSD pools. For this, new ssd, hdd specific hosts
# have to be added to the map. The ssd, hdd specific maps will then
# be linked to the root entry for SSD/HDD pool and finally which is linked
# to a rule entry. The rules will then be applied to the respective pools
# created using the mkpool command.
# For populating the map with the host/tier specific entries, A dictionary
# of host/tier specific entries will be created. This will include the
# Total tier specific count, tier specific count for a particular host
# and entries for the tier for a particular host.
# The host_<tier>_dict will have the tier specific entries and the count
# for a particular host.
# The following operation is performed.
# - Get existing crushmap.
# - Populate the tier/host specific rules.
# - Compile/Apply the new crush map.
# - Apply the ruleset to the tier specific pools.
def create_hdd_ssd_pool(self):
local('sudo ceph osd getcrushmap -o /tmp/ma-crush-map')
local('sudo crushtool -d /tmp/ma-crush-map -o /tmp/ma-crush-map.txt')
print self._args
host_hdd_dict = {}
host_ssd_dict = {}
host_hdd_dict['totalcount'] = 0
host_ssd_dict['totalcount'] = 0
host_hdd_dict['hostcount'] = 0
host_ssd_dict['hostcount'] = 0
# Build the host/tier specific dictionary
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
host_hdd_dict[hostname, 'count'] = 0
host_ssd_dict[hostname, 'count'] = 0
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_hdd_dict['hostcount'] += 1
break
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_ssd_dict['hostcount'] += 1
break
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
osddet=run('sudo mount | grep %s | awk \'{ print $3 }\'' %(disksplit[1]), shell='/bin/bash')
osdnum=osddet.split('-')[1]
#host_hdd_dict[hostname, host_hdd_dict[hostname,'count']] = disksplit[1] + ':' + osdnum
host_hdd_dict[hostname, host_hdd_dict[hostname,'count']] = osdnum
host_hdd_dict[hostname, 'count'] += 1
host_hdd_dict['totalcount'] += 1
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
osddet=run('sudo mount | grep %s | awk \'{ print $3 }\'' %(disksplit[1]), shell='/bin/bash')
osdnum=osddet.split('-')[1]
#host_ssd_dict[hostname, host_ssd_dict[hostname,'count']] = disksplit[1] + ':' + osdnum
host_ssd_dict[hostname, host_ssd_dict[hostname,'count']] = osdnum
host_ssd_dict[hostname, 'count'] += 1
host_ssd_dict['totalcount'] += 1
#print host_hdd_dict
#print host_ssd_dict
# Configure Crush map
# Add host entries
local('sudo cat /tmp/ma-crush-map.txt |grep -v "^# end" > /tmp/ma-crush-map-new.txt')
cur_id=int(local('sudo cat /tmp/ma-crush-map.txt |grep "id " |wc -l', capture=True))
cur_id += 1
#print cur_id
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
if host_hdd_dict[hostname, 'count'] != 0:
local('sudo echo host %s-hdd { >> /tmp/ma-crush-map-new.txt' %(hostname))
local('sudo echo " id -%d" >> /tmp/ma-crush-map-new.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-new.txt')
hsthddcnt=host_hdd_dict[hostname, 'count']
while hsthddcnt != 0:
hsthddcnt -= 1
local('sudo echo " item osd.%s weight 1.000" >> /tmp/ma-crush-map-new.txt' %(host_hdd_dict[hostname, hsthddcnt]))
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
if host_ssd_dict[hostname, 'count'] != 0:
local('sudo echo host %s-ssd { >> /tmp/ma-crush-map-new.txt' %(hostname))
local('sudo echo " id -%d" >> /tmp/ma-crush-map-new.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-new.txt')
hstssdcnt=host_ssd_dict[hostname, 'count']
while hstssdcnt != 0:
hstssdcnt -= 1
local('sudo echo " item osd.%s weight 1.000" >> /tmp/ma-crush-map-new.txt' %(host_ssd_dict[hostname, hstssdcnt]))
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
# Add root entries for hdd/ssd
local('sudo echo "root hdd {" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " id -%d" >> /tmp/ma-crush-map-new.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-new.txt')
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
if host_hdd_dict[hostname, 'count'] != 0:
local('sudo echo " item %s-hdd weight %s.000" >> /tmp/ma-crush-map-new.txt' %(hostname, host_hdd_dict[hostname, 'count']))
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "root ssd {" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " id -%d" >> /tmp/ma-crush-map-new.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-new.txt')
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
if host_ssd_dict[hostname, 'count'] != 0:
local('sudo echo " item %s-ssd weight %s.000" >> /tmp/ma-crush-map-new.txt' %(hostname, host_ssd_dict[hostname, 'count']))
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
# Add ruleset for hdd/ssd
rule_id=int(local('sudo cat /tmp/ma-crush-map.txt |grep "ruleset " |wc -l', capture=True))
local('sudo echo "rule hdd {" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " ruleset %d" >> /tmp/ma-crush-map-new.txt' %(rule_id))
hdd_rule_set = rule_id
rule_id += 1
local('sudo echo " type replicated" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " min_size 0" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " max_size 10" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step take hdd" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step chooseleaf firstn 0 type host" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step emit" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "rule ssd {" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " ruleset %d" >> /tmp/ma-crush-map-new.txt' %(rule_id))
ssd_rule_set = rule_id
rule_id += 1
local('sudo echo " type replicated" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " min_size 0" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " max_size 10" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step take ssd" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step chooseleaf firstn 0 type host" >> /tmp/ma-crush-map-new.txt')
local('sudo echo " step emit" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "}" >> /tmp/ma-crush-map-new.txt')
local('sudo echo "" >> /tmp/ma-crush-map-new.txt')
# Apply the new crush map
local('sudo crushtool -c /tmp/ma-crush-map-new.txt -o /tmp/ma-newcrush-map')
local('sudo ceph -k /etc/ceph/ceph.client.admin.keyring osd setcrushmap -i /tmp/ma-newcrush-map')
# Create HDD/SSD pools
local('sudo rados mkpool volumes_hdd')
local('sudo rados mkpool volumes_ssd')
local('sudo ceph osd pool set volumes_hdd crush_ruleset %d' %(hdd_rule_set))
local('sudo ceph osd pool set volumes_ssd crush_ruleset %d' %(ssd_rule_set))
# Change the crush ruleset of images and volumes to point to HDD
local('sudo ceph osd pool set images crush_ruleset %d' %(hdd_rule_set))
local('sudo ceph osd pool set volumes crush_ruleset %d' %(hdd_rule_set))
# Set replica size based on count
if host_hdd_dict['hostcount'] <= 1:
local('sudo ceph osd pool set volumes_hdd size 1')
else:
local('sudo ceph osd pool set volumes_hdd size 2')
if host_ssd_dict['hostcount'] <= 1:
local('sudo ceph osd pool set volumes_ssd size 1')
else:
local('sudo ceph osd pool set volumes_ssd size 2')
# Set PG/PGPs for HDD/SSD Pool
self.set_pg_pgp_count(host_hdd_dict['totalcount'], 'volumes_hdd', host_hdd_dict['hostcount'])
self.set_pg_pgp_count(host_ssd_dict['totalcount'], 'volumes_ssd', host_ssd_dict['hostcount'])
# Add a new node osds to HDD/SSD pool
# For HDD/SSD pool, the crush map has to be changed to accomodate the
# rules for the HDD/SSD pools. For this, new ssd, hdd specific hosts
# have to be added to the map. The ssd, hdd specific maps will then
# be linked to the root entry for SSD/HDD pool and finally which is linked
# to a rule entry. The rules will then be applied to the respective pools
# created using the mkpool command.
# For populating the map with the host/tier specific entries, A dictionary
# of host/tier specific entries will be created. This will include the
# Total tier specific count, tier specific count for a particular host
# and entries for the tier for a particular host.
# The host_<tier>_dict will have the tier specific entries and the count
# for a particular host.
# The following operation is performed.
# - Get existing crushmap.
# - Populate the tier/host specific rules.
# - Compile/Apply the new crush map.
# - Apply the ruleset to the tier specific pools.
def add_to_hdd_ssd_pool(self):
add_storage_node = self._args.add_storage_node
local('sudo ceph osd getcrushmap -o /tmp/ma-crush-map')
local('sudo crushtool -d /tmp/ma-crush-map -o /tmp/ma-crush-map.txt')
#print self._args
# Add host entries to the existing map
host_hdd_dict = {}
host_ssd_dict = {}
host_hdd_dict['totalcount'] = 0
host_ssd_dict['totalcount'] = 0
host_hdd_dict['hostcount'] = 0
host_ssd_dict['hostcount'] = 0
# Build the host/tier specific dictionary
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
host_hdd_dict[hostname, 'count'] = 0
host_ssd_dict[hostname, 'count'] = 0
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_hdd_dict['hostcount'] += 1
break
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_ssd_dict['hostcount'] += 1
break
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
osddet=run('sudo mount | grep %s | awk \'{ print $3 }\'' %(disksplit[1]), shell='/bin/bash')
osdnum=osddet.split('-')[1]
#host_hdd_dict[hostname, host_hdd_dict[hostname,'count']] = disksplit[1] + ':' + osdnum
host_hdd_dict[hostname, host_hdd_dict[hostname,'count']] = osdnum
host_hdd_dict[hostname, 'count'] += 1
host_hdd_dict['totalcount'] += 1
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
osddet=run('sudo mount | grep %s | awk \'{ print $3 }\'' %(disksplit[1]), shell='/bin/bash')
osdnum=osddet.split('-')[1]
#host_ssd_dict[hostname, host_ssd_dict[hostname,'count']] = disksplit[1] + ':' + osdnum
host_ssd_dict[hostname, host_ssd_dict[hostname,'count']] = osdnum
host_ssd_dict[hostname, 'count'] += 1
host_ssd_dict['totalcount'] += 1
#print host_hdd_dict
#print host_ssd_dict
local('sudo cat /tmp/ma-crush-map.txt |grep -v "^# end" > /tmp/ma-crush-map-new.txt')
cur_id=int(local('sudo cat /tmp/ma-crush-map.txt |grep "id " |wc -l', capture=True))
cur_id += 1
root_line_str=local('cat /tmp/ma-crush-map-new.txt |grep -n \"root hdd\"', capture=True)
root_line_num=int(root_line_str.split(":")[0])
root_line_num-=1
local('cat /tmp/ma-crush-map-new.txt | head -n %d > /tmp/ma-crush-map-tmp.txt' %(root_line_num))
root_line_num+=1
#print cur_id
# Populate the crush map with the new host entries
if host_hdd_dict[add_storage_node, 'count'] != 0:
local('sudo echo host %s-hdd { >> /tmp/ma-crush-map-tmp.txt' %(add_storage_node))
local('sudo echo " id -%d" >> /tmp/ma-crush-map-tmp.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-tmp.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-tmp.txt')
hsthddcnt=host_hdd_dict[add_storage_node, 'count']
while hsthddcnt != 0:
hsthddcnt -= 1
local('sudo echo " item osd.%s weight 1.000" >> /tmp/ma-crush-map-tmp.txt' %(host_hdd_dict[add_storage_node, hsthddcnt]))
local('sudo echo "}" >> /tmp/ma-crush-map-tmp.txt')
local('sudo echo "" >> /tmp/ma-crush-map-tmp.txt')
if host_ssd_dict[add_storage_node, 'count'] != 0:
local('sudo echo host %s-ssd { >> /tmp/ma-crush-map-tmp.txt' %(add_storage_node))
local('sudo echo " id -%d" >> /tmp/ma-crush-map-tmp.txt' %(cur_id))
cur_id += 1
local('sudo echo " alg straw" >> /tmp/ma-crush-map-tmp.txt')
local('sudo echo " hash 0 #rjenkins1" >> /tmp/ma-crush-map-tmp.txt')
hstssdcnt=host_ssd_dict[add_storage_node, 'count']
while hstssdcnt != 0:
hstssdcnt -= 1
local('sudo echo " item osd.%s weight 1.000" >> /tmp/ma-crush-map-tmp.txt' %(host_ssd_dict[add_storage_node, hstssdcnt]))
local('sudo echo "}" >> /tmp/ma-crush-map-tmp.txt')
local('sudo echo "" >> /tmp/ma-crush-map-tmp.txt')
local('cat /tmp/ma-crush-map-new.txt | tail -n +%d >> /tmp/ma-crush-map-tmp.txt' %(root_line_num))
local('cp /tmp/ma-crush-map-tmp.txt /tmp/ma-crush-map-new.txt')
# Add the new host to the existing root entries
add_line_str=local('cat /tmp/ma-crush-map-new.txt |grep -n item |grep \"\-hdd\" |tail -n 1', shell='/bin/bash', capture=True)
add_line_num=int(add_line_str.split(":")[0])
local('cat /tmp/ma-crush-map-new.txt | head -n %d > /tmp/ma-crush-map-tmp.txt' %(add_line_num))
local('sudo echo " item %s-hdd weight %s.000" >> /tmp/ma-crush-map-tmp.txt' %(add_storage_node, host_hdd_dict[add_storage_node, 'count']))
add_line_num+=1
local('cat /tmp/ma-crush-map-new.txt | tail -n +%d >> /tmp/ma-crush-map-tmp.txt' %(add_line_num))
local('cp /tmp/ma-crush-map-tmp.txt /tmp/ma-crush-map-new.txt')
add_line_str=local('cat /tmp/ma-crush-map-new.txt |grep -n item |grep \"\-ssd\" |tail -n 1', shell='/bin/bash', capture=True)
add_line_num=int(add_line_str.split(":")[0])
local('cat /tmp/ma-crush-map-new.txt | head -n %d > /tmp/ma-crush-map-tmp.txt' %(add_line_num))
local('sudo echo " item %s-ssd weight %s.000" >> /tmp/ma-crush-map-tmp.txt' %(add_storage_node, host_ssd_dict[add_storage_node, 'count']))
add_line_num+=1
local('cat /tmp/ma-crush-map-new.txt | tail -n +%d >> /tmp/ma-crush-map-tmp.txt' %(add_line_num))
local('cp /tmp/ma-crush-map-tmp.txt /tmp/ma-crush-map-new.txt')
local('sudo crushtool -c /tmp/ma-crush-map-new.txt -o /tmp/ma-newcrush-map')
# Load the new crush map
local('sudo ceph -k /etc/ceph/ceph.client.admin.keyring osd setcrushmap -i /tmp/ma-newcrush-map')
# Set replica size based on new count
if host_hdd_dict['hostcount'] <= 1:
local('sudo ceph osd pool set volumes_hdd size 1')
else:
rep_size=local('sudo ceph osd pool get volumes_hdd size | awk \'{print $2}\'', shell='/bin/bash', capture=True)
if rep_size != '2':
local('sudo ceph osd pool set volumes_hdd size 2')
if host_ssd_dict['hostcount'] <= 1:
local('sudo ceph osd pool set volumes_ssd size 1')
else:
rep_size=local('sudo ceph osd pool get volumes_ssd size | awk \'{print $2}\'', shell='/bin/bash', capture=True)
if rep_size != '2':
local('sudo ceph osd pool set volumes_ssd size 2')
# Set PG/PGPs for HDD/SSD Pool based on the new osd count
self.set_pg_pgp_count(host_hdd_dict['totalcount'], 'volumes_hdd', host_hdd_dict['hostcount'])
self.set_pg_pgp_count(host_ssd_dict['totalcount'], 'volumes_ssd', host_ssd_dict['hostcount'])
def add_nfs_disk_config(self):
NFS_SERVER_LIST_FILE='/etc/cinder/nfs_server_list.txt'
if self._args.storage_nfs_disk_config[0] != 'none':
# Create NFS mount list file
file_present=local('sudo ls %s | wc -l' %(NFS_SERVER_LIST_FILE), capture=True)
if file_present == '0':
local('sudo touch %s' %(NFS_SERVER_LIST_FILE), capture=True)
local('sudo chown root:cinder %s' %(NFS_SERVER_LIST_FILE), capture=True)
local('sudo chmod 0640 %s' %(NFS_SERVER_LIST_FILE), capture=True)
# Add NFS mount list to file
for entry in self._args.storage_nfs_disk_config:
entry_present=local('cat %s | grep \"%s\" | wc -l' %(NFS_SERVER_LIST_FILE, entry), capture=True)
if entry_present == '0':
local('echo %s >> %s' %(entry, NFS_SERVER_LIST_FILE))
# Cinder configuration to create backend
cinder_configured=local('sudo cat %s | grep enabled_backends | grep nfs | wc -l' %(CINDER_CONFIG_FILE), capture=True)
if cinder_configured == '0':
existing_backends=local('sudo cat %s |grep enabled_backends |awk \'{print $3}\'' %(CINDER_CONFIG_FILE), shell='/bin/bash', capture=True)
if existing_backends != '':
new_backend = existing_backends + ',' + 'nfs'
local('sudo openstack-config --set %s DEFAULT enabled_backends %s' %(CINDER_CONFIG_FILE, new_backend))
else:
local('sudo openstack-config --set %s DEFAULT enabled_backends nfs' %(CINDER_CONFIG_FILE))
local('sudo openstack-config --set %s nfs nfs_shares_config %s' %(CINDER_CONFIG_FILE, NFS_SERVER_LIST_FILE))
local('sudo openstack-config --set %s nfs nfs_sparsed_volumes True' %(CINDER_CONFIG_FILE))
#local('sudo openstack-config --set %s nfs nfs_mount_options ' %(CINDER_CONFIG_FILE, NFS_SERVER_LIST_FILE))
local('sudo openstack-config --set %s nfs volume_driver cinder.volume.drivers.nfs.NfsDriver' %(CINDER_CONFIG_FILE))
local('sudo openstack-config --set %s nfs volume_backend_name NFS' %(CINDER_CONFIG_FILE))
def __init__(self, args_str = None):
#print sys.argv[1:]
self._args = None
if not args_str:
args_str = ' '.join(sys.argv[1:])
self._parse_args(args_str)
for entries, entry_token in zip(self._args.storage_hosts, self._args.storage_host_tokens):
with settings(host_string = 'root@%s' %(entries), password = entry_token):
for hostname, host_ip in zip(self._args.storage_hostnames, self._args.storage_hosts):
run('cat /etc/hosts |grep -v %s > /tmp/hosts; echo %s %s >> /tmp/hosts; cp -f /tmp/hosts /etc/hosts' % (hostname, host_ip, hostname))
ceph_mon_hosts=''
pdist = platform.dist()[0]
for entries in self._args.storage_hostnames:
ceph_mon_hosts=ceph_mon_hosts+entries+' '
#print ceph_mon_hosts
# setup SSH for autologin for Ceph
rsa_present=local('sudo ls ~/.ssh/id_rsa | wc -l', capture=True)
if rsa_present != '1':
local('sudo ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa')
sshkey=local('cat ~/.ssh/id_rsa.pub', capture=True)
local('sudo mkdir -p ~/.ssh')
already_present=local('grep "%s" ~/.ssh/known_hosts 2> /dev/null | wc -l' % (sshkey), capture=True)
if already_present == '0':
local('sudo echo "%s" >> ~/.ssh/known_hosts' % (sshkey))
already_present=local('grep "%s" ~/.ssh/authorized_keys 2> /dev/null | wc -l' % (sshkey), capture=True)
if already_present == '0':
local('sudo echo "%s" >> ~/.ssh/authorized_keys' % (sshkey))
for entries, entry_token, hostname in zip(self._args.storage_hosts, self._args.storage_host_tokens, self._args.storage_hostnames):
if entries != self._args.storage_master:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
run('sudo mkdir -p ~/.ssh')
already_present=run('grep "%s" ~/.ssh/known_hosts 2> /dev/null | wc -l' % (sshkey))
#print already_present
if already_present == '0':
run('sudo echo %s >> ~/.ssh/known_hosts' % (sshkey))
already_present=run('grep "%s" ~/.ssh/authorized_keys 2> /dev/null | wc -l' % (sshkey))
#print already_present
if already_present == '0':
run('sudo echo %s >> ~/.ssh/authorized_keys' % (sshkey))
hostfound = local('sudo grep %s,%s ~/.ssh/known_hosts | wc -l' %(hostname,entries), capture=True)
if hostfound == "0":
out = run('sudo ssh-keyscan -t rsa %s,%s' %(hostname,entries))
local('sudo echo "%s" >> ~/.ssh/known_hosts' % (out))
#local('sudo echo "%s" >> ~/.ssh/authorized_keys' % (out))
#Add a new node to the existing cluster
if self._args.add_storage_node:
configure_with_ceph = 0
add_storage_node = self._args.add_storage_node
if self._args.storage_directory_config[0] != 'none':
for directory in self._args.storage_directory_config:
dirsplit = directory.split(':')
if dirsplit[0] == add_storage_node:
configure_with_ceph = 1
if self._args.storage_disk_config[0] != 'none':
for disk in self._args.storage_disk_config:
dirsplit = disk.split(':')
if dirsplit[0] == add_storage_node:
configure_with_ceph = 1
if self._args.storage_ssd_disk_config[0] != 'none':
for disk in self._args.storage_ssd_disk_config:
dirsplit = disk.split(':')
if dirsplit[0] == add_storage_node:
configure_with_ceph = 1
if configure_with_ceph == 1:
ip_cidr=local('ip addr show |grep %s |awk \'{print $2}\'' %(self._args.storage_master), capture=True)
local('sudo openstack-config --set /root/ceph.conf global public_network %s\/%s' %(netaddr.IPNetwork(ip_cidr).network, netaddr.IPNetwork(ip_cidr).prefixlen))
for entries, entry_token, hostname in zip(self._args.storage_hosts, self._args.storage_host_tokens, self._args.storage_hostnames):
if hostname == add_storage_node:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
ceph_running=run('ps -ef|grep ceph |grep -v grep|wc -l')
if ceph_running != '0':
print 'Ceph already running in node'
return
run('sudo mkdir -p /var/lib/ceph/bootstrap-osd')
run('sudo mkdir -p /var/lib/ceph/osd')
run('sudo mkdir -p /etc/ceph')
local('sudo ceph-deploy --overwrite-conf mon create-initial %s' % (add_storage_node))
if self._args.storage_directory_config[0] != 'none':
for directory in self._args.storage_directory_config:
dirsplit = directory.split(':')
if dirsplit[0] == add_storage_node:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
run('sudo mkdir -p %s' % (dirsplit[1]))
run('sudo rm -rf %s' % (dirsplit[1]))
run('sudo mkdir -p %s' % (dirsplit[1]))
local('sudo ceph-deploy osd prepare %s' % (directory))
local('sudo ceph-deploy osd activate %s' % (directory))
# Setup Journal disks
storage_disk_list=[]
# Convert configuration from --storage-journal-config to ":" format
# for example --storage-disk-config ceph1:/dev/sdb ceph1:/dev/sdc
# --storage-journal-config ceph1:/dev/sdd will be stored in
# storage_disk_list as ceph1:/dev/sdb:/dev/sdd, ceph1:/dev/sdc:/dev/sdd
if self._args.storage_journal_config[0] != 'none':
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
host_disks = 0
journal_disks = 0
#print hostname
#print self._args.storage_disk_config
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_disks += 1
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
host_disks += 1
journal_disks_list = ''
for journal in self._args.storage_journal_config:
journalsplit = journal.split(':')
if journalsplit[0] == hostname:
journal_disks += 1
if journal_disks_list == '':
journal_disks_list = journalsplit[1]
else:
journal_disks_list = journal_disks_list + ':' + journalsplit[1]
#print 'num disks %d' %(host_disks)
#print 'num journal %d' %(journal_disks)
if journal_disks != 0:
num_partitions = (host_disks / journal_disks) + (host_disks % journal_disks > 0)
#print 'num partitions %d' %(num_partitions)
index = num_partitions
init_journal_disks_list = journal_disks_list
while True:
index -= 1
if index == 0:
break
journal_disks_list = journal_disks_list + ':' + init_journal_disks_list
#print journal_disks_list
journal_disks_split = journal_disks_list.split(':')
index = 0
for disks in self._args.storage_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
#print journal_disks_list
if journal_disks_list != '':
storage_disk_node = hostname + ':' + disksplit[1] + ':' + journal_disks_split[index]
index += 1
else:
storage_disk_node = disks
storage_disk_list.append(storage_disk_node)
for disks in self._args.storage_ssd_disk_config:
disksplit = disks.split(':')
if disksplit[0] == hostname:
#print journal_disks_list
if journal_disks_list != '':
storage_disk_node = hostname + ':' + disksplit[1] + ':' + journal_disks_split[index]
index += 1
else:
storage_disk_node = disks
storage_disk_list.append(storage_disk_node)
else:
if self._args.storage_ssd_disk_config[0] != 'none':
storage_disk_list = self._args.storage_disk_config + self._args.storage_ssd_disk_config
else:
storage_disk_list = self._args.storage_disk_config
#print self._args.storage_disk_config
# based on the coverted format or if the user directly provides in
# storage_disk_list ceph1:/dev/sdb:/dev/sdd, ceph1:/dev/sdc:/dev/sdd
# create journal partitions in the journal disk and assign partition
# numbers to the storage_disk_list. The final storage_disk_list will
# look as ceph1:/dev/sdb:/dev/sdd1, ceph1:/dev/sdc:/dev/sdd2
# with sdd1 and sdd2 of default_journal_size.
# TODO: make default_journal_size as configurable - currently its 1024M
new_storage_disk_list=[]
if storage_disk_list != []:
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
for disks in storage_disk_list:
journal_available = disks.count(':')
disksplit = disks.split(':')
if disksplit[0] == add_storage_node and disksplit[0] == hostname:
#print hostname
if journal_available == 2:
#print disksplit[2]
with settings(host_string = 'root@%s' %(entries), password = entry_token):
run('dd if=/dev/zero of=%s bs=512 count=1' %(disksplit[2]))
run('parted -s %s mklabel gpt 2>&1 > /dev/null' %(disksplit[2]))
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
for disks in storage_disk_list:
journal_available = disks.count(':')
disksplit = disks.split(':')
if disksplit[0] == add_storage_node and disksplit[0] == hostname:
#print hostname
# No need to partition
# Ceph will do the partition
#if journal_available == 2:
# #print disksplit[2]
# with settings(host_string = 'root@%s' %(entries), password = entry_token):
# default_journal_size = 1024
# num_primary = run('parted -s %s print|grep primary|wc -l' %(disksplit[2]), shell='/bin/bash')
# part_num = int(num_primary) + 1
# start_part = default_journal_size * part_num
# end_part = start_part + default_journal_size
# run('parted -s %s mkpart primary %dM %dM' %(disksplit[2], start_part, end_part))
# storage_disk_node = disks + str(part_num)
# new_storage_disk_list.append(storage_disk_node)
#else:
new_storage_disk_list.append(disks)
#print new_storage_disk_list
#print self._args.storage_disk_config
if new_storage_disk_list != []:
for disks in new_storage_disk_list:
dirsplit = disks.split(':')
if dirsplit[0] == add_storage_node:
local('sudo ceph-deploy disk zap %s' % (disks))
# For prefirefly use prepare/activate on ubuntu release
local('sudo ceph-deploy osd create %s' % (disks))
volume_keyring_list=local('cat /etc/ceph/client.volumes.keyring | grep key', capture=True)
volume_keyring=volume_keyring_list.split(' ')[2]
current_count = 1
while True:
virsh_secret=local('virsh secret-list 2>&1 |cut -d " " -f 1 | awk \'NR > 2 { print }\' | head -n %d | tail -n 1' %(current_count), capture=True)
if virsh_secret == '':
break
virsh_secret_key=local('virsh secret-get-value %s' %(virsh_secret), capture=True)
if virsh_secret_key == volume_keyring:
break
current_count += 1
# Find the host count
host_count = 0
if new_storage_disk_list != []:
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
for disks in storage_disk_list:
disksplit = disks.split(':')
if hostname == disksplit[0]:
host_count += 1
break
# Set replica size based on new count
if host_count <= 1:
local('sudo ceph osd pool set volumes size 1')
else:
rep_size=local('sudo ceph osd pool get volumes size | awk \'{print $2}\'', shell='/bin/bash', capture=True)
if rep_size == '1':
local('sudo ceph osd pool set volumes size 2')
osd_count=int(local('ceph osd stat | awk \'{print $3}\'', shell='/bin/bash', capture=True))
# Set PG/PGP count based on osd new count
self.set_pg_pgp_count(osd_count, 'images', host_count)
self.set_pg_pgp_count(osd_count, 'volumes', host_count)
# rbd cache enabled and rbd cache size set to 512MB
local('ceph tell osd.* injectargs -- --rbd_cache=true')
local('ceph tell osd.* injectargs -- --rbd_cache_size=536870912')
local('sudo openstack-config --set /etc/ceph/ceph.conf global "rbd cache" true')
local('sudo openstack-config --set /etc/ceph/ceph.conf global "rbd cache size" 536870912')
# change default osd op threads 2 to 4
local('ceph tell osd.* injectargs -- --osd_op_threads=4')
local('sudo openstack-config --set /etc/ceph/ceph.conf osd "osd op threads" 4')
# change default disk threads 1 to 2
local('ceph tell osd.* injectargs -- --osd_disk_threads=2')
local('sudo openstack-config --set /etc/ceph/ceph.conf osd "osd disk threads" 2')
# compute ceph.conf configuration done here
for entries, entry_token in zip(self._args.storage_hosts, self._args.storage_host_tokens):
if entries != self._args.storage_master:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
run('sudo openstack-config --set /etc/ceph/ceph.conf global "rbd cache" true')
run('sudo openstack-config --set /etc/ceph/ceph.conf global "rbd cache size" 536870912')
run('sudo openstack-config --set /etc/ceph/ceph.conf osd "osd op threads" 4')
run('sudo openstack-config --set /etc/ceph/ceph.conf osd "osd disk threads" 2')
# log ceph.log to syslog
local('ceph tell mon.* injectargs -- --mon_cluster_log_to_syslog=true')
# set ceph.log to syslog config in ceph.conf
local('sudo openstack-config --set /etc/ceph/ceph.conf mon "mon cluster log to syslog" true')
for entries, entry_token in zip(self._args.storage_hosts, self._args.storage_host_tokens):
if entries != self._args.storage_master:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
run('sudo openstack-config --set /etc/ceph/ceph.conf mon "mon cluster log to syslog" true')
if self._args.storage_ssd_disk_config[0] != 'none':
volumes_pool_avail=local('sudo rados lspools |grep volumes_hdd | wc -l ', capture=True)
if volumes_pool_avail != '0':
self.add_to_hdd_ssd_pool()
else:
self.create_hdd_ssd_pool()
#TODO: Add configurations to cinder
cinder_lvm_type_list=[]
cinder_lvm_name_list=[]
#Create LVM volumes on each node
if self._args.storage_local_disk_config[0] != 'none':
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
with settings(host_string = 'root@%s' %(entries), password = entry_token):
local_disk_list=''
for local_disks in self._args.storage_local_disk_config:
disksplit = local_disks.split(':')
if disksplit[0] == hostname:
if disksplit[0] == add_storage_node:
local_disk_list = local_disk_list + disksplit[1] + ' '
run('sudo dd if=/dev/zero of=%s bs=512 count=1' %(disksplit[1]))
if local_disk_list != '':
if disksplit[0] == hostname:
if disksplit[0] == add_storage_node:
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT sql_connection mysql://cinder:cinder@%s/cinder' %(self._args.storage_master))
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT rabbit_host %s' %(self._args.cfg_host))
run('sudo cinder-manage db sync')
existing_backends=run('sudo cat /etc/cinder/cinder.conf |grep enabled_backends |awk \'{print $3}\'', shell='/bin/bash')
if existing_backends != '':
new_backend = existing_backends + ',' + 'lvm-local-disk-volumes'
else:
new_backend = 'lvm-local-disk-volumes'
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT enabled_backends %s' %(new_backend))
run('sudo pvcreate %s' %(local_disk_list))
run('sudo vgcreate ocs-lvm-group %s' %(local_disk_list))
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-disk-volumes volume_group ocs-lvm-group')
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-disk-volumes volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver')
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-disk-volumes volume_backend_name OCS_LVM_%s' %(hostname))
cinder_lvm_type_list.append('ocs-block-lvm-disk-%s' %(hostname))
cinder_lvm_name_list.append('OCS_LVM_%s' %(hostname))
#Create LVM volumes for SSD disks on each node
if self._args.storage_local_ssd_disk_config[0] != 'none':
for hostname, entries, entry_token in zip(self._args.storage_hostnames, self._args.storage_hosts, self._args.storage_host_tokens):
with settings(host_string = 'root@%s' %(entries), password = entry_token):
local_ssd_disk_list=''
for local_ssd_disks in self._args.storage_local_ssd_disk_config:
disksplit = local_ssd_disks.split(':')
if disksplit[0] == hostname:
if disksplit[0] == add_storage_node:
local_ssd_disk_list = local_ssd_disk_list + disksplit[1] + ' '
run('sudo dd if=/dev/zero of=%s bs=512 count=1' %(disksplit[1]))
if local_ssd_disk_list != '':
if disksplit[0] == hostname:
if disksplit[0] == add_storage_node:
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT sql_connection mysql://cinder:cinder@%s/cinder' %(self._args.storage_master))
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT rabbit_host %s' %(self._args.cfg_host))
run('sudo cinder-manage db sync')
existing_backends=run('sudo cat /etc/cinder/cinder.conf |grep enabled_backends |awk \'{print $3}\'', shell='/bin/bash')
if existing_backends != '':
new_backend = existing_backends + ',' + 'lvm-local-ssd-disk-volumes'
else:
new_backend = 'lvm-local-ssd-disk-volumes'
run('sudo openstack-config --set /etc/cinder/cinder.conf DEFAULT enabled_backends %s' %(new_backend))
run('sudo pvcreate %s' %(local_ssd_disk_list))
run('sudo vgcreate ocs-lvm-ssd-group %s' %(local_ssd_disk_list))
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-ssd-disk-volumes volume_group ocs-lvm-ssd-group')
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-ssd-disk-volumes volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver')
run('sudo openstack-config --set /etc/cinder/cinder.conf lvm-local-ssd-disk-volumes volume_backend_name OCS_LVM_SSD_%s' %(hostname))
cinder_lvm_type_list.append('ocs-block-lvm-ssd-disk-%s' %(hostname))
cinder_lvm_name_list.append('OCS_LVM_SSD_%s' %(hostname))
# Create Cinder type for all the LVM backends
for lvm_types, lvm_names in zip(cinder_lvm_type_list, cinder_lvm_name_list):
local('(. /etc/contrail/openstackrc ; cinder type-create %s)' %(lvm_types))
local('(. /etc/contrail/openstackrc ; cinder type-key %s set volume_backend_name=%s)' %(lvm_types, lvm_names))
if virsh_secret == '':
print 'Cannot find virsh secret uuid'
return
# Add NFS configurations if present
if self._args.storage_nfs_disk_config[0] != 'none':
self.add_nfs_disk_config()
nfs_type_present=local('(. /etc/contrail/openstackrc ; cinder type-list | grep ocs-block-nfs-disk | wc -l)', capture=True)
if nfs_type_present == '0':
local('(. /etc/contrail/openstackrc ; cinder type-create ocs-block-nfs-disk)')
local('(. /etc/contrail/openstackrc ; cinder type-key ocs-block-nfs-disk set volume_backend_name=NFS)')
for entries, entry_token, hostname in zip(self._args.storage_hosts, self._args.storage_host_tokens, self._args.storage_hostnames):
if hostname == add_storage_node:
with settings(host_string = 'root@%s' %(entries), password = entry_token):
if configure_with_ceph == 1:
while True:
virsh_unsecret=run('virsh secret-list 2>&1 |cut -d " " -f 1 | awk \'NR > 2 { print }\' | head -n 1')
if virsh_unsecret != "":
run('virsh secret-undefine %s' %(virsh_unsecret))
else:
break
run('echo "<secret ephemeral=\'no\' private=\'no\'>\n<uuid>%s</uuid><usage type=\'ceph\'>\n<name>client.volumes secret</name>\n</usage>\n</secret>" > secret.xml' % (virsh_secret))
run('virsh secret-define --file secret.xml')
run('virsh secret-set-value %s --base64 %s' % (virsh_secret,volume_keyring))
# Remove rbd_user configurations from nova if present
run('sudo openstack-config --del /etc/nova/nova.conf DEFAULT rbd_user')
run('sudo openstack-config --del /etc/nova/nova.conf DEFAULT rbd_secret_uuid')
# This should not be set for multi-backend. The virsh secret setting itself is enough for correct authentication.
#run('sudo openstack-config --set /etc/nova/nova.conf DEFAULT rbd_user volumes')
#run('sudo openstack-config --set /etc/nova/nova.conf DEFAULT rbd_secret_uuid %s' % (virsh_secret))
run('sudo openstack-config --set /etc/nova/nova.conf DEFAULT cinder_endpoint_template "http://%s:8776/v1/%%(project_id)s"' % (self._args.storage_master), shell='/bin/bash')
if pdist == 'centos':
run('sudo chkconfig tgt on')
run('sudo service tgt restart')
run('sudo service openstack-cinder-api restart')
run('sudo chkconfig openstack-cinder-api on')
run('sudo service openstack-cinder-scheduler restart')
run('sudo chkconfig openstack-cinder-scheduler on')
if configure_with_ceph == 1:
bash_cephargs = run('grep "bashrc" /etc/init.d/openstack-cinder-volume | wc -l')
if bash_cephargs == "0":
run('cat /etc/init.d/openstack-cinder-volume | sed "s/start)/start) source ~\/.bashrc/" > /tmp/openstack-cinder-volume.tmp')
run('mv -f /tmp/openstack-cinder-volume.tmp /etc/init.d/openstack-cinder-volume; chmod a+x /etc/init.d/openstack-cinder-volume')
run('sudo chkconfig openstack-cinder-volume on')
run('sudo service openstack-cinder-volume restart')
run('sudo service libvirtd restart')
run('sudo service openstack-nova-compute restart')
if pdist == 'Ubuntu':
run('sudo chkconfig tgt on')
run('sudo service tgt restart')
run('sudo service libvirt-bin restart')
run('sudo service nova-compute restart')
run('sudo chkconfig cinder-volume on')
run('sudo service cinder-volume restart')
return