Newer
Older
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
#!/usr/bin/python
import re
import os
import sys
import argparse
import subprocess
import socket
try:
myfullpath = os.path.dirname(os.path.realpath(__file__))
except NameError:
myfullpath = os.path.abspath(os.path.curdir)
hostname = socket.gethostname().split('.')[0]
tp = open("disks_lists.pp","r")
tp_lines = tp.readlines()
tp.close()
#Remove last parantheses
ll = tp_lines[0:-2]
disk_tag_template = 'ceph_osd_list_prod_10x'
disk_tag = disk_tag_template+"_"+hostname
ll.append(" \'"+disk_tag+"\'" + " => {\n")
ll.append(' }\n')
ll.append('}\n')
n = open("disks_lists.pp", "w")
for l in ll:
n.write(l)
n.close()
#sys.exit(0)
#{
# '23-2EH3N2JX-HGST-HUH728080AL4200/sdaa_data'=> {
# store_type => 'bluestore',
# bluestore_wal => 'cs-001_journal/sdaa_wal',
# bluestore_db => 'cs-001_journal/sdaa_db',
# ensure => 'present',
# }
#{
# '<volume group>/<logical volume>'=> {
# store_type => 'bluestore',
# bluestore_db => '<ssd volume group>/<ssd logical volume>',
# ensure => 'present',
# }
# LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
# 101-db01 101-ceph-db01 -wi-a----- <74,49g
import subprocess
process = subprocess.Popen(['/sbin/lvs'], stdout=subprocess.PIPE)
stdout = process.communicate()[0]
tmp = stdout.split('\n')[1:-1]
ll = []
db_lvs = []
data_lvs = []
for l in tmp:
el = l.split()[0:2]
if '-db' in el[0] :
db_lvs.append(el)
#print 'db ',el
else:
data_lvs.append(el)
#print 'data ',el
full_list=[]
for l in data_lvs:
el = []
osd = l[1][-2:]
el.append(l[0])
el.append(l[1])
for d in db_lvs:
if osd == d[0][-2:]:
el.append(d[0])
el.append(d[1])
full_list.append(el)
# CREATE PARTITIONS FOR CEPH OSDS AND UPDATE PUPPET CONFIGURATION
sed_string=""
for o in full_list:
sed_string = sed_string + "'\"'\""+o[0]+"/"+o[1]+"\"'\"'=> \
{\\n \ \ \ \ \ \ \ \ store_type => '\"'\"'bluestore'\"'\"', \
\\n \ \ \ \ \ \ \ \ bluestore_db => '\"'\"'"+o[1]+"/"+o[2]+"'\"'\"',\
\\n \ \ \ \ \ \ \ \ ensure => '\"'\"'present'\"'\"',\\n \ \ \ \ \ \},\\n"
sed_string = sed_string + "\ \ \ \ \},"
#print sed_string
os.system("sed -i '/ '\"'\""+disk_tag+"\"'\"' => {/a "+sed_string+"' "+"./disks_lists.pp")